]> git.saurik.com Git - cycript.git/blame_incremental - Cycript.l
Finished implementing automatic semi-colon rules, but failed hard at fixing multi...
[cycript.git] / Cycript.l
... / ...
CommitLineData
1%{
2#include "Cycript.tab.hh"
3typedef cy::parser::token tk;
4#define YY_EXTRA_TYPE CYDriver *
5#define N yylval->newline_ = yyextra->newline_; yyextra->newline_ = false; yyextra->restricted_ = false;
6#define R yyextra->restricted_ = true;
7#define L { bool restricted(yyextra->restricted_); yyextra->restricted_ = false; if (restricted) return tk::NewLine; else yyextra->newline_ = true; }
8%}
9
10%option prefix="cy"
11%option bison-bridge
12%option bison-locations
13%option noyywrap
14%option yylineno
15%option nounput
16%option interactive
17%option reentrant
18
19Exponent [eE][+-]?[0-9]+
20Escape \\['"\\bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
21
22%%
23
24\/\/[^\n]* ;
25\/\*(\n|[^\*]|\*[^/])\*\/ if (memchr(yytext, '\n', yyleng) != NULL) L // XXX: supposedly I will be screwed on very very long multi-line comments and need to replace this with a manual lexer. http://websrv.cs.fsu.edu/~engelen/courses/COP5621/Pr2.pdf ; XXX: this rule doesn't work anyway, fucking A :(
26
27"&" N return tk::Ampersand;
28"&&" N return tk::AmpersandAmpersand;
29"&=" N return tk::AmpersandEqual;
30"^" N return tk::Carrot;
31"^=" N return tk::CarrotEqual;
32"=" N return tk::Equal;
33"==" N return tk::EqualEqual;
34"===" N return tk::EqualEqualEqual;
35"!" N return tk::Exclamation;
36"!=" N return tk::ExclamationEqual;
37"!==" N return tk::ExclamationEqualEqual;
38"-" N return tk::Hyphen;
39"-=" N return tk::HyphenEqual;
40"--" N return yylval->newline_ ? tk::HyphenHyphen_ : tk::HyphenHyphen;
41"->" N return tk::HyphenRight;
42"<" N return tk::Left;
43"<=" N return tk::LeftEqual;
44"<<" N return tk::LeftLeft;
45"<<=" N return tk::LeftLeftEqual;
46"%" N return tk::Percent;
47"%=" N return tk::PercentEqual;
48"." N return tk::Period;
49"|" N return tk::Pipe;
50"|=" N return tk::PipeEqual;
51"||" N return tk::PipePipe;
52"+" N return tk::Plus;
53"+=" N return tk::PlusEqual;
54"++" N return yylval->newline_ ? tk::PlusPlus_ : tk::PlusPlus;
55">" N return tk::Right;
56">=" N return tk::RightEqual;
57">>" N return tk::RightRight;
58">>=" N return tk::RightRightEqual;
59">>>" N return tk::RightRightRight;
60">>>=" N return tk::RightRightRightEqual;
61"/" N return tk::Slash;
62"/=" N return tk::SlashEqual;
63"*" N return tk::Star;
64"*=" N return tk::StarEqual;
65"~" N return tk::Tilde;
66
67":" N return tk::Colon;
68"," N return tk::Comma;
69"?" N return tk::Question;
70";" N return tk::SemiColon;
71
72"(" N return tk::OpenParen;
73")" N return tk::CloseParen;
74
75"{" N return tk::OpenBrace;
76"}" N return tk::CloseBrace;
77
78"[" N return tk::OpenBracket;
79"]" N return tk::CloseBracket;
80
81"break" N R yylval->word_ = new CYWord("break"); return tk::Break;
82"case" N yylval->word_ = new CYWord("case"); return tk::Case;
83"catch" N yylval->word_ = new CYWord("catch"); return tk::Catch;
84"continue" N R yylval->word_ = new CYWord("continue"); return tk::Continue;
85"default" N yylval->word_ = new CYWord("default"); return tk::Default;
86"delete" N yylval->word_ = new CYWord("delete"); return tk::Delete;
87"do" N yylval->word_ = new CYWord("do"); return tk::Do;
88"else" N yylval->word_ = new CYWord("else"); return tk::Else;
89"false" N yylval->false_ = new CYFalse(); return tk::False;
90"finally" N yylval->word_ = new CYWord("finally"); return tk::Finally;
91"for" N yylval->word_ = new CYWord("for"); return tk::For;
92"function" N yylval->word_ = new CYWord("function"); return tk::Function;
93"if" N yylval->word_ = new CYWord("if"); return tk::If;
94"in" N yylval->word_ = new CYWord("in"); return tk::In;
95"instanceof" N yylval->word_ = new CYWord("instanceof"); return tk::InstanceOf;
96"new" N yylval->word_ = new CYWord("new"); return tk::New;
97"null" N yylval->null_ = new CYNull(); return tk::Null;
98"return" N R yylval->word_ = new CYWord("return"); return tk::Return;
99"switch" N yylval->word_ = new CYWord("switch"); return tk::Switch;
100"this" N yylval->this_ = new CYThis(); return tk::This;
101"throw" N R yylval->word_ = new CYWord("throw"); return tk::Throw;
102"true" N yylval->true_ = new CYTrue(); return tk::True;
103"try" N yylval->word_ = new CYWord("try"); return tk::Try;
104"typeof" N yylval->word_ = new CYWord("typeof"); return tk::TypeOf;
105"var" N yylval->word_ = new CYWord("var"); return tk::Var;
106"void" N yylval->word_ = new CYWord("void"); return tk::Void;
107"while" N yylval->word_ = new CYWord("while"); return tk::While;
108"with" N yylval->word_ = new CYWord("with"); return tk::With;
109
110[a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); N return tk::Identifier;
111
112(\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new CYNumber(strtod(yytext, NULL)); N return tk::NumericLiteral;
113
1140[xX][0-9a-fA-F]+ N yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 16)); return tk::NumericLiteral;
115
1160[bB][0-1]+ N yylval->number_ = new CYNumber(strtoull(yytext + 2, NULL, 2)); return tk::NumericLiteral;
117
118\"([^"\\\n]|{Escape})*\" N return tk::StringLiteral;
119'([^'\\\n]|{Escape})*' N return tk::StringLiteral;
120
121\n L
122[ \t] ;
123
124%%
125
126void CYDriver::ScannerInit() {
127 cylex_init(&scanner_);
128 cyset_extra(this, scanner_);
129}
130
131void CYDriver::ScannerDestroy() {
132 cylex_destroy(scanner_);
133}