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