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