forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoz.js
More file actions
1 lines (1 loc) · 4.15 KB
/
Copy pathoz.js
File metadata and controls
1 lines (1 loc) · 4.15 KB
1
!function(mod){"object"==typeof exports&&"object"==typeof module?mod(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):mod(CodeMirror)}(function(CodeMirror){"use strict";CodeMirror.defineMode("oz",function(conf){function wordRegexp(words){return new RegExp("^(("+words.join(")|(")+"))\\b")}var singleOperators=/[\^@!\|<>#~\.\*\-\+\\/,=]/,doubleOperators=/(<-)|(:=)|(=<)|(>=)|(<=)|(<:)|(>:)|(=:)|(\\=)|(\\=:)|(!!)|(==)|(::)/,tripleOperators=/(:::)|(\.\.\.)|(=<:)|(>=:)/,middle=["in","then","else","of","elseof","elsecase","elseif","catch","finally","with","require","prepare","import","export","define","do"],end=["end"],atoms=wordRegexp(["true","false","nil","unit"]),commonKeywords=wordRegexp(["andthen","at","attr","declare","feat","from","lex","mod","div","mode","orelse","parser","prod","prop","scanner","self","syn","token"]),openingKeywords=wordRegexp(["local","proc","fun","case","class","if","cond","or","dis","choice","not","thread","try","raise","lock","for","suchthat","meth","functor"]),middleKeywords=wordRegexp(middle),endKeywords=wordRegexp(end);function tokenBase(stream,state){if(stream.eatSpace())return null;if(stream.match(/[{}]/))return"bracket";if(stream.match("[]"))return"keyword";if(stream.match(tripleOperators)||stream.match(doubleOperators))return"operator";if(stream.match(atoms))return"atom";var matched=stream.match(openingKeywords);if(matched)return state.doInCurrentLine?state.doInCurrentLine=!1:state.currentIndent++,"proc"==matched[0]||"fun"==matched[0]?state.tokenize=tokenFunProc:"class"==matched[0]?state.tokenize=tokenClass:"meth"==matched[0]&&(state.tokenize=tokenMeth),"keyword";if(stream.match(middleKeywords)||stream.match(commonKeywords))return"keyword";if(stream.match(endKeywords))return state.currentIndent--,"keyword";var ch=stream.next();if('"'==ch||"'"==ch)return state.tokenize=tokenString(ch),state.tokenize(stream,state);if(/[~\d]/.test(ch)){if("~"==ch){if(!/^[0-9]/.test(stream.peek()))return null;if("0"==stream.next()&&stream.match(/^[xX][0-9a-fA-F]+/)||stream.match(/^[0-9]*(\.[0-9]+)?([eE][~+]?[0-9]+)?/))return"number"}return"0"==ch&&stream.match(/^[xX][0-9a-fA-F]+/)||stream.match(/^[0-9]*(\.[0-9]+)?([eE][~+]?[0-9]+)?/)?"number":null}return"%"==ch?(stream.skipToEnd(),"comment"):"/"==ch&&stream.eat("*")?(state.tokenize=tokenComment,tokenComment(stream,state)):singleOperators.test(ch)?"operator":(stream.eatWhile(/\w/),"variable")}function tokenClass(stream,state){return stream.eatSpace()?null:(stream.match(/([A-Z][A-Za-z0-9_]*)|(`.+`)/),state.tokenize=tokenBase,"variable-3")}function tokenMeth(stream,state){return stream.eatSpace()?null:(stream.match(/([a-zA-Z][A-Za-z0-9_]*)|(`.+`)/),state.tokenize=tokenBase,"def")}function tokenFunProc(stream,state){return stream.eatSpace()?null:!state.hasPassedFirstStage&&stream.eat("{")?(state.hasPassedFirstStage=!0,"bracket"):state.hasPassedFirstStage?(stream.match(/([A-Z][A-Za-z0-9_]*)|(`.+`)|\$/),state.hasPassedFirstStage=!1,state.tokenize=tokenBase,"def"):(state.tokenize=tokenBase,null)}function tokenComment(stream,state){for(var maybeEnd=!1,ch;ch=stream.next();){if("/"==ch&&maybeEnd){state.tokenize=tokenBase;break}maybeEnd="*"==ch}return"comment"}function tokenString(quote){return function(stream,state){for(var escaped=!1,next,end=!1;null!=(next=stream.next());){if(next==quote&&!escaped){end=!0;break}escaped=!escaped&&"\\"==next}return!end&&escaped||(state.tokenize=tokenBase),"string"}}function buildElectricInputRegEx(){var allClosings=middle.concat(end);return new RegExp("[\\[\\]]|("+allClosings.join("|")+")$")}return{startState:function(){return{tokenize:tokenBase,currentIndent:0,doInCurrentLine:!1,hasPassedFirstStage:!1}},token:function(stream,state){return stream.sol()&&(state.doInCurrentLine=0),state.tokenize(stream,state)},indent:function(state,textAfter){var trueText=textAfter.replace(/^\s+|\s+$/g,"");return trueText.match(endKeywords)||trueText.match(middleKeywords)||trueText.match(/(\[])/)?conf.indentUnit*(state.currentIndent-1):state.currentIndent<0?0:state.currentIndent*conf.indentUnit},fold:"indent",electricInput:buildElectricInputRegEx(),lineComment:"%",blockCommentStart:"/*",blockCommentEnd:"*/"}}),CodeMirror.defineMIME("text/x-oz","oz")});