]> git.saurik.com Git - cycript.git/blob - Cycript.l.in
38a9459deb1d8f2bba31c734c201b90f8eb70266
[cycript.git] / Cycript.l.in
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 %top{
23 #if defined(__clang__)
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wdeprecated-register"
26 #pragma clang diagnostic ignored "-Wunused-function"
27 #pragma clang diagnostic ignored "-Wunused-variable"
28 #else
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wsign-compare"
31 #pragma GCC diagnostic ignored "-Wunused-function"
32 #pragma GCC diagnostic ignored "-Wunused-variable"
33 #endif
34 }
35
36 %{
37
38 #define YYLTYPE CYLocation
39 #include "Cycript.tab.hh"
40 typedef cy::parser::token tk;
41
42 #include "Highlight.hpp"
43
44 #define YY_EXTRA_TYPE CYDriver *
45
46 // do /not/ fold token to the return: this is a macro and the ordering is dependent
47 #define F(value, highlight) do { \
48 int token(value); \
49 yyextra->no_.Class = false; \
50 yyextra->no_.Function = false; \
51 yyextra->no_.NewLine = false; \
52 yyextra->no_.OpenBrace = false; \
53 yylval->highlight_ = highlight; \
54 return token; \
55 } while (false)
56
57 #define P yyextra->pool_
58 #define A new(P)
59 #define Y P.strmemdup(yytext, yyleng)
60
61 #define I(type, Type, value, highlight) do { \
62 yylval->semantic_.type ## _ = A CY ## Type; \
63 F(value, highlight); \
64 } while (false)
65
66 #define C \
67 yyextra->newline_ = yyextra->last_; \
68 yyextra->last_ = false; \
69 BEGIN(yyextra->template_.top() ? DivOrTemplateTail : Div);
70
71 #define N \
72 if (yyextra->last_ && yyextra->no_.NewLine) { \
73 yyextra->last_ = false; \
74 F(tk::NewLine, hi::Nothing); \
75 }
76
77 #define V(more) { \
78 if (const char *nl = reinterpret_cast<const char *>(memchr(yytext, '\n', yyleng))) { \
79 unsigned lines(0); \
80 size_t left; \
81 do { \
82 ++lines; \
83 left = yyleng - (nl - yytext) - 1; \
84 nl = reinterpret_cast<const char *>(memchr(nl + 1, '\n', left)); \
85 } while (nl != NULL); \
86 yylloc->step(); \
87 yylloc->end.lines(lines); \
88 yylloc->end.columns(left); \
89 more \
90 } else L \
91 }
92
93 #define R yylloc->end.columns(yyleng);
94 #define L yylloc->step(); R
95
96 #define H(value, highlight) do { \
97 if (yyextra->highlight_) \
98 F(value, highlight); \
99 } while (false)
100
101 #define M \
102 H(tk::Comment, hi::Comment);
103
104 #define E(message) { \
105 CYDriver::Error error; \
106 error.location_ = *yylloc; \
107 error.message_ = "syntax error, " message; \
108 yyextra->errors_.push_back(error); \
109 yyterminate(); \
110 }
111
112 int X(char c) {
113 if (c >= '0' && c <= '9')
114 return c - '0';
115 if (c >= 'a' && c <= 'f')
116 return c - 'a' + 10;
117 if (c >= 'A' && c <= 'F')
118 return c - 'A' + 10;
119 return -1;
120 }
121
122 template <typename Type_>
123 static void U(Type_ &local, unsigned point) {
124 if (false) {
125 } else if (point < 0x000080) {
126 *local++ = point;
127 } else if (point < 0x000800) {
128 *local++ = 0xc0 | point >> 0x06 & 0x1f;
129 goto one;
130 } else if (point < 0x010000) {
131 *local++ = 0xe0 | point >> 0x0c & 0x0f;
132 goto two;
133 } else if (point < 0x110000) {
134 *local++ = 0xf0 | point >> 0x12 & 0x07;
135 *local++ = 0x80 | point >> 0x0c & 0x3f;
136 two:
137 *local++ = 0x80 | point >> 0x06 & 0x3f;
138 one:
139 *local++ = 0x80 | point >> 0x00 & 0x3f;
140 } else _assert(false);
141 }
142
143 static void U(char *&local, const char *text, yy_size_t &i) {
144 unsigned point;
145
146 char next(text[++i]);
147 if (next != '{') {
148 point = X(text[i + 0]) << 12 | X(text[i + 1]) << 8 | X(text[i + 2]) << 4 | X(text[i + 3]);
149 i += 3;
150 } else {
151 point = 0;
152 for (;;) {
153 next = text[++i];
154 if (next == '}')
155 break;
156 point = (point << 4) | X(next);
157 }
158 }
159
160 U(local, point);
161 }
162
163 #define CYLexBufferPoint(point) do { \
164 std::back_insert_iterator<std::vector<char> > inserter(yyextra->buffer_); \
165 U(inserter, point); \
166 } while (false)
167
168 #define CYLexBufferUnit(value) do { \
169 yyextra->buffer_.push_back(value); \
170 } while (false)
171
172 #define CYLexBufferUnits(data, size) do { \
173 yyextra->buffer_.insert(yyextra->buffer_.end(), data, data + size); \
174 } while (false)
175
176 #define CYLexBufferStart(condition) do { \
177 yyextra->buffer_.clear(); \
178 yy_push_state(condition, yyscanner); \
179 } while (false)
180
181 #define CYLexBufferEnd(type, Type, value, highlight) do { \
182 yy_pop_state(yyscanner); \
183 C I(type, Type(P.strmemdup(yyextra->buffer_.data(), yyextra->buffer_.size()), yyextra->buffer_.size()), value, highlight); \
184 } while (false)
185
186 #define YY_INPUT(data, value, size) { \
187 if (yyextra->data_.eof()) \
188 value = YY_NULL; \
189 else { \
190 yyextra->data_.read(data, size); \
191 size_t copy(yyextra->data_.gcount()); \
192 value = copy == 0 ? YY_NULL : copy; \
193 } \
194 }
195
196 %}
197
198 %option prefix="cy"
199 %option bison-bridge
200 %option bison-locations
201 %option nodefault
202 %option noyywrap
203 %option noyylineno
204 %option nounput
205 %option nounistd
206 %option 8bit
207 %option backup
208 %option batch
209 %option never-interactive
210 %option pointer
211 %option reentrant
212 %option stack
213
214 %option full
215 %option ecs
216
217 U1 [\x00-\x7f]
218 U0 [\x80-\xbf]
219 U2 [\xc2-\xdf]
220 U3 [\xe0-\xef]
221 U4 [\xf0-\xf4]
222 UN [\xc0-\xc1\xf5-\xff]
223
224 HexDigit [0-9a-fA-F]
225 LineTerminatorSequence \r?\n|\r|\xe2\x80[\xa8\xa9]
226 WhiteSpace [\x09\x0b\x0c\x20]|\xc2\xa0|\xef\xbb\xbf
227 UnicodeEscape \\u({HexDigit}{4}|\{{HexDigit}+\})
228
229 @include NotLineTerminator.l
230 CommentCharacter [^*/]{-}[\r\n\x80-\xff]|{NotLineTerminator}
231 SingleCharacter [^'\\]{-}[\r\n\x80-\xff]|{NotLineTerminator}
232 DoubleCharacter [^"\\]{-}[\r\n\x80-\xff]|{NotLineTerminator}
233 PlateCharacter [^$`\\]{-}[\r\n\x80-\xff]|{NotLineTerminator}
234
235 @include UnicodeIDStart.l
236 @include UnicodeIDContinue.l
237 IdentifierMore [$_]
238
239 UnicodeStart {IdentifierMore}|{UnicodeIDStart}
240 UnicodePart {IdentifierMore}|\xe2\x80[\x8c\x8d]|{UnicodeIDContinue}
241 UnicodeFail {U2}|{U3}|{U3}{U0}|{U4}|{U4}{U0}|{U4}{U0}{U0}|{UN}|{U0}
242 UnicodeScrap {UnicodePart}*{UnicodeFail}?
243
244 IdentifierStart {UnicodeStart}|{UnicodeEscape}
245 IdentifierPart {UnicodePart}|{UnicodeEscape}
246 IdentifierFail {UnicodeFail}|\\(u({HexDigit}{0,3}|\{{HexDigit}*))?
247 IdentifierScrap {IdentifierPart}*{IdentifierFail}?
248
249 NonTerminator [^\n]
250 BackslashSequence \\{NonTerminator}
251 RegularExpressionFirstChar [^\n*\\/]|{BackslashSequence}
252 RegularExpressionChar [^\n\\/]|{BackslashSequence}
253 RegularExpressionFlags {UnicodePart}*
254 RegularExpressionChars {RegularExpressionChar}*
255 RegularExpressionBody {RegularExpressionFirstChar}{RegularExpressionChars}
256
257 @begin E4X
258 XMLNameStart [a-zA-Z_:]
259 XMLNamePart [a-zA-Z0-9.-_:]
260 XMLName {XMLNameStart}{XMLNamePart}*
261 @end
262
263 %x MultiLine
264
265 %x LegacySingleString
266 %x LegacyDoubleString
267
268 %x StrictSingleString
269 %x StrictDoubleString
270 %x StrictAccentString
271
272 %s Div
273 %s DivOrTemplateTail
274 %s RegExp
275 %s RegExpOrTemplateTail
276
277 @begin E4X
278 %x XMLContent
279 %x XMLTag
280 @end
281
282 %%
283
284 /* RegEx {{{ */
285 <RegExp,RegExpOrTemplateTail>{
286 \/{RegularExpressionBody}\/{RegularExpressionFlags} L C I(literal, RegEx(Y), tk::RegularExpressionLiteral, hi::Constant);
287 \/{RegularExpressionBody}\/{RegularExpressionFlags}{UnicodeFail} L E("invalid flags")
288 \/{RegularExpressionBody}?\\? L E("unterminated regex")
289 }
290 /* }}} */
291 /* Comment {{{ */
292 #![^\n]* L M
293 \/\/[^\n]* L M
294
295 \/\* L yy_push_state(MultiLine, yyscanner);
296
297 <MultiLine>{
298 \**\*\/ R yy_pop_state(yyscanner); M N
299 \**{LineTerminatorSequence} yylloc->end.lines(); yyextra->last_ = true;
300 \**{CommentCharacter}|\/ R
301 \**({UnicodeFail}|\*) R E("invalid comment");
302 <<EOF>> R E("invalid comment")
303 }
304 /* }}} */
305 /* Element {{{ */
306 @begin E4X
307 <RegExp>"<>" L F(tk::LeftRight, hi::Structure);
308 <XMLContent>"</>" L F(tk::LeftSlashRight, hi::Structure);
309
310 <RegExp,XMLContent>\<!\[CDATA\[(\n|[^[]|\[[^[]|\[\[[^>])*]]> V() F(tk::XMLCDATA, hi::Constant);
311 <RegExp,XMLContent>\<!--(\n|[^-]|-[^-])*--> V() F(tk::XMLComment, hi::Comment);
312 <RegExp,XMLContent>\<?(\n|[^?]|\?[^>])*?> V() F(tk::XMLPI, hi::Meta);
313
314 <XMLTag>"=" L F(tk::Equal, hi::Structure);
315 <XMLTag>">" L F(tk::Right, hi::Structure);
316 <XMLTag>"/>" L F(tk::SlashRight, hi::Structure);
317 <XMLTag>"{" L F(tk::OpenBrace, hi::Structure);
318
319 <XMLTag>\"(\n|[^"])*\"|'(\n|[^'])*' V() F(tk::XMLAttributeValue, hi::Constant);
320 <XMLTag>{XMLName} L F(tk::XMLName, hi::Identifier);
321 <XMLTag>[ \t\r\n] V() F(tk::XMLWhitespace, hi::Nothing);
322
323 <XMLContent>"{" L F(tk::OpenBrace, hi::Structure);
324 <XMLContent>"<" L F(tk::Left, hi::Structure);
325 <XMLContent>"</" L F(tk::LeftSlash, hi::Structure);
326 @end
327 /* }}} */
328 /* Operator {{{ */
329 "..." L C F(tk::PeriodPeriodPeriod, hi::Meta);
330 ".." L E("invalid operator")
331
332 @begin E4X
333 "::" L C F(tk::ColonColon, hi::Operator);
334 ".." L C F(tk::PeriodPeriod, hi::Operator);
335 @end
336
337 @begin E4X ObjectiveC
338 "@" L C F(tk::At, hi::Operator);
339 "#" L C F(tk::Pound, hi::Operator);
340 @end
341
342 "&" L C F(tk::Ampersand, hi::Operator);
343 "&&" L C F(tk::AmpersandAmpersand, hi::Operator);
344 "&=" L C F(tk::AmpersandEqual, hi::Operator);
345 "^" L C F(tk::Carrot, hi::Operator);
346 "^=" L C F(tk::CarrotEqual, hi::Operator);
347 "=" L C F(tk::Equal, hi::Operator);
348 "==" L C F(tk::EqualEqual, hi::Operator);
349 "===" L C F(tk::EqualEqualEqual, hi::Operator);
350 "=>" L C F(yyextra->newline_ ? tk::EqualRight_ : tk::EqualRight, hi::Operator);
351 "!" L C F(tk::Exclamation, hi::Operator);
352 "!=" L C F(tk::ExclamationEqual, hi::Operator);
353 "!==" L C F(tk::ExclamationEqualEqual, hi::Operator);
354 "-" L C F(tk::Hyphen, hi::Operator);
355 "-=" L C F(tk::HyphenEqual, hi::Operator);
356 "--" L C F(yyextra->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen, hi::Operator);
357 "->" L C F(tk::HyphenRight, hi::Operator);
358 "<" L C F(tk::Left, hi::Operator);
359 "<=" L C F(tk::LeftEqual, hi::Operator);
360 "<<" L C F(tk::LeftLeft, hi::Operator);
361 "<<=" L C F(tk::LeftLeftEqual, hi::Operator);
362 "%" L C F(tk::Percent, hi::Operator);
363 "%=" L C F(tk::PercentEqual, hi::Operator);
364 "." L C F(tk::Period, hi::Operator);
365 "|" L C F(tk::Pipe, hi::Operator);
366 "|=" L C F(tk::PipeEqual, hi::Operator);
367 "||" L C F(tk::PipePipe, hi::Operator);
368 "+" L C F(tk::Plus, hi::Operator);
369 "+=" L C F(tk::PlusEqual, hi::Operator);
370 "++" L C F(yyextra->newline_ ? tk::PlusPlus_ : tk::PlusPlus, hi::Operator);
371 ">" L C F(tk::Right, hi::Operator);
372 ">=" L C F(tk::RightEqual, hi::Operator);
373 ">>" L C F(tk::RightRight, hi::Operator);
374 ">>=" L C F(tk::RightRightEqual, hi::Operator);
375 ">>>" L C F(tk::RightRightRight, hi::Operator);
376 ">>>=" L C F(tk::RightRightRightEqual, hi::Operator);
377 "*" L C F(tk::Star, hi::Operator);
378 "*=" L C F(tk::StarEqual, hi::Operator);
379 "~" L C F(tk::Tilde, hi::Operator);
380
381 <Div,DivOrTemplateTail>"/" L C F(tk::Slash, hi::Operator);
382 <Div,DivOrTemplateTail>"/=" L C F(tk::SlashEqual, hi::Operator);
383
384 ":" L C F(tk::Colon, hi::Structure);
385 "," L C F(tk::Comma, hi::Structure);
386 "?" L C F(tk::Question, hi::Structure);
387 ";" L C F(tk::SemiColon, hi::Structure);
388
389 "(" L C F(tk::OpenParen, hi::Structure);
390 ")" L C F(tk::CloseParen, hi::Structure);
391
392 "{" L yyextra->template_.push(false); C F(yyextra->no_.OpenBrace ? tk::OpenBrace__ : yyextra->newline_ ? tk::OpenBrace_ : tk::OpenBrace, hi::Structure);
393 <Div,RegExp>"}" L yyextra->template_.pop(); C F(tk::CloseBrace, hi::Structure);
394
395 "[" L C F(tk::OpenBracket, hi::Structure);
396 "]" L C F(tk::CloseBracket, hi::Structure);
397 /* }}} */
398 /* Keyword {{{ */
399 "@error" L C F(tk::At_error_, hi::Error);
400
401 @begin Java
402 "@class" L C F(tk::At_class_, hi::Meta);
403 @end
404
405 @begin C
406 "@encode" L C F(tk::At_encode_, hi::Meta);
407 @end
408
409 @begin ObjectiveC
410 "@end" L C F(tk::At_end_, hi::Meta);
411 "@false" L C F(tk::At_false_, hi::Constant);
412 "@implementation" L C F(tk::At_implementation_, hi::Meta);
413 "@import" L C F(tk::At_import_, hi::Special);
414 "@NO" L C F(tk::At_NO_, hi::Constant);
415 "@null" L C F(tk::At_null_, hi::Constant);
416 "@selector" L C F(tk::At_selector_, hi::Meta);
417 "@true" L C F(tk::At_true_, hi::Constant);
418 "@YES" L C F(tk::At_YES_, hi::Constant);
419 @end
420
421 @({UnicodeStart}{UnicodeScrap}|{UnicodeFail}) L E("invalid keyword")
422 /* }}} */
423 /* Highlight {{{ */
424 "undefined" L C F(tk::_undefined_, hi::Operator);
425
426 @begin ObjectiveC
427 "bool" L C F(tk::_bool_, hi::Type);
428 "BOOL" L C F(tk::_BOOL_, hi::Type);
429 "id" L C F(tk::_id_, hi::Type);
430 "nil" L C F(tk::_nil_, hi::Constant);
431 "NULL" L C F(tk::_NULL_, hi::Constant);
432 "SEL" L C F(tk::_SEL_, hi::Type);
433 @end
434 /* }}} */
435 /* Reserved {{{ */
436 "abstract" L C /*FII*/ F(tk::_abstract_, hi::Meta);
437 "await" L C /*II?*/ F(tk::_await_, hi::Meta);
438 "boolean" L C /*FII*/ F(tk::_boolean_, hi::Type);
439 "break" L C /*KKK*/ F(tk::_break_, hi::Control);
440 "byte" L C /*FII*/ F(tk::_byte_, hi::Type);
441 "case" L C /*KKK*/ F(tk::_case_, hi::Control);
442 "catch" L C /*KKK*/ F(tk::_catch_, hi::Control);
443 "char" L C /*FII*/ F(tk::_char_, hi::Type);
444 "class" L C /*FFK*/ F(yyextra->no_.Class ? tk::_class__ : tk::_class_, hi::Meta);
445 "const" L C /*FFK*/ F(tk::_const_, hi::Meta);
446 "continue" L C /*KKK*/ F(tk::_continue_, hi::Control);
447 "debugger" L C /*FKK*/ F(tk::_debugger_, hi::Meta);
448 "default" L C /*KKK*/ F(tk::_default_, hi::Control);
449 "delete" L C /*KKK*/ F(tk::_delete_, hi::Operator);
450 "do" L C /*KKK*/ F(tk::_do_, hi::Control);
451 "double" L C /*FII*/ F(tk::_double_, hi::Type);
452 "else" L C /*KKK*/ F(tk::_else_, hi::Control);
453 "enum" L C /*FFF*/ F(tk::_enum_, hi::Meta);
454 "export" L C /*FFK*/ F(tk::_export_, hi::Meta);
455 "extends" L C /*FFK*/ F(tk::_extends_, hi::Meta);
456 "false" L C /*LLL*/ F(tk::_false_, hi::Constant);
457 "final" L C /*FII*/ F(tk::_final_, hi::Meta);
458 "finally" L C /*KKK*/ F(tk::_finally_, hi::Control);
459 "float" L C /*FII*/ F(tk::_float_, hi::Type);
460 "for" L C /*KKK*/ F(tk::_for_, hi::Control);
461 "function" L C /*KKK*/ F(yyextra->no_.Function ? tk::_function__ : tk::_function_, hi::Meta);
462 "goto" L C /*FII*/ F(tk::_goto_, hi::Control);
463 "if" L C /*KKK*/ F(tk::_if_, hi::Control);
464 "implements" L C /*FSS*/ F(tk::_implements_, hi::Meta);
465 "import" L C /*FFK*/ F(tk::_import_, hi::Meta);
466 "in" L C /*KKK*/ F(yyextra->in_.top() ? tk::_in__ : tk::_in_, hi::Operator);
467 "instanceof" L C /*KKK*/ F(tk::_instanceof_, hi::Operator);
468 "int" L C /*FII*/ F(tk::_int_, hi::Type);
469 "interface" L C /*FSS*/ F(tk::_interface_, hi::Meta);
470 "let" L C /*IS?*/ F(tk::_let_, hi::Meta);
471 "long" L C /*FII*/ F(tk::_long_, hi::Type);
472 "native" L C /*FII*/ F(tk::_native_, hi::Meta);
473 "new" L C /*KKK*/ F(tk::_new_, hi::Operator);
474 "null" L C /*LLL*/ F(tk::_null_, hi::Constant);
475 "package" L C /*FSS*/ F(tk::_package_, hi::Meta);
476 "private" L C /*FSS*/ F(tk::_private_, hi::Meta);
477 "protected" L C /*FSS*/ F(tk::_protected_, hi::Meta);
478 "public" L C /*FSS*/ F(tk::_public_, hi::Meta);
479 "return" L C /*KKK*/ F(tk::_return_, hi::Control);
480 "short" L C /*FII*/ F(tk::_short_, hi::Type);
481 "static" L C /*FS?*/ F(tk::_static_, hi::Meta);
482 "super" L C /*FFK*/ F(tk::_super_, hi::Constant);
483 "switch" L C /*KKK*/ F(tk::_switch_, hi::Control);
484 "synchronized" L C /*FII*/ F(tk::_synchronized_, hi::Meta);
485 "this" L C /*KKK*/ F(tk::_this_, hi::Constant);
486 "throw" L C /*KKK*/ F(tk::_throw_, hi::Control);
487 "throws" L C /*FII*/ F(tk::_throws_, hi::Meta);
488 "transient" L C /*FII*/ F(tk::_transient_, hi::Meta);
489 "true" L C /*LLL*/ F(tk::_true_, hi::Constant);
490 "try" L C /*KKK*/ F(tk::_try_, hi::Control);
491 "typeof" L C /*KKK*/ F(tk::_typeof_, hi::Operator);
492 "var" L C /*KKK*/ F(tk::_var_, hi::Meta);
493 "void" L C /*KKK*/ F(tk::_void_, hi::Operator);
494 "volatile" L C /*FII*/ F(tk::_volatile_, hi::Meta);
495 "while" L C /*KKK*/ F(tk::_while_, hi::Control);
496 "with" L C /*KKK*/ F(tk::_with_, hi::Control);
497 "yield" L C /*IS?*/ F(tk::_yield_, hi::Control);
498
499 "auto" L C F(tk::_auto_, hi::Meta);
500 "each" L C F(tk::_each_, hi::Control);
501 "of" L C F(tk::_of_, hi::Operator);
502
503 @begin C
504 "extern" L C F(tk::_extern_, hi::Type);
505 "signed" L C F(tk::_signed_, hi::Type);
506 "typedef" L C F(tk::_typedef_, hi::Meta);
507 "unsigned" L C F(tk::_unsigned_, hi::Type);
508 @end
509
510 @begin ObjectiveC
511 "NO" L C F(tk::_NO_, hi::Constant);
512 "YES" L C F(tk::_YES_, hi::Constant);
513 @end
514
515 @begin E4X
516 "namespace" L C F(tk::_namespace_, hi::Meta);
517 "xml" L C F(tk::_xml_, hi::Meta);
518 @end
519 /* }}} */
520 /* Identifier {{{ */
521 {UnicodeStart}{UnicodePart}* L C I(identifier, Identifier(Y), tk::Identifier_, hi::Identifier);
522
523 {IdentifierStart}{IdentifierPart}* L C {
524 char *value(A char[yyleng + 1]);
525 char *local(value);
526
527 for (yy_size_t i(0), e(yyleng); i != e; ++i) {
528 char next(yytext[i]);
529 if (next != '\\')
530 *local++ = next;
531 else
532 U(local, yytext, ++i);
533 }
534
535 *local = '\0';
536 I(identifier, Identifier(value), tk::Identifier_, hi::Identifier);
537 }
538
539 ({IdentifierStart}{IdentifierPart}*)?{IdentifierFail} L E("invalid identifier")
540 /* }}} */
541 /* Number {{{ */
542 0[0-7]+ L C I(number, Number(strtoull(yytext + 1, NULL, 8)), tk::NumericLiteral, hi::Constant);
543 0[0-9]+ L C I(number, Number(strtoull(yytext + 1, NULL, 10)), tk::NumericLiteral, hi::Constant);
544
545 0[xX][0-9a-fA-F]+ L C I(number, Number(strtoull(yytext + 2, NULL, 16)), tk::NumericLiteral, hi::Constant);
546 0[oO][0-7]+ L C I(number, Number(strtoull(yytext + 2, NULL, 8)), tk::NumericLiteral, hi::Constant);
547 0[bB][0-1]+ L C I(number, Number(strtoull(yytext + 2, NULL, 2)), tk::NumericLiteral, hi::Constant);
548
549 (\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?)([eE][+-]?[0-9]+)? L C I(number, Number(strtod(yytext, NULL)), tk::NumericLiteral, hi::Constant);
550 (\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?)[eE][+-]?{IdentifierScrap} L E("invalid exponent")
551 (\.?[0-9]|(0|[1-9][0-9]*)\.){IdentifierScrap} L E("invalid number")
552 /* }}} */
553 /* String {{{ */
554 \' L CYLexBufferStart(LegacySingleString);
555 <LegacySingleString,StrictSingleString>{
556 \' R CYLexBufferEnd(string, String, tk::StringLiteral, hi::Constant);
557 {SingleCharacter}+ R CYLexBufferUnits(yytext, yyleng);
558 {SingleCharacter}*{UnicodeFail} R E("invalid character");
559 {LineTerminatorSequence} R E("invalid newline");
560 }
561
562 \" L CYLexBufferStart(LegacyDoubleString);
563 <LegacyDoubleString,StrictDoubleString>{
564 \" R CYLexBufferEnd(string, String, tk::StringLiteral, hi::Constant);
565 {DoubleCharacter}+ R CYLexBufferUnits(yytext, yyleng);
566 {DoubleCharacter}*{UnicodeFail} R E("invalid character");
567 {LineTerminatorSequence} R E("invalid newline");
568 }
569 /* }}} */
570 /* Template {{{ */
571 "`" L yyextra->tail_ = false; CYLexBufferStart(StrictAccentString);
572 <DivOrTemplateTail,RegExpOrTemplateTail>"}" L yyextra->tail_ = true; yyextra->template_.pop(); CYLexBufferStart(StrictAccentString);
573
574 <StrictAccentString>{
575 "`" R CYLexBufferEnd(string, String, yyextra->tail_ ? tk::TemplateTail : tk::NoSubstitutionTemplate, hi::Constant);
576 "${" R yyextra->template_.push(true); CYLexBufferEnd(string, String, yyextra->tail_ ? tk::TemplateMiddle : tk::TemplateHead, hi::Constant);
577
578 "$" R CYLexBufferUnit('$');
579
580 {PlateCharacter}+ R CYLexBufferUnits(yytext, yyleng);
581 {PlateCharacter}*{UnicodeFail} R E("invalid character");
582 {LineTerminatorSequence} R E("invalid newline");
583 }
584 /* }}} */
585 /* Escapes {{{ */
586 <LegacySingleString,LegacyDoubleString>{
587 \\[0-3][0-7][0-7] R CYLexBufferPoint(X(yytext[1]) << 6 | X(yytext[2]) << 3 | X(yytext[3]));
588 \\[0-7][0-7] R CYLexBufferUnit(X(yytext[1]) << 3 | X(yytext[2]));
589 \\[0-7] R CYLexBufferUnit(X(yytext[1]));
590 }
591
592 <StrictSingleString,StrictDoubleString,StrictAccentString>{
593 \\0[0-7] R E("legacy escape");
594 \\0 R CYLexBufferUnit('\0');
595 }
596
597 <LegacySingleString,LegacyDoubleString,StrictSingleString,StrictDoubleString,StrictAccentString>{
598 \\b R CYLexBufferUnit('\b');
599 \\f R CYLexBufferUnit('\f');
600 \\n R CYLexBufferUnit('\n');
601 \\r R CYLexBufferUnit('\r');
602 \\t R CYLexBufferUnit('\t');
603 \\v R CYLexBufferUnit('\v');
604
605 \\x{HexDigit}{2} R CYLexBufferPoint(X(yytext[2]) << 4 | X(yytext[3]));
606
607 \\u{HexDigit}{4} R CYLexBufferPoint(X(yytext[2]) << 12 | X(yytext[3]) << 8 | X(yytext[4]) << 4 | X(yytext[5]));
608
609 \\u\{{HexDigit}+\} R {
610 unsigned point(0);
611 for (yy_size_t i(3); i != yyleng - 1; ++i)
612 point = point << 4 | X(yytext[i]);
613 CYLexBufferPoint(point);
614 }
615
616 \\{LineTerminatorSequence} yylloc->end.lines();
617 \\(.|{NotLineTerminator}) R CYLexBufferUnits(yytext + 1, yyleng - 1);
618
619 \\(x{HexDigit}{0,1}|u({HexDigit}{0,3}|\{{HexDigit}*)|{UnicodeFail})? R E("invalid escape");
620 <<EOF>> R E("invalid string");
621 }
622 /* }}} */
623
624 {LineTerminatorSequence} yylloc->step(); yylloc->end.lines(); yyextra->last_ = true; N
625 {WhiteSpace} L
626
627 <<EOF>> if (yyextra->auto_) { yyextra->auto_ = false; F(tk::AutoComplete, hi::Nothing); } L yyterminate();
628
629 . L E("invalid character")
630
631 %%
632
633 void CYDriver::ScannerInit() {
634 cylex_init(&scanner_);
635 cyset_extra(this, scanner_);
636 }
637
638 void CYDriver::ScannerDestroy() {
639 cylex_destroy(scanner_);
640 }
641
642 void CYDriver::SetCondition(Condition condition) {
643 struct yyguts_t *yyg(reinterpret_cast<struct yyguts_t *>(scanner_));
644
645 switch (condition) {
646 case RegExpCondition:
647 BEGIN(template_.top() ? RegExpOrTemplateTail : RegExp);
648 break;
649 @begin E4X
650 case XMLContentCondition:
651 BEGIN(XMLContent);
652 break;
653 case XMLTagCondition:
654 BEGIN(XMLTag);
655 break;
656 @end
657 default:
658 _assert(false);
659 }
660 }
661
662 void CYDriver::PushCondition(Condition condition) {
663 switch (condition) {
664 case RegExpCondition:
665 yy_push_state(RegExp, scanner_);
666 break;
667 @begin E4X
668 case XMLContentCondition:
669 yy_push_state(XMLContent, scanner_);
670 break;
671 case XMLTagCondition:
672 yy_push_state(XMLTag, scanner_);
673 break;
674 @end
675 default:
676 _assert(false);
677 }
678 }
679
680 void CYDriver::PopCondition() {
681 yy_pop_state(scanner_);
682 }
683
684 #if defined(__clang__)
685 #pragma clang diagnostic pop
686 #else
687 // must not pop -Wunused-function
688 //#pragma GCC diagnostic pop
689 #endif