| 1 |
# Defines an editing mode for [Ace](https://ace.c9.io). |
| 2 |
# |
| 3 |
# Open [test/ace.html](../test/ace.html) to test. |
| 4 |
|
| 5 |
require, exports, module <-! define \ace/mode/ls |
| 6 |
|
| 7 |
identifier = /(?![\d\s])[$\w\xAA-\uFFDC](?:(?!\s)[$\w\xAA-\uFFDC]|-[A-Za-z])*/$ |
| 8 |
|
| 9 |
exports.Mode = class LiveScriptMode extends require(\ace/mode/text)Mode |
| 10 |
-> |
| 11 |
@$tokenizer = |
| 12 |
new (require \ace/tokenizer)Tokenizer LiveScriptMode.Rules |
| 13 |
if require \ace/mode/matching_brace_outdent |
| 14 |
@$outdent = new that.MatchingBraceOutdent |
| 15 |
|
| 16 |
indenter = // (? |
| 17 |
: [({[=:] |
| 18 |
| [-~]> |
| 19 |
| \b (?: e(?:lse|xport) | d(?:o|efault) | t(?:ry|hen) | finally | |
| 20 |
import (?:\s* all)? | const | var | |
| 21 |
let | new | catch (?:\s* #identifier)? ) |
| 22 |
) \s* $ // |
| 23 |
|
| 24 |
getNextLineIndent: (state, line, tab) -> |
| 25 |
indent = @$getIndent line |
| 26 |
{tokens} = @$tokenizer.getLineTokens line, state |
| 27 |
unless tokens.length and tokens[*-1]type is \comment |
| 28 |
indent += tab if state is \start and indenter.test line |
| 29 |
indent |
| 30 |
|
| 31 |
toggleCommentLines: (state, doc, startRow, endRow) -> |
| 32 |
comment = /^(\s*)#/; range = new (require \ace/range)Range 0 0 0 0 |
| 33 |
for i from startRow to endRow |
| 34 |
if out = comment.test line = doc.getLine i |
| 35 |
then line.=replace comment, \$1 |
| 36 |
else line.=replace /^\s*/ \$&# |
| 37 |
range.end.row = range.start.row = i |
| 38 |
range.end.column = line.length + 1 |
| 39 |
doc.replace range, line |
| 40 |
1 - out * 2 |
| 41 |
|
| 42 |
checkOutdent: (state, line, input) -> @$outdent?checkOutdent line, input |
| 43 |
|
| 44 |
autoOutdent: (state, doc, row) -> @$outdent?autoOutdent doc, row |
| 45 |
|
| 46 |
### Highlight Rules |
| 47 |
|
| 48 |
keywordend = /(?![$\w]|-[A-Za-z]|\s*:(?![:=]))/$ |
| 49 |
stringfill = token: \string, regex: '.+' |
| 50 |
|
| 51 |
LiveScriptMode.Rules = |
| 52 |
start: |
| 53 |
* token: \keyword |
| 54 |
regex: //(? |
| 55 |
:t(?:h(?:is|row|en)|ry|ypeof!?) |
| 56 |
|c(?:on(?:tinue|st)|a(?:se|tch)|lass) |
| 57 |
|i(?:n(?:stanceof)?|mp(?:ort(?:\s+all)?|lements)|[fs]) |
| 58 |
|d(?:e(?:fault|lete|bugger)|o) |
| 59 |
|f(?:or(?:\s+own)?|inally|unction) |
| 60 |
|s(?:uper|witch) |
| 61 |
|e(?:lse|x(?:tends|port)|val) |
| 62 |
|a(?:nd|rguments) |
| 63 |
|n(?:ew|ot) |
| 64 |
|un(?:less|til) |
| 65 |
|w(?:hile|ith) |
| 66 |
|o[fr]|return|break|let|var|loop |
| 67 |
)//$ + keywordend |
| 68 |
|
| 69 |
* token: \constant.language |
| 70 |
regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend |
| 71 |
|
| 72 |
* token: \invalid.illegal |
| 73 |
regex: '(? |
| 74 |
:p(?:ackage|r(?:ivate|otected)|ublic) |
| 75 |
|i(?:mplements|nterface) |
| 76 |
|enum|static|yield |
| 77 |
)' + keywordend |
| 78 |
|
| 79 |
* token: \language.support.class |
| 80 |
regex: '(? |
| 81 |
:R(?:e(?:gExp|ferenceError)|angeError) |
| 82 |
|S(?:tring|yntaxError) |
| 83 |
|E(?:rror|valError) |
| 84 |
|Array|Boolean|Date|Function|Number|Object|TypeError|URIError |
| 85 |
)' + keywordend |
| 86 |
|
| 87 |
* token: \language.support.function |
| 88 |
regex: '(? |
| 89 |
:is(?:NaN|Finite) |
| 90 |
|parse(?:Int|Float) |
| 91 |
|Math|JSON |
| 92 |
|(?:en|de)codeURI(?:Component)? |
| 93 |
)' + keywordend |
| 94 |
|
| 95 |
* token: \variable.language |
| 96 |
regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend |
| 97 |
|
| 98 |
* token: \identifier |
| 99 |
regex: identifier + /\s*:(?![:=])/$ |
| 100 |
|
| 101 |
* token: \variable |
| 102 |
regex: identifier |
| 103 |
|
| 104 |
* token: \keyword.operator |
| 105 |
regex: /(?:\.{3}|\s+\?)/$ |
| 106 |
|
| 107 |
* token: \keyword.variable |
| 108 |
regex: /(?:@+|::|\.\.)/$ |
| 109 |
next : \key |
| 110 |
|
| 111 |
* token: \keyword.operator |
| 112 |
regex: /\.\s*/$ |
| 113 |
next : \key |
| 114 |
|
| 115 |
* token: \string |
| 116 |
regex: /\\\S[^\s,;)}\]]*/$ |
| 117 |
|
| 118 |
* token: \string.doc |
| 119 |
regex: \''' |
| 120 |
next : \qdoc |
| 121 |
|
| 122 |
* token: \string.doc |
| 123 |
regex: \""" |
| 124 |
next : \qqdoc |
| 125 |
|
| 126 |
* token: \string |
| 127 |
regex: \' |
| 128 |
next : \qstring |
| 129 |
|
| 130 |
* token: \string |
| 131 |
regex: \" |
| 132 |
next : \qqstring |
| 133 |
|
| 134 |
* token: \string |
| 135 |
regex: \` |
| 136 |
next : \js |
| 137 |
|
| 138 |
* token: \string |
| 139 |
regex: '<\\[' |
| 140 |
next : \words |
| 141 |
|
| 142 |
* token: \string.regex |
| 143 |
regex: \// |
| 144 |
next : \heregex |
| 145 |
|
| 146 |
* token: \comment.doc |
| 147 |
regex: '/\\*' |
| 148 |
next : \comment |
| 149 |
|
| 150 |
* token: \comment |
| 151 |
regex: '#.*' |
| 152 |
|
| 153 |
* token: \string.regex |
| 154 |
regex: // |
| 155 |
/(?: [^ [ / \n \\ ]* |
| 156 |
(?: (?: \\. |
| 157 |
| \[ [^\]\n\\]* (?:\\.[^\]\n\\]*)* \] |
| 158 |
) [^ [ / \n \\ ]* |
| 159 |
)* |
| 160 |
)/ [gimy$]{0,4} |
| 161 |
//$ |
| 162 |
next : \key |
| 163 |
|
| 164 |
* token: \constant.numeric |
| 165 |
regex: '(?:0x[\\da-fA-F][\\da-fA-F_]* |
| 166 |
|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]* |
| 167 |
|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*) |
| 168 |
(?:e[+-]?\\d[\\d_]*)?[\\w$]*)' |
| 169 |
|
| 170 |
* token: \lparen |
| 171 |
regex: '[({[]' |
| 172 |
|
| 173 |
* token: \rparen |
| 174 |
regex: '[)}\\]]' |
| 175 |
next : \key |
| 176 |
|
| 177 |
* token: \keyword.operator |
| 178 |
regex: \\\S+ |
| 179 |
|
| 180 |
* token: \text |
| 181 |
regex: \\\s+ |
| 182 |
|
| 183 |
heregex: |
| 184 |
* token: \string.regex |
| 185 |
regex: '.*?//[gimy$?]{0,4}' |
| 186 |
next : \start |
| 187 |
* token: \string.regex |
| 188 |
regex: '\\s*#{' |
| 189 |
* token: \comment.regex |
| 190 |
regex: '\\s+(?:#.*)?' |
| 191 |
* token: \string.regex |
| 192 |
regex: '\\S+' |
| 193 |
|
| 194 |
key: |
| 195 |
* token: \keyword.operator |
| 196 |
regex: '[.?@!]+' |
| 197 |
* token: \identifier |
| 198 |
regex: identifier |
| 199 |
next : \start |
| 200 |
* token: \text |
| 201 |
regex: '.' |
| 202 |
next : \start |
| 203 |
|
| 204 |
comment: |
| 205 |
* token: \comment.doc |
| 206 |
regex: '.*?\\*/' |
| 207 |
next : \start |
| 208 |
* token: \comment.doc |
| 209 |
regex: '.+' |
| 210 |
|
| 211 |
qdoc: |
| 212 |
token: \string |
| 213 |
regex: ".*?'''" |
| 214 |
next : \key |
| 215 |
stringfill |
| 216 |
|
| 217 |
qqdoc: |
| 218 |
token: \string |
| 219 |
regex: '.*?"""' |
| 220 |
next : \key |
| 221 |
stringfill |
| 222 |
|
| 223 |
qstring: |
| 224 |
token: \string |
| 225 |
regex: /[^\\']*(?:\\.[^\\']*)*'/$ |
| 226 |
next : \key |
| 227 |
stringfill |
| 228 |
|
| 229 |
qqstring: |
| 230 |
token: \string |
| 231 |
regex: /[^\\"]*(?:\\.[^\\"]*)*"/$ |
| 232 |
next : \key |
| 233 |
stringfill |
| 234 |
|
| 235 |
js: |
| 236 |
token: \string |
| 237 |
regex: /[^\\`]*(?:\\.[^\\`]*)*`/$ |
| 238 |
next : \key |
| 239 |
stringfill |
| 240 |
|
| 241 |
words: |
| 242 |
token: \string |
| 243 |
regex: '.*?\\]>' |
| 244 |
next : \key |
| 245 |
stringfill |