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