Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: src/lexer/lexer_py.re

Issue 63773003: Experimental parser: add push_token syntax (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 18 matching lines...) Expand all
29 whitespace = whitespace_char+; 29 whitespace = whitespace_char+;
30 identifier_start = [$_a-zA-Z:lit:]; # TODO add relevant latin1 char codes 30 identifier_start = [$_a-zA-Z:lit:]; # TODO add relevant latin1 char codes
31 identifier_char = [0-9:identifier_start:]; 31 identifier_char = [0-9:identifier_start:];
32 line_terminator = [\n\r]; 32 line_terminator = [\n\r];
33 digit = [0-9]; 33 digit = [0-9];
34 hex_digit = [0-9a-fA-F]; 34 hex_digit = [0-9a-fA-F];
35 maybe_exponent = ([eE] [\-+]? digit+)?; 35 maybe_exponent = ([eE] [\-+]? digit+)?;
36 number = ("0x" hex_digit+) | (("." digit+ maybe_exponent) | (digit+ ("." digit*) ? maybe_exponent)); 36 number = ("0x" hex_digit+) | (("." digit+ maybe_exponent) | (digit+ ("." digit*) ? maybe_exponent));
37 37
38 <default> 38 <default>
39 "|=" { PUSH_TOKEN(Token::ASSIGN_BIT_OR); } 39 "|=" push_token(ASSIGN_BIT_OR)
40 "^=" { PUSH_TOKEN(Token::ASSIGN_BIT_XOR); } 40 "^=" push_token(ASSIGN_BIT_XOR)
41 "&=" { PUSH_TOKEN(Token::ASSIGN_BIT_AND); } 41 "&=" push_token(ASSIGN_BIT_AND)
42 "+=" { PUSH_TOKEN(Token::ASSIGN_ADD); } 42 "+=" push_token(ASSIGN_ADD)
43 "-=" { PUSH_TOKEN(Token::ASSIGN_SUB); } 43 "-=" push_token(ASSIGN_SUB)
44 "*=" { PUSH_TOKEN(Token::ASSIGN_MUL); } 44 "*=" push_token(ASSIGN_MUL)
45 "/=" { PUSH_TOKEN(Token::ASSIGN_DIV); } 45 "/=" push_token(ASSIGN_DIV)
46 "%=" { PUSH_TOKEN(Token::ASSIGN_MOD); } 46 "%=" push_token(ASSIGN_MOD)
47 47
48 "===" { PUSH_TOKEN(Token::EQ_STRICT); } 48 "===" push_token(EQ_STRICT)
49 "==" { PUSH_TOKEN(Token::EQ); } 49 "==" push_token(EQ)
50 "=" { PUSH_TOKEN(Token::ASSIGN); } 50 "=" push_token(ASSIGN)
51 "!==" { PUSH_TOKEN(Token::NE_STRICT); } 51 "!==" push_token(NE_STRICT)
52 "!=" { PUSH_TOKEN(Token::NE); } 52 "!=" push_token(NE)
53 "!" { PUSH_TOKEN(Token::NOT); } 53 "!" push_token(NOT)
54 54
55 "//" <<SingleLineComment>> 55 "//" <<SingleLineComment>>
56 "/*" <<MultiLineComment>> 56 "/*" <<MultiLineComment>>
57 "<!--" <<HtmlComment>> 57 "<!--" <<HtmlComment>>
58 58
59 #whitespace* "-->" { if (just_seen_line_terminator_) { YYSETCONDITION(kCondition SingleLineComment); goto yyc_SingleLineComment; } else { --cursor_; send(Token:: DEC); start_ = cursor_; goto yyc_Normal; } } 59 #whitespace* "-->" { if (just_seen_line_terminator_) { YYSETCONDITION(kCondition SingleLineComment); goto yyc_SingleLineComment; } else { --cursor_; send(Token:: DEC); start_ = cursor_; goto yyc_Normal; } }
60 60
61 ">>>=" { PUSH_TOKEN(Token::ASSIGN_SHR); } 61 ">>>=" push_token(ASSIGN_SHR)
62 ">>>" { PUSH_TOKEN(Token::SHR); } 62 ">>>" push_token(SHR)
63 "<<=" { PUSH_TOKEN(Token::ASSIGN_SHL); } 63 "<<=" push_token(ASSIGN_SHL)
64 ">>=" { PUSH_TOKEN(Token::ASSIGN_SAR); } 64 ">>=" push_token(ASSIGN_SAR)
65 "<=" { PUSH_TOKEN(Token::LTE); } 65 "<=" push_token(LTE)
66 ">=" { PUSH_TOKEN(Token::GTE); } 66 ">=" push_token(GTE)
67 "<<" { PUSH_TOKEN(Token::SHL); } 67 "<<" push_token(SHL)
68 ">>" { PUSH_TOKEN(Token::SAR); } 68 ">>" push_token(SAR)
69 "<" { PUSH_TOKEN(Token::LT); } 69 "<" push_token(LT)
70 ">" { PUSH_TOKEN(Token::GT); } 70 ">" push_token(GT)
71 71
72 number { PUSH_TOKEN(Token::NUMBER); } 72 number push_token(NUMBER)
73 # number identifier_char { PUSH_TOKEN(Token::ILLEGAL); } 73 # number identifier_char push_token(ILLEGAL)
74 74
75 "(" { PUSH_TOKEN(Token::LPAREN); } 75 "(" push_token(LPAREN)
76 ")" { PUSH_TOKEN(Token::RPAREN); } 76 ")" push_token(RPAREN)
77 "[" { PUSH_TOKEN(Token::LBRACK); } 77 "[" push_token(LBRACK)
78 "]" { PUSH_TOKEN(Token::RBRACK); } 78 "]" push_token(RBRACK)
79 "{" { PUSH_TOKEN(Token::LBRACE); } 79 "{" push_token(LBRACE)
80 "}" { PUSH_TOKEN(Token::RBRACE); } 80 "}" push_token(RBRACE)
81 ":" { PUSH_TOKEN(Token::COLON); } 81 ":" push_token(COLON)
82 ";" { PUSH_TOKEN(Token::SEMICOLON); } 82 ";" push_token(SEMICOLON)
83 "." { PUSH_TOKEN(Token::PERIOD); } 83 "." push_token(PERIOD)
84 "?" { PUSH_TOKEN(Token::CONDITIONAL); } 84 "?" push_token(CONDITIONAL)
85 "++" { PUSH_TOKEN(Token::INC); } 85 "++" push_token(INC)
86 "--" { PUSH_TOKEN(Token::DEC); } 86 "--" push_token(DEC)
87 87
88 "||" { PUSH_TOKEN(Token::OR); } 88 "||" push_token(OR)
89 "&&" { PUSH_TOKEN(Token::AND); } 89 "&&" push_token(AND)
90 90
91 "|" { PUSH_TOKEN(Token::BIT_OR); } 91 "|" push_token(BIT_OR)
92 "^" { PUSH_TOKEN(Token::BIT_XOR); } 92 "^" push_token(BIT_XOR)
93 "&" { PUSH_TOKEN(Token::BIT_AND); } 93 "&" push_token(BIT_AND)
94 "+" { PUSH_TOKEN(Token::ADD); } 94 "+" push_token(ADD)
95 "-" { PUSH_TOKEN(Token::SUB); } 95 "-" push_token(SUB)
96 "*" { PUSH_TOKEN(Token::MUL); } 96 "*" push_token(MUL)
97 "/" { PUSH_TOKEN(Token::DIV); } 97 "/" push_token(DIV)
98 "%" { PUSH_TOKEN(Token::MOD); } 98 "%" push_token(MOD)
99 "~" { PUSH_TOKEN(Token::BIT_NOT); } 99 "~" push_token(BIT_NOT)
100 "," { PUSH_TOKEN(Token::COMMA); } 100 "," push_token(COMMA)
101 101
102 line_terminator+ { PUSH_LINE_TERMINATOR(); } 102 line_terminator+ { PUSH_LINE_TERMINATOR(); }
103 whitespace { SKIP(); } # TODO implement skip 103 whitespace { SKIP(); } # TODO implement skip
104 104
105 "\"" <<DoubleQuoteString>> 105 "\"" <<DoubleQuoteString>>
106 "'" <<SingleQuoteString>> 106 "'" <<SingleQuoteString>>
107 107
108 # all keywords 108 # all keywords
109 "break" { PUSH_TOKEN(Token::BREAK); } 109 "break" push_token(BREAK)
110 "case" { PUSH_TOKEN(Token::CASE); } 110 "case" push_token(CASE)
111 "catch" { PUSH_TOKEN(Token::CATCH); } 111 "catch" push_token(CATCH)
112 "class" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 112 "class" push_token(FUTURE_RESERVED_WORD)
113 "const" { PUSH_TOKEN(Token::CONST); } 113 "const" push_token(CONST)
114 "continue" { PUSH_TOKEN(Token::CONTINUE); } 114 "continue" push_token(CONTINUE)
115 "debugger" { PUSH_TOKEN(Token::DEBUGGER); } 115 "debugger" push_token(DEBUGGER)
116 "default" { PUSH_TOKEN(Token::DEFAULT); } 116 "default" push_token(DEFAULT)
117 "delete" { PUSH_TOKEN(Token::DELETE); } 117 "delete" push_token(DELETE)
118 "do" { PUSH_TOKEN(Token::DO); } 118 "do" push_token(DO)
119 "else" { PUSH_TOKEN(Token::ELSE); } 119 "else" push_token(ELSE)
120 "enum" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 120 "enum" push_token(FUTURE_RESERVED_WORD)
121 "export" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 121 "export" push_token(FUTURE_RESERVED_WORD)
122 "extends" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 122 "extends" push_token(FUTURE_RESERVED_WORD)
123 "false" { PUSH_TOKEN(Token::FALSE_LITERAL); } 123 "false" push_token(FALSE_LITERAL)
124 "finally" { PUSH_TOKEN(Token::FINALLY); } 124 "finally" push_token(FINALLY)
125 "for" { PUSH_TOKEN(Token::FOR); } 125 "for" push_token(FOR)
126 "function" { PUSH_TOKEN(Token::FUNCTION); } 126 "function" push_token(FUNCTION)
127 "if" { PUSH_TOKEN(Token::IF); } 127 "if" push_token(IF)
128 "implements" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 128 "implements" push_token(FUTURE_STRICT_RESERVED_WORD)
129 "import" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 129 "import" push_token(FUTURE_RESERVED_WORD)
130 "in" { PUSH_TOKEN(Token::IN); } 130 "in" push_token(IN)
131 "instanceof" { PUSH_TOKEN(Token::INSTANCEOF); } 131 "instanceof" push_token(INSTANCEOF)
132 "interface" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 132 "interface" push_token(FUTURE_STRICT_RESERVED_WORD)
133 "let" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 133 "let" push_token(FUTURE_STRICT_RESERVED_WORD)
134 "new" { PUSH_TOKEN(Token::NEW); } 134 "new" push_token(NEW)
135 "null" { PUSH_TOKEN(Token::NULL_LITERAL); } 135 "null" push_token(NULL_LITERAL)
136 "package" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 136 "package" push_token(FUTURE_STRICT_RESERVED_WORD)
137 "private" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 137 "private" push_token(FUTURE_STRICT_RESERVED_WORD)
138 "protected" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 138 "protected" push_token(FUTURE_STRICT_RESERVED_WORD)
139 "public" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 139 "public" push_token(FUTURE_STRICT_RESERVED_WORD)
140 "return" { PUSH_TOKEN(Token::RETURN); } 140 "return" push_token(RETURN)
141 "static" { PUSH_TOKEN(Token::FUTURE_STRICT_RESERVED_WORD); } 141 "static" push_token(FUTURE_STRICT_RESERVED_WORD)
142 "super" { PUSH_TOKEN(Token::FUTURE_RESERVED_WORD); } 142 "super" push_token(FUTURE_RESERVED_WORD)
143 "switch" { PUSH_TOKEN(Token::SWITCH); } 143 "switch" push_token(SWITCH)
144 "this" { PUSH_TOKEN(Token::THIS); } 144 "this" push_token(THIS)
145 "throw" { PUSH_TOKEN(Token::THROW); } 145 "throw" push_token(THROW)
146 "true" { PUSH_TOKEN(Token::TRUE_LITERAL); } 146 "true" push_token(TRUE_LITERAL)
147 "try" { PUSH_TOKEN(Token::TRY); } 147 "try" push_token(TRY)
148 "typeof" { PUSH_TOKEN(Token::TYPEOF); } 148 "typeof" push_token(TYPEOF)
149 "var" { PUSH_TOKEN(Token::VAR); } 149 "var" push_token(VAR)
150 "void" { PUSH_TOKEN(Token::VOID); } 150 "void" push_token(VOID)
151 "while" { PUSH_TOKEN(Token::WHILE); } 151 "while" push_token(WHILE)
152 "with" { PUSH_TOKEN(Token::WITH); } 152 "with" push_token(WITH)
153 "yield" { PUSH_TOKEN(Token::YIELD); } 153 "yield" push_token(YIELD)
154 154
155 identifier_start { PUSH_TOKEN(Token::IDENTIFIER); } <<Identifier>> 155 identifier_start push_token(IDENTIFIER) <<Identifier>>
156 /\\u[0-9a-fA-F]{4}/ { 156 /\\u[0-9a-fA-F]{4}/ {
157 if (V8_UNLIKELY(!ValidIdentifierStart())) { 157 if (V8_UNLIKELY(!ValidIdentifierStart())) {
158 PUSH_TOKEN(Token::ILLEGAL); 158 PUSH_TOKEN(Token::ILLEGAL);
159 } 159 }
160 } <<Identifier>> 160 } <<Identifier>>
161 161
162 eof { PUSH_TOKEN(Token::EOS); return 0; } 162 eof { PUSH_TOKEN(Token::EOS); return 0; }
163 default_action { PUSH_TOKEN(Token::ILLEGAL); } 163 default_action push_token(ILLEGAL)
164 164
165 <DoubleQuoteString> 165 <DoubleQuoteString>
166 /\\\n\r?/ <<continue>> 166 /\\\n\r?/ <<continue>>
167 /\\\r\n?/ <<continue>> 167 /\\\r\n?/ <<continue>>
168 /\\./ <<continue>> 168 /\\./ <<continue>>
169 /\n|\r/ { PUSH_TOKEN(Token::ILLEGAL); } 169 /\n|\r/ push_token(ILLEGAL)
170 "\"" { PUSH_TOKEN(Token::STRING); } 170 "\"" push_token(STRING)
171 eof <<terminate_illegal>> 171 eof <<terminate_illegal>>
172 catch_all <<continue>> 172 catch_all <<continue>>
173 173
174 <SingleQuoteString> 174 <SingleQuoteString>
175 /\\\n\r?/ <<continue>> 175 /\\\n\r?/ <<continue>>
176 /\\\r\n?/ <<continue>> 176 /\\\r\n?/ <<continue>>
177 /\\./ <<continue>> 177 /\\./ <<continue>>
178 /\n|\r/ { PUSH_TOKEN(Token::ILLEGAL); } 178 /\n|\r/ push_token(ILLEGAL)
179 "'" { PUSH_TOKEN(Token::STRING); } 179 "'" push_token(STRING)
180 eof <<terminate_illegal>> 180 eof <<terminate_illegal>>
181 catch_all <<continue>> 181 catch_all <<continue>>
182 182
183 <Identifier> 183 <Identifier>
184 identifier_char <<continue>> 184 identifier_char <<continue>>
185 /\\u[0-9a-fA-F]{4}/ { 185 /\\u[0-9a-fA-F]{4}/ {
186 if (V8_UNLIKELY(!ValidIdentifierStart())) { 186 if (V8_UNLIKELY(!ValidIdentifierStart())) {
187 PUSH_TOKEN(Token::ILLEGAL); 187 PUSH_TOKEN(Token::ILLEGAL);
188 } 188 }
189 } <<continue>> 189 } <<continue>>
190 default_action { PUSH_TOKEN(Token::IDENTIFIER); } 190 default_action push_token(IDENTIFIER)
191 191
192 <SingleLineComment> 192 <SingleLineComment>
193 line_terminator { PUSH_LINE_TERMINATOR(); } 193 line_terminator { PUSH_LINE_TERMINATOR(); }
194 eof <<terminate>> 194 eof <<terminate>>
195 catch_all <<continue>> 195 catch_all <<continue>>
196 196
197 <MultiLineComment> 197 <MultiLineComment>
198 "*/" { SKIP(); BACK(); goto code_start;} 198 "*/" { SKIP(); BACK(); goto code_start;}
199 /\*[^\057]/ <<continue>> 199 /\*[^\057]/ <<continue>>
200 # need to force action 200 # need to force action
201 line_terminator+ { PUSH_LINE_TERMINATOR(); } <<continue>> 201 line_terminator+ { PUSH_LINE_TERMINATOR(); } <<continue>>
202 eof <<terminate>> 202 eof <<terminate>>
203 catch_all <<continue>> 203 catch_all <<continue>>
204 204
205 <HtmlComment> 205 <HtmlComment>
206 "-->" { SKIP(); } 206 "-->" { SKIP(); }
207 /--./ <<continue>> 207 /--./ <<continue>>
208 /-./ <<continue>> 208 /-./ <<continue>>
209 # need to force action 209 # need to force action
210 line_terminator+ { PUSH_LINE_TERMINATOR(); } <<continue>> 210 line_terminator+ { PUSH_LINE_TERMINATOR(); } <<continue>>
211 eof <<terminate>> 211 eof <<terminate>>
212 catch_all <<continue>> 212 catch_all <<continue>>
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698