-
Notifications
You must be signed in to change notification settings - Fork 156
/
lang-ls.ls
80 lines (75 loc) · 2.55 KB
/
lang-ls.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# LiveScript language plugin for
# [google-code-prettify](http://code.google.com/p/google-code-prettify/).
tint = (ext, shortcuts, fallthroughs) ->
for rule in shortcuts when rule.length < 4 then rule.splice 2 0 0
PR.registerLangHandler PR.createSimpleLexer(shortcuts, fallthroughs), [ext]
ident = /(?![\d\s])[$\w\xAA-\uFFDC](?:(?!\s)[$\w\xAA-\uFFDC]|-[A-Za-z])*/$
kwend = /(?!(?!\s)[$\w\xAA-\uFFDC]|-[A-Za-z])/$
### Main
tint \ls [
[\str // ^ '(?: ''[\S\s]*?'' | [^\\']*(?:\\[\S\s][^\\']*)* )' // \']
[\lang-ls-qq //(^ "(?: ""[\S\s]*?"" | [^\\"]*(?:\\[\S\s][^\\"]*)* )" )// \"]
[\lang-ls-qr //(^ / / [\S\s]*? / / [gimy$?]{0,4} )// \/]
[\lang-ls-at //(^ @@? #ident? )// \@]
[\com /^#.*/ \#]
[\typ // ^ (?
: 0x[\da-f][\da-f_]*
| (?:[2-9]|[12]\d|3[0-6]) r [\da-z][\da-z_]*
| \d[\d_]*(?:\.\d[\d_]*)? (?:e[+-]?\d[\d_]*)? [\w$]*
) //i \0123456789]
[\lang-js /^`([^\\`]*(?:\\[\S\s][^\\`]*)*)`/ \`]
] [
[\str // ^ \\ \S [^\s,;)}\]]* //]
[\com // ^ /\* [\S\s]* \*/ //]
[\pln // ^ (?
: \.{3}
| (?: \.\s*(?:(?:[-+*/%&|^:]|>>>?|<<)?=|[~!@])?\s* | [)}\]?] | :: )
(?: #ident[?~!@]? )+
| #ident [^\n\S]* :(?![:=])
) //]
# ref. [retrie](https://github.com/satyr/retrie)
[\kwd // ^ (?![$_-]) (?
: t(?:ry|h(?:row|en)|ypeof!?)
| f(?:or(?:[^\n\S]+(?:own|ever))?|inally|unction)
| n(?:ew|ot|o)
| c(?:on(?:tinue|st)|a(?:se|tch)|lass)
| i(?:[fs]|n(?:stanceof)?|mp(?:ort(?:[^\n\S]+all)?|lements))
| e(?:lse|x(?:tends|port))
| d(?:e(?:fault|lete|bugger)|o)
| un(?:less|til)
| w(?:hile|ith|hen)
| s(?:witch|uper)
| a(?:nd|wait)
| o[frn] | off | return | break | let | var | loop | yes | yield
) #kwend //]
[\typ // ^ (?: true | false | null | void ) #kwend //]
[\ctx // ^ (?
: t(?:h(?:is|at)|o|il)
| f(?:rom|allthrough)
| e(?:val)?
| it | arguments | by | constructor | prototype | superclass | async
) #kwend //]
[\glb // ^ (?
: Array | Boolean | Date | Error | Function | JSON | Math | Number
| Object | RegExp | S(?:tring|yntaxError) | TypeError
| is(?:NaN|Finite) | parse(?:Int|Float) | (?:en|de)codeURI(?:Component)?
) #kwend //]
[\var // ^ #ident //]
[\str /^<\[[\S\s]*?]>/]
[\lang-ls-r // ^ [^/] (
/ (?![\s/])
[^ [ / \n \\ ]*
(?:
(?: \\.
| \[ [^\]\n\\]*(?:\\.[^\]\n\\]*)* \]
) [^ [ / \n \\ ]*
)* / [gimy$]{0,4}
) (?!\d) //]
]
### Subrules
interps = [\lang-ls // ^# ({[\S\s]*?} | #ident) // \#]
regexes = [\lit /^[\S\s]+?/]
tint \ls-qq [interps] [[\str /^[\S\s]+?/]]
tint \ls-qr [interps] [[\com /^\s#(?!{).*/] regexes]
tint \ls-r [] [regexes]
tint \ls-at [[\ctx /^@+/ \@]] []