2 * Link to the project's GitHub page:
3 * https://github.com/duralog/CodeMirror
5 CodeMirror.defineMode 'livescript', (conf) ->
6 tokenBase = (stream, state) ->
8 if next_rule = state.next or \start
9 state.next = state.next
10 if Array.isArray nr = Rules[next_rule]
12 if r.regex and m = stream.match r.regex
17 if stream.match r = Rules[next_rule]
18 if r.regex and stream.match r.regex
27 startState: (basecolumn) ->
32 token: (stream, state) ->
33 style = tokenBase stream, state #tokenLexer stream, state
36 indent: stream.indentation!
37 content: stream.current!
39 style.replace /\./g, ' '
40 indent: (state, textAfter) ->
41 # XXX this won't work with backcalls
42 indentation = state.lastToken.indent
43 if state.lastToken.content.match indenter then indentation += 2
49 # taken from mode-ls.ls
54 | \b (?: e(?:lse|xport) | d(?:o|efault) | t(?:ry|hen) | finally |
55 import (?:\s* all)? | const | var |
56 let | new | catch (?:\s* #identifier)? )
59 identifier = /(?![\d\s])[$\w\xAA-\uFFDC](?:(?!\s)[$\w\xAA-\uFFDC]|-[A-Za-z])*/$
60 keywordend = /(?![$\w]|-[A-Za-z]|\s*:(?![:=]))/$
61 stringfill = token: \string, regex: '.+'
74 :t(?:h(?:is|row|en)|ry|ypeof!?)
75 |c(?:on(?:tinue|st)|a(?:se|tch)|lass)
76 |i(?:n(?:stanceof)?|mp(?:ort(?:\s+all)?|lements)|[fs])
77 |d(?:e(?:fault|lete|bugger)|o)
78 |f(?:or(?:\s+own)?|inally|unction)
80 |e(?:lse|x(?:tends|port)|val)
85 |o[fr]|return|break|let|var|loop
88 * token: \constant.language
89 regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
91 * token: \invalid.illegal
93 :p(?:ackage|r(?:ivate|otected)|ublic)
94 |i(?:mplements|nterface)
98 * token: \language.support.class
100 :R(?:e(?:gExp|ferenceError)|angeError)
101 |S(?:tring|yntaxError)
103 |Array|Boolean|Date|Function|Number|Object|TypeError|URIError
106 * token: \language.support.function
111 |(?:en|de)codeURI(?:Component)?
114 * token: \variable.language
115 regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
118 regex: identifier + /\s*:(?![:=])/$
123 * token: \keyword.operator
124 regex: /(?:\.{3}|\s+\?)/$
126 * token: \keyword.variable
127 regex: /(?:@+|::|\.\.)/$
130 * token: \keyword.operator
135 regex: /\\\S[^\s,;)}\]]*/$
161 * token: \string.regex
165 * token: \string.regex
169 | \[ [^\]\n\\]* (?:\\.[^\]\n\\]*)* \]
176 * token: \constant.numeric
177 regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*
178 |(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*
179 |(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)
180 (?:e[+-]?\\d[\\d_]*)?[\\w$]*)'
189 * token: \keyword.operator
196 * token: \string.regex
197 regex: '.*?//[gimy$?]{0,4}'
199 * token: \string.regex
201 * token: \comment.regex
202 regex: '\\s+(?:#.*)?'
203 * token: \string.regex
207 * token: \keyword.operator
217 * token: \comment.doc
220 * token: \comment.doc
237 regex: /[^\\']*(?:\\.[^\\']*)*'/$
243 regex: /[^\\"]*(?:\\.[^\\"]*)*"/$
249 regex: /[^\\`]*(?:\\.[^\\`]*)*`/$
259 # for optimization, precompile the regexps
263 if rr.regex then Rules[idx][i].regex = new RegExp '^'+rr.regex
264 else if r.regex then Rules[idx].regex = new RegExp '^'+r.regex
266 CodeMirror.defineMIME 'text/x-livescript', 'livescript'