Skip to content

Commit

Permalink
Include binary and octal number literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
metatoaster committed Nov 10, 2018
1 parent 8d701fe commit 58ed10f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/calmjs/parse/lexers/es2015.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ class Lexer(ES5Lexer):
'TEMPLATE_NOSUB', 'TEMPLATE_HEAD', 'TEMPLATE_MIDDLE', 'TEMPLATE_TAIL',
)

t_NUMBER = r"""
(?: 0[bB][01]+ # binary_integer_literal
| 0[oO][0-7]+ # or octal_integer_literal
| 0[xX][0-9a-fA-F]+ # or hex_integer_literal
| 0[0-7]+ # or legacy_octal_integer_literal
| (?: # or decimal_literal
(?:0|[1-9][0-9]*) # decimal_integer_literal
\. # dot
[0-9]* # decimal_digits_opt
(?:[eE][+-]?[0-9]+)? # exponent_part_opt
|
\. # dot
[0-9]+ # decimal_digits
(?:[eE][+-]?[0-9]+)? # exponent_part_opt
|
(?:0|[1-9][0-9]*) # decimal_integer_literal
(?:[eE][+-]?[0-9]+)? # exponent_part_opt
)
)
"""

template = r"""
(?:(?:`|}) # opening ` or }
(?: [^`\\] # no \, or `
Expand Down
4 changes: 4 additions & 0 deletions src/calmjs/parse/tests/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@
('function *gen() { yield 1 }',
['FUNCTION function', 'MULT *', 'ID gen', 'LPAREN (', 'RPAREN )',
'LBRACE {', 'YIELD yield', 'NUMBER 1', 'RBRACE }']),
), (
'es2015_numbers',
(('0b1011 0B1101 0o755 0O644'),
['NUMBER 0b1011', 'NUMBER 0B1101', 'NUMBER 0o755', 'NUMBER 0O644']),
), (
'punctuators',
('=> ...',
Expand Down

0 comments on commit 58ed10f

Please sign in to comment.