1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
5 * Link to the project's GitHub page:
6 * https://github.com/duralog/CodeMirror
10 if (typeof exports
== "object" && typeof module
== "object") // CommonJS
11 mod(require("../../lib/codemirror"));
12 else if (typeof define
== "function" && define
.amd
) // AMD
13 define(["../../lib/codemirror"], mod
);
14 else // Plain browser env
16 })(function(CodeMirror
) {
19 CodeMirror
.defineMode('livescript', function(){
20 var tokenBase = function(stream
, state
) {
21 var next_rule
= state
.next
|| "start";
23 state
.next
= state
.next
;
24 var nr
= Rules
[next_rule
];
26 for (var i
$ = 0; i
$ < nr
.length
; ++i
$) {
28 if (r
.regex
&& stream
.match(r
.regex
)) {
29 state
.next
= r
.next
|| state
.next
;
36 if (stream
.match(r
= Rules
[next_rule
])) {
37 if (r
.regex
&& stream
.match(r
.regex
)) {
50 startState: function(){
56 token: function(stream
, state
){
57 while (stream
.pos
== stream
.start
)
58 var style
= tokenBase(stream
, state
);
61 indent
: stream
.indentation(),
62 content
: stream
.current()
64 return style
.replace(/\./g, ' ');
66 indent: function(state
){
67 var indentation
= state
.lastToken
.indent
;
68 if (state
.lastToken
.content
.match(indenter
)) {
77 var identifier
= '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*';
78 var indenter
= RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier
+ ')?))\\s*$');
79 var keywordend
= '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';
95 regex
: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend
97 token
: 'constant.language',
98 regex
: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
100 token
: 'invalid.illegal',
101 regex
: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend
103 token
: 'language.support.class',
104 regex
: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend
106 token
: 'language.support.function',
107 regex
: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend
109 token
: 'variable.language',
110 regex
: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
113 regex
: identifier
+ '\\s*:(?![:=])'
118 token
: 'keyword.operator',
119 regex
: '(?:\\.{3}|\\s+\\?)'
121 token
: 'keyword.variable',
122 regex
: '(?:@+|::|\\.\\.)',
125 token
: 'keyword.operator',
130 regex
: '\\\\\\S[^\\s,;)}\\]]*'
156 token
: 'string.regex',
160 token
: 'string.regex',
161 regex
: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',
164 token
: 'constant.numeric',
165 regex
: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'
174 token
: 'keyword.operator',
183 token
: 'string.regex',
184 regex
: '.*?//[gimy$?]{0,4}',
187 token
: 'string.regex',
190 token
: 'comment.regex',
191 regex
: '\\s+(?:#.*)?'
193 token
: 'string.regex',
199 token
: 'keyword.operator',
213 token
: 'comment.doc',
217 token
: 'comment.doc',
238 regex
: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',
245 regex
: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
252 regex
: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',
264 for (var idx
in Rules
) {
267 for (var i
= 0, len
= r
.length
; i
< len
; ++i
) {
269 if (typeof rr
.regex
=== 'string') {
270 Rules
[idx
][i
].regex
= new RegExp('^' + rr
.regex
);
273 } else if (typeof rr
.regex
=== 'string') {
274 Rules
[idx
].regex
= new RegExp('^' + r
.regex
);
278 CodeMirror
.defineMIME('text/x-livescript', 'livescript');