| OLD | NEW |
| 1 // Portions of this code based on re2c: | 1 // Portions of this code based on re2c: |
| 2 // (re2c/examples/push.re) | 2 // (re2c/examples/push.re) |
| 3 // Copyright 2013 the V8 project authors. All rights reserved. | 3 // Copyright 2013 the V8 project authors. All rights reserved. |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // - Run-time lexing modifications: harmony number literals, keywords depending | 37 // - Run-time lexing modifications: harmony number literals, keywords depending |
| 38 // on harmony_modules, harmony_scoping | 38 // on harmony_modules, harmony_scoping |
| 39 // - Escaping the string literals (like the baseline does) | 39 // - Escaping the string literals (like the baseline does) |
| 40 // - Error recovery after illegal tokens. | 40 // - Error recovery after illegal tokens. |
| 41 | 41 |
| 42 enum Condition { | 42 enum Condition { |
| 43 kConditionNormal, | 43 kConditionNormal, |
| 44 kConditionDoubleQuoteString, | 44 kConditionDoubleQuoteString, |
| 45 kConditionSingleQuoteString, | 45 kConditionSingleQuoteString, |
| 46 kConditionIdentifier, | 46 kConditionIdentifier, |
| 47 kConditionIdentifierIllegal, |
| 47 kConditionSingleLineComment, | 48 kConditionSingleLineComment, |
| 48 kConditionMultiLineComment, | 49 kConditionMultiLineComment, |
| 49 kConditionHtmlComment | 50 kConditionHtmlComment |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 #if defined(WIN32) | 53 #if defined(WIN32) |
| 53 | 54 |
| 54 typedef signed char int8_t; | 55 typedef signed char int8_t; |
| 55 typedef signed short int16_t; | 56 typedef signed short int16_t; |
| 56 typedef signed int int32_t; | 57 typedef signed int int32_t; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 re2c:define:YYCTYPE = uint8_t; | 191 re2c:define:YYCTYPE = uint8_t; |
| 191 re2c:define:YYLIMIT = limit_; | 192 re2c:define:YYLIMIT = limit_; |
| 192 re2c:define:YYMARKER = marker_; | 193 re2c:define:YYMARKER = marker_; |
| 193 | 194 |
| 194 eof = "\000"; | 195 eof = "\000"; |
| 195 any = [\000-\377]; | 196 any = [\000-\377]; |
| 196 whitespace_char = [ \t\v\f\r]; | 197 whitespace_char = [ \t\v\f\r]; |
| 197 whitespace = whitespace_char+; | 198 whitespace = whitespace_char+; |
| 198 identifier_start_ = [$_a-zA-Z]; | 199 identifier_start_ = [$_a-zA-Z]; |
| 199 identifier_char = [$_a-zA-Z0-9]; | 200 identifier_char = [$_a-zA-Z0-9]; |
| 200 not_identifier_char = any\identifier_char; | 201 not_identifier_char = any\identifier_char\[\\]; |
| 201 illegal_after_identifier = [\\]; | |
| 202 line_terminator = [\n\r]+; | 202 line_terminator = [\n\r]+; |
| 203 digit = [0-9]; | 203 digit = [0-9]; |
| 204 hex_digit = [0-9a-fA-F]; | 204 hex_digit = [0-9a-fA-F]; |
| 205 maybe_exponent = ('e' [-+]? digit+)?; | 205 maybe_exponent = ('e' [-+]? digit+)?; |
| 206 | 206 |
| 207 <Normal> "break" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::BREA
K); } | 207 <Normal> "break" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::BREA
K); } |
| 208 <Normal> "case" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CASE
); } | 208 <Normal> "case" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CASE
); } |
| 209 <Normal> "catch" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CATC
H); } | 209 <Normal> "catch" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CATC
H); } |
| 210 <Normal> "class" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU
RE_RESERVED_WORD); } | 210 <Normal> "class" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::FUTU
RE_RESERVED_WORD); } |
| 211 <Normal> "const" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CONS
T); } | 211 <Normal> "const" not_identifier_char { PUSH_TOKEN_LOOKAHEAD(Token::CONS
T); } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 <Normal> "~" { PUSH_TOKEN(Token::BIT_NOT); } | 311 <Normal> "~" { PUSH_TOKEN(Token::BIT_NOT); } |
| 312 <Normal> "," { PUSH_TOKEN(Token::COMMA); } | 312 <Normal> "," { PUSH_TOKEN(Token::COMMA); } |
| 313 | 313 |
| 314 <Normal> line_terminator { PUSH_LINE_TERMINATOR(); } | 314 <Normal> line_terminator { PUSH_LINE_TERMINATOR(); } |
| 315 <Normal> whitespace { SKIP(); } | 315 <Normal> whitespace { SKIP(); } |
| 316 | 316 |
| 317 <Normal> ["] :=> DoubleQuoteString | 317 <Normal> ["] :=> DoubleQuoteString |
| 318 <Normal> ['] :=> SingleQuoteString | 318 <Normal> ['] :=> SingleQuoteString |
| 319 | 319 |
| 320 <Normal> identifier_start_ :=> Identifier | 320 <Normal> identifier_start_ :=> Identifier |
| 321 <Normal> "\\u0000" :=> IdentifierIllegal |
| 322 <Normal> "\\u" [0-9a-fA-F]{4} :=> Identifier |
| 323 <Normal> "\\" { PUSH_TOKEN(Token::ILLEGAL); } |
| 321 | 324 |
| 322 <Normal> eof { PUSH_EOF_AND_RETURN();} | 325 <Normal> eof { PUSH_EOF_AND_RETURN();} |
| 323 <Normal> any { PUSH_TOKEN(Token::ILLEGAL); } | 326 <Normal> any { PUSH_TOKEN(Token::ILLEGAL); } |
| 324 | 327 |
| 325 <DoubleQuoteString> "\\\"" { goto yy0; } | 328 <DoubleQuoteString> "\\\"" { goto yy0; } |
| 326 <DoubleQuoteString> '"' { PUSH_TOKEN(Token::STRING);} | 329 <DoubleQuoteString> '"' { PUSH_TOKEN(Token::STRING);} |
| 327 <DoubleQuoteString> "\\" "\n" "\r"? { goto yy0; } | 330 <DoubleQuoteString> "\\" "\n" "\r"? { goto yy0; } |
| 328 <DoubleQuoteString> "\\" "\r" "\n"? { goto yy0; } | 331 <DoubleQuoteString> "\\" "\r" "\n"? { goto yy0; } |
| 329 <DoubleQuoteString> "\n" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } | 332 <DoubleQuoteString> "\n" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } |
| 330 <DoubleQuoteString> "\r" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } | 333 <DoubleQuoteString> "\r" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } |
| 331 <DoubleQuoteString> eof { TERMINATE_ILLEGAL(); } | 334 <DoubleQuoteString> eof { TERMINATE_ILLEGAL(); } |
| 332 <DoubleQuoteString> any { goto yy0; } | 335 <DoubleQuoteString> any { goto yy0; } |
| 333 | 336 |
| 334 <SingleQuoteString> "\\'" { goto yy0; } | 337 <SingleQuoteString> "\\'" { goto yy0; } |
| 335 <SingleQuoteString> "'" { PUSH_TOKEN(Token::STRING);} | 338 <SingleQuoteString> "'" { PUSH_TOKEN(Token::STRING);} |
| 336 <SingleQuoteString> "\\" "\n" "\r"? { goto yy0; } | 339 <SingleQuoteString> "\\" "\n" "\r"? { goto yy0; } |
| 337 <SingleQuoteString> "\\" "\r" "\n"? { goto yy0; } | 340 <SingleQuoteString> "\\" "\r" "\n"? { goto yy0; } |
| 338 <SingleQuoteString> "\n" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } | 341 <SingleQuoteString> "\n" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } |
| 339 <SingleQuoteString> "\r" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } | 342 <SingleQuoteString> "\r" => Normal { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } |
| 340 <SingleQuoteString> eof { TERMINATE_ILLEGAL(); } | 343 <SingleQuoteString> eof { TERMINATE_ILLEGAL(); } |
| 341 <SingleQuoteString> any { goto yy0; } | 344 <SingleQuoteString> any { goto yy0; } |
| 342 | 345 |
| 343 <Identifier> identifier_char+ { goto yy0; } | 346 <Identifier> identifier_char+ { goto yy0; } |
| 344 <Identifier> illegal_after_identifier { PUSH_TOKEN(Token::ILLEGAL); } | 347 <Identifier> "\\u0000" :=> IdentifierIllegal |
| 348 <Identifier> "\\u" [0-9a-fA-F]{4} { goto yy0; } |
| 349 <Identifier> "\\" { PUSH_TOKEN(Token::ILLEGAL); } |
| 345 <Identifier> any { PUSH_TOKEN_LOOKAHEAD(Token::IDENTIFIER); } | 350 <Identifier> any { PUSH_TOKEN_LOOKAHEAD(Token::IDENTIFIER); } |
| 346 | 351 |
| 352 <IdentifierIllegal> identifier_char+ { goto yy0; } |
| 353 <IdentifierIllegal> "\\"+ { goto yy0; } |
| 354 <IdentifierIllegal> any { PUSH_TOKEN_LOOKAHEAD(Token::ILLEGAL)
; } |
| 355 |
| 347 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();} | 356 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();} |
| 348 <SingleLineComment> eof { PUSH_LINE_TERMINATOR();} | 357 <SingleLineComment> eof { PUSH_LINE_TERMINATOR();} |
| 349 <SingleLineComment> any { goto yy0; } | 358 <SingleLineComment> any { goto yy0; } |
| 350 | 359 |
| 351 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();} | 360 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();} |
| 352 <MultiLineComment> eof { TERMINATE_ILLEGAL(); } | 361 <MultiLineComment> eof { TERMINATE_ILLEGAL(); } |
| 353 <MultiLineComment> any { goto yy0; } | 362 <MultiLineComment> any { goto yy0; } |
| 354 | 363 |
| 355 <HtmlComment> eof { TERMINATE_ILLEGAL(); } | 364 <HtmlComment> eof { TERMINATE_ILLEGAL(); } |
| 356 <HtmlComment> "-->" { PUSH_LINE_TERMINATOR();} | 365 <HtmlComment> "-->" { PUSH_LINE_TERMINATOR();} |
| (...skipping 26 matching lines...) Expand all Loading... |
| 383 size_t start_offset = start_ - buffer_; | 392 size_t start_offset = start_ - buffer_; |
| 384 memmove(buffer_, start_, limit_ - start_); | 393 memmove(buffer_, start_, limit_ - start_); |
| 385 marker_ -= start_offset; | 394 marker_ -= start_offset; |
| 386 cursor_ -= start_offset; | 395 cursor_ -= start_offset; |
| 387 limit_ -= start_offset; | 396 limit_ -= start_offset; |
| 388 start_ -= start_offset; | 397 start_ -= start_offset; |
| 389 real_start_ += start_offset; | 398 real_start_ += start_offset; |
| 390 } | 399 } |
| 391 return 0; | 400 return 0; |
| 392 } | 401 } |
| OLD | NEW |