diff options
Diffstat (limited to 'imports/codemirror/mode/coffeescript')
-rw-r--r--[-rwxr-xr-x] | imports/codemirror/mode/coffeescript/LICENSE | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | imports/codemirror/mode/coffeescript/coffeescript.js | 90 | ||||
-rw-r--r--[-rwxr-xr-x] | imports/codemirror/mode/coffeescript/index.html | 0 |
3 files changed, 53 insertions, 37 deletions
diff --git a/imports/codemirror/mode/coffeescript/LICENSE b/imports/codemirror/mode/coffeescript/LICENSE index 977e284e..977e284e 100755..100644 --- a/imports/codemirror/mode/coffeescript/LICENSE +++ b/imports/codemirror/mode/coffeescript/LICENSE | |||
diff --git a/imports/codemirror/mode/coffeescript/coffeescript.js b/imports/codemirror/mode/coffeescript/coffeescript.js index d4d57239..4f2bd66d 100755..100644 --- a/imports/codemirror/mode/coffeescript/coffeescript.js +++ b/imports/codemirror/mode/coffeescript/coffeescript.js | |||
@@ -4,17 +4,17 @@ | |||
4 | */ | 4 | */ |
5 | CodeMirror.defineMode('coffeescript', function(conf) { | 5 | CodeMirror.defineMode('coffeescript', function(conf) { |
6 | var ERRORCLASS = 'error'; | 6 | var ERRORCLASS = 'error'; |
7 | 7 | ||
8 | function wordRegexp(words) { | 8 | function wordRegexp(words) { |
9 | return new RegExp("^((" + words.join(")|(") + "))\\b"); | 9 | return new RegExp("^((" + words.join(")|(") + "))\\b"); |
10 | } | 10 | } |
11 | 11 | ||
12 | var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]"); | 12 | var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]"); |
13 | var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); | 13 | var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); |
14 | var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))"); | 14 | var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))"); |
15 | var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); | 15 | var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); |
16 | var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))"); | 16 | var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))"); |
17 | var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*"); | 17 | var identifiers = new RegExp("^[_A-Za-z$][_A-Za-z$0-9]*"); |
18 | 18 | ||
19 | var wordOperators = wordRegexp(['and', 'or', 'not', | 19 | var wordOperators = wordRegexp(['and', 'or', 'not', |
20 | 'is', 'isnt', 'in', | 20 | 'is', 'isnt', 'in', |
@@ -57,15 +57,21 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
57 | if (stream.eatSpace()) { | 57 | if (stream.eatSpace()) { |
58 | return null; | 58 | return null; |
59 | } | 59 | } |
60 | 60 | ||
61 | var ch = stream.peek(); | 61 | var ch = stream.peek(); |
62 | 62 | ||
63 | // Handle comments | 63 | // Handle multi line comments |
64 | if (stream.match("###")) { | ||
65 | state.tokenize = longComment; | ||
66 | return state.tokenize(stream, state); | ||
67 | } | ||
68 | |||
69 | // Single line comment | ||
64 | if (ch === '#') { | 70 | if (ch === '#') { |
65 | stream.skipToEnd(); | 71 | stream.skipToEnd(); |
66 | return 'comment'; | 72 | return 'comment'; |
67 | } | 73 | } |
68 | 74 | ||
69 | // Handle number literals | 75 | // Handle number literals |
70 | if (stream.match(/^-?[0-9\.]/, false)) { | 76 | if (stream.match(/^-?[0-9\.]/, false)) { |
71 | var floatLiteral = false; | 77 | var floatLiteral = false; |
@@ -79,7 +85,12 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
79 | if (stream.match(/^-?\.\d+/)) { | 85 | if (stream.match(/^-?\.\d+/)) { |
80 | floatLiteral = true; | 86 | floatLiteral = true; |
81 | } | 87 | } |
88 | |||
82 | if (floatLiteral) { | 89 | if (floatLiteral) { |
90 | // prevent from getting extra . on 1.. | ||
91 | if (stream.peek() == "."){ | ||
92 | stream.backUp(1); | ||
93 | } | ||
83 | return 'number'; | 94 | return 'number'; |
84 | } | 95 | } |
85 | // Integers | 96 | // Integers |
@@ -100,7 +111,7 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
100 | return 'number'; | 111 | return 'number'; |
101 | } | 112 | } |
102 | } | 113 | } |
103 | 114 | ||
104 | // Handle strings | 115 | // Handle strings |
105 | if (stream.match(stringPrefixes)) { | 116 | if (stream.match(stringPrefixes)) { |
106 | state.tokenize = tokenFactory(stream.current(), 'string'); | 117 | state.tokenize = tokenFactory(stream.current(), 'string'); |
@@ -115,7 +126,7 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
115 | stream.backUp(1); | 126 | stream.backUp(1); |
116 | } | 127 | } |
117 | } | 128 | } |
118 | 129 | ||
119 | // Handle operators and delimiters | 130 | // Handle operators and delimiters |
120 | if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { | 131 | if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { |
121 | return 'punctuation'; | 132 | return 'punctuation'; |
@@ -128,28 +139,26 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
128 | if (stream.match(singleDelimiters)) { | 139 | if (stream.match(singleDelimiters)) { |
129 | return 'punctuation'; | 140 | return 'punctuation'; |
130 | } | 141 | } |
131 | 142 | ||
132 | if (stream.match(constants)) { | 143 | if (stream.match(constants)) { |
133 | return 'atom'; | 144 | return 'atom'; |
134 | } | 145 | } |
135 | 146 | ||
136 | if (stream.match(keywords)) { | 147 | if (stream.match(keywords)) { |
137 | return 'keyword'; | 148 | return 'keyword'; |
138 | } | 149 | } |
139 | 150 | ||
140 | if (stream.match(identifiers)) { | 151 | if (stream.match(identifiers)) { |
141 | return 'variable'; | 152 | return 'variable'; |
142 | } | 153 | } |
143 | 154 | ||
144 | // Handle non-detected items | 155 | // Handle non-detected items |
145 | stream.next(); | 156 | stream.next(); |
146 | return ERRORCLASS; | 157 | return ERRORCLASS; |
147 | } | 158 | } |
148 | 159 | ||
149 | function tokenFactory(delimiter, outclass) { | 160 | function tokenFactory(delimiter, outclass) { |
150 | var delim_re = new RegExp(delimiter); | ||
151 | var singleline = delimiter.length == 1; | 161 | var singleline = delimiter.length == 1; |
152 | |||
153 | return function tokenString(stream, state) { | 162 | return function tokenString(stream, state) { |
154 | while (!stream.eol()) { | 163 | while (!stream.eol()) { |
155 | stream.eatWhile(/[^'"\/\\]/); | 164 | stream.eatWhile(/[^'"\/\\]/); |
@@ -158,7 +167,7 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
158 | if (singleline && stream.eol()) { | 167 | if (singleline && stream.eol()) { |
159 | return outclass; | 168 | return outclass; |
160 | } | 169 | } |
161 | } else if (stream.match(delim_re)) { | 170 | } else if (stream.match(delimiter)) { |
162 | state.tokenize = tokenBase; | 171 | state.tokenize = tokenBase; |
163 | return outclass; | 172 | return outclass; |
164 | } else { | 173 | } else { |
@@ -175,7 +184,19 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
175 | return outclass; | 184 | return outclass; |
176 | }; | 185 | }; |
177 | } | 186 | } |
178 | 187 | ||
188 | function longComment(stream, state) { | ||
189 | while (!stream.eol()) { | ||
190 | stream.eatWhile(/[^#]/); | ||
191 | if (stream.match("###")) { | ||
192 | state.tokenize = tokenBase; | ||
193 | break; | ||
194 | } | ||
195 | stream.eatWhile("#"); | ||
196 | } | ||
197 | return "comment" | ||
198 | } | ||
199 | |||
179 | function indent(stream, state, type) { | 200 | function indent(stream, state, type) { |
180 | type = type || 'coffee'; | 201 | type = type || 'coffee'; |
181 | var indentUnit = 0; | 202 | var indentUnit = 0; |
@@ -194,7 +215,7 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
194 | type: type | 215 | type: type |
195 | }); | 216 | }); |
196 | } | 217 | } |
197 | 218 | ||
198 | function dedent(stream, state) { | 219 | function dedent(stream, state) { |
199 | if (state.scopes.length == 1) return; | 220 | if (state.scopes.length == 1) return; |
200 | if (state.scopes[0].type === 'coffee') { | 221 | if (state.scopes[0].type === 'coffee') { |
@@ -233,18 +254,13 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||
233 | return ERRORCLASS; | 254 | return ERRORCLASS; |
234 | } | 255 | } |
235 | } | 256 | } |
236 | 257 | ||
237 | // Handle properties | 258 | // Handle properties |
238 | if (current === '@') { | 259 | if (current === '@') { |
239 | style = state.tokenize(stream, state); | 260 | stream.eat('@'); |
240 | current = stream.current(); | 261 | return 'keyword'; |
241 | if (style === 'variable') { | ||
242 | return 'variable-2'; | ||
243 | } else { | ||
244 | return ERRORCLASS; | ||
245 | } | ||
246 | } | 262 | } |
247 | 263 | ||
248 | // Handle scope changes. | 264 | // Handle scope changes. |
249 | if (current === 'return') { | 265 | if (current === 'return') { |
250 | state.dedent += 1; | 266 | state.dedent += 1; |
@@ -266,7 +282,7 @@ CodeMirror.defineMode('coffeescript', function(conf) { | |||