Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / mode / livescript / livescript.ls
1 /**
2  * Link to the project's GitHub page:
3  * https://github.com/duralog/CodeMirror
4  */
5 CodeMirror.defineMode 'livescript', (conf) ->
6   tokenBase = (stream, state) ->
7     #indent =
8     if next_rule = state.next or \start
9       state.next = state.next
10       if Array.isArray nr = Rules[next_rule]
11         for r in nr
12           if r.regex and m = stream.match r.regex
13             state.next = r.next
14             return r.token
15         stream.next!
16         return \error
17       if stream.match r = Rules[next_rule]
18         if r.regex and stream.match r.regex
19           state.next = r.next
20           return r.token
21         else
22           stream.next!
23           return \error
24     stream.next!
25     return 'error'
26   external = {
27     startState: (basecolumn) ->
28       {
29         next: \start
30         lastToken: null
31       }
32     token: (stream, state) ->
33       style = tokenBase stream, state #tokenLexer stream, state
34       state.lastToken = {
35         style: style
36         indent: stream.indentation!
37         content: stream.current!
38       }
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
44       return indentation
45   }
46   external
47
48 ### Highlight Rules
49 # taken from mode-ls.ls
50
51 indenter = // (?
52     : [({[=:]
53     | [-~]>
54     | \b (?: e(?:lse|xport) | d(?:o|efault) | t(?:ry|hen) | finally |
55              import (?:\s* all)? | const | var |
56              let | new | catch (?:\s* #identifier)? )
57   ) \s* $ //
58
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: '.+'
62
63 Rules =
64   start:
65     * token: \comment.doc
66       regex: '/\\*'
67       next : \comment
68
69     * token: \comment
70       regex: '#.*'
71
72     * token: \keyword
73       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)
79         |s(?:uper|witch)
80         |e(?:lse|x(?:tends|port)|val)
81         |a(?:nd|rguments)
82         |n(?:ew|ot)
83         |un(?:less|til)
84         |w(?:hile|ith)
85         |o[fr]|return|break|let|var|loop
86       )//$ + keywordend
87
88     * token: \constant.language
89       regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
90
91     * token: \invalid.illegal
92       regex: '(?
93         :p(?:ackage|r(?:ivate|otected)|ublic)
94         |i(?:mplements|nterface)
95         |enum|static|yield
96       )' + keywordend
97
98     * token: \language.support.class
99       regex: '(?
100         :R(?:e(?:gExp|ferenceError)|angeError)
101         |S(?:tring|yntaxError)
102         |E(?:rror|valError)
103         |Array|Boolean|Date|Function|Number|Object|TypeError|URIError
104       )' + keywordend
105
106     * token: \language.support.function
107       regex: '(?
108         :is(?:NaN|Finite)
109         |parse(?:Int|Float)
110         |Math|JSON
111         |(?:en|de)codeURI(?:Component)?
112       )' + keywordend
113
114     * token: \variable.language
115       regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
116
117     * token: \identifier
118       regex: identifier + /\s*:(?![:=])/$
119
120     * token: \variable
121       regex: identifier
122
123     * token: \keyword.operator
124       regex: /(?:\.{3}|\s+\?)/$
125
126     * token: \keyword.variable
127       regex: /(?:@+|::|\.\.)/$
128       next : \key
129
130     * token: \keyword.operator
131       regex: /\.\s*/$
132       next : \key
133
134     * token: \string
135       regex: /\\\S[^\s,;)}\]]*/$
136
137     * token: \string.doc
138       regex: \'''
139       next : \qdoc
140
141     * token: \string.doc
142       regex: \"""
143       next : \qqdoc
144
145     * token: \string
146       regex: \'
147       next : \qstring
148
149     * token: \string
150       regex: \"
151       next : \qqstring
152
153     * token: \string
154       regex: \`
155       next : \js
156
157     * token: \string
158       regex: '<\\['
159       next : \words
160
161     * token: \string.regex
162       regex: \//
163       next : \heregex
164
165     * token: \string.regex
166       regex: //
167         /(?: [^ [ / \n \\ ]*
168           (?: (?: \\.
169                 | \[ [^\]\n\\]* (?:\\.[^\]\n\\]*)* \]
170               ) [^ [ / \n \\ ]*
171           )*
172         )/ [gimy$]{0,4}
173       //$
174       next : \key
175
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$]*)'
181
182     * token: \lparen
183       regex: '[({[]'
184
185     * token: \rparen
186       regex: '[)}\\]]'
187       next : \key
188
189     * token: \keyword.operator
190       regex: \\\S+
191
192     * token: \text
193       regex: \\\s+
194
195   heregex:
196     * token: \string.regex
197       regex: '.*?//[gimy$?]{0,4}'
198       next : \start
199     * token: \string.regex
200       regex: '\\s*#{'
201     * token: \comment.regex
202       regex: '\\s+(?:#.*)?'
203     * token: \string.regex
204       regex: '\\S+'
205
206   key:
207     * token: \keyword.operator
208       regex: '[.?@!]+'
209     * token: \identifier
210       regex: identifier
211       next : \start
212     * token: \text
213       regex: '.'
214       next : \start
215
216   comment:
217     * token: \comment.doc
218       regex: '.*?\\*/'
219       next : \start
220     * token: \comment.doc
221       regex: '.+'
222
223   qdoc:
224     token: \string
225     regex: ".*?'''"
226     next : \key
227     stringfill
228
229   qqdoc:
230     token: \string
231     regex: '.*?"""'
232     next : \key
233     stringfill
234
235   qstring:
236     token: \string
237     regex: /[^\\']*(?:\\.[^\\']*)*'/$
238     next : \key
239     stringfill
240
241   qqstring:
242     token: \string
243     regex: /[^\\"]*(?:\\.[^\\"]*)*"/$
244     next : \key
245     stringfill
246
247   js:
248     token: \string
249     regex: /[^\\`]*(?:\\.[^\\`]*)*`/$
250     next : \key
251     stringfill
252
253   words:
254     token: \string
255     regex: '.*?\\]>'
256     next : \key
257     stringfill
258
259 # for optimization, precompile the regexps
260 for idx, r of Rules
261   if Array.isArray r
262     for rr, i in r
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
265
266 CodeMirror.defineMIME 'text/x-livescript', 'livescript'