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