Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/livescript/livescript.ls
1294 views
/**1* Link to the project's GitHub page:2* https://github.com/duralog/CodeMirror3*/4CodeMirror.defineMode 'livescript', (conf) ->5tokenBase = (stream, state) ->6#indent =7if next_rule = state.next or \start8state.next = state.next9if Array.isArray nr = Rules[next_rule]10for r in nr11if r.regex and m = stream.match r.regex12state.next = r.next13return r.token14stream.next!15return \error16if stream.match r = Rules[next_rule]17if r.regex and stream.match r.regex18state.next = r.next19return r.token20else21stream.next!22return \error23stream.next!24return 'error'25external = {26startState: (basecolumn) ->27{28next: \start29lastToken: null30}31token: (stream, state) ->32style = tokenBase stream, state #tokenLexer stream, state33state.lastToken = {34style: style35indent: stream.indentation!36content: stream.current!37}38style.replace /\./g, ' '39indent: (state, textAfter) ->40# XXX this won't work with backcalls41indentation = state.lastToken.indent42if state.lastToken.content.match indenter then indentation += 243return indentation44}45external4647### Highlight Rules48# taken from mode-ls.ls4950indenter = // (?51: [({[=:]52| [-~]>53| \b (?: e(?:lse|xport) | d(?:o|efault) | t(?:ry|hen) | finally |54import (?:\s* all)? | const | var |55let | new | catch (?:\s* #identifier)? )56) \s* $ //5758identifier = /(?![\d\s])[$\w\xAA-\uFFDC](?:(?!\s)[$\w\xAA-\uFFDC]|-[A-Za-z])*/$59keywordend = /(?![$\w]|-[A-Za-z]|\s*:(?![:=]))/$60stringfill = token: \string, regex: '.+'6162Rules =63start:64* token: \comment.doc65regex: '/\\*'66next : \comment6768* token: \comment69regex: '#.*'7071* token: \keyword72regex: //(?73:t(?:h(?:is|row|en)|ry|ypeof!?)74|c(?:on(?:tinue|st)|a(?:se|tch)|lass)75|i(?:n(?:stanceof)?|mp(?:ort(?:\s+all)?|lements)|[fs])76|d(?:e(?:fault|lete|bugger)|o)77|f(?:or(?:\s+own)?|inally|unction)78|s(?:uper|witch)79|e(?:lse|x(?:tends|port)|val)80|a(?:nd|rguments)81|n(?:ew|ot)82|un(?:less|til)83|w(?:hile|ith)84|o[fr]|return|break|let|var|loop85)//$ + keywordend8687* token: \constant.language88regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend8990* token: \invalid.illegal91regex: '(?92:p(?:ackage|r(?:ivate|otected)|ublic)93|i(?:mplements|nterface)94|enum|static|yield95)' + keywordend9697* token: \language.support.class98regex: '(?99:R(?:e(?:gExp|ferenceError)|angeError)100|S(?:tring|yntaxError)101|E(?:rror|valError)102|Array|Boolean|Date|Function|Number|Object|TypeError|URIError103)' + keywordend104105* token: \language.support.function106regex: '(?107:is(?:NaN|Finite)108|parse(?:Int|Float)109|Math|JSON110|(?:en|de)codeURI(?:Component)?111)' + keywordend112113* token: \variable.language114regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend115116* token: \identifier117regex: identifier + /\s*:(?![:=])/$118119* token: \variable120regex: identifier121122* token: \keyword.operator123regex: /(?:\.{3}|\s+\?)/$124125* token: \keyword.variable126regex: /(?:@+|::|\.\.)/$127next : \key128129* token: \keyword.operator130regex: /\.\s*/$131next : \key132133* token: \string134regex: /\\\S[^\s,;)}\]]*/$135136* token: \string.doc137regex: \'''138next : \qdoc139140* token: \string.doc141regex: \"""142next : \qqdoc143144* token: \string145regex: \'146next : \qstring147148* token: \string149regex: \"150next : \qqstring151152* token: \string153regex: \`154next : \js155156* token: \string157regex: '<\\['158next : \words159160* token: \string.regex161regex: \//162next : \heregex163164* token: \string.regex165regex: //166/(?: [^ [ / \n \\ ]*167(?: (?: \\.168| \[ [^\]\n\\]* (?:\\.[^\]\n\\]*)* \]169) [^ [ / \n \\ ]*170)*171)/ [gimy$]{0,4}172//$173next : \key174175* token: \constant.numeric176regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*177|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*178|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)179(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'180181* token: \lparen182regex: '[({[]'183184* token: \rparen185regex: '[)}\\]]'186next : \key187188* token: \keyword.operator189regex: \\\S+190191* token: \text192regex: \\\s+193194heregex:195* token: \string.regex196regex: '.*?//[gimy$?]{0,4}'197next : \start198* token: \string.regex199regex: '\\s*#{'200* token: \comment.regex201regex: '\\s+(?:#.*)?'202* token: \string.regex203regex: '\\S+'204205key:206* token: \keyword.operator207regex: '[.?@!]+'208* token: \identifier209regex: identifier210next : \start211* token: \text212regex: '.'213next : \start214215comment:216* token: \comment.doc217regex: '.*?\\*/'218next : \start219* token: \comment.doc220regex: '.+'221222qdoc:223token: \string224regex: ".*?'''"225next : \key226stringfill227228qqdoc:229token: \string230regex: '.*?"""'231next : \key232stringfill233234qstring:235token: \string236regex: /[^\\']*(?:\\.[^\\']*)*'/$237next : \key238stringfill239240qqstring:241token: \string242regex: /[^\\"]*(?:\\.[^\\"]*)*"/$243next : \key244stringfill245246js:247token: \string248regex: /[^\\`]*(?:\\.[^\\`]*)*`/$249next : \key250stringfill251252words:253token: \string254regex: '.*?\\]>'255next : \key256stringfill257258# for optimization, precompile the regexps259for idx, r of Rules260if Array.isArray r261for rr, i in r262if rr.regex then Rules[idx][i].regex = new RegExp '^'+rr.regex263else if r.regex then Rules[idx].regex = new RegExp '^'+r.regex264265CodeMirror.defineMIME 'text/x-livescript', 'livescript'266267268