Skip to content

Commit 58ed10f

Browse files
committed
Include binary and octal number literals.
1 parent 8d701fe commit 58ed10f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/calmjs/parse/lexers/es2015.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ class Lexer(ES5Lexer):
5050
'TEMPLATE_NOSUB', 'TEMPLATE_HEAD', 'TEMPLATE_MIDDLE', 'TEMPLATE_TAIL',
5151
)
5252

53+
t_NUMBER = r"""
54+
(?: 0[bB][01]+ # binary_integer_literal
55+
| 0[oO][0-7]+ # or octal_integer_literal
56+
| 0[xX][0-9a-fA-F]+ # or hex_integer_literal
57+
| 0[0-7]+ # or legacy_octal_integer_literal
58+
| (?: # or decimal_literal
59+
(?:0|[1-9][0-9]*) # decimal_integer_literal
60+
\. # dot
61+
[0-9]* # decimal_digits_opt
62+
(?:[eE][+-]?[0-9]+)? # exponent_part_opt
63+
|
64+
\. # dot
65+
[0-9]+ # decimal_digits
66+
(?:[eE][+-]?[0-9]+)? # exponent_part_opt
67+
|
68+
(?:0|[1-9][0-9]*) # decimal_integer_literal
69+
(?:[eE][+-]?[0-9]+)? # exponent_part_opt
70+
)
71+
)
72+
"""
73+
5374
template = r"""
5475
(?:(?:`|}) # opening ` or }
5576
(?: [^`\\] # no \, or `

src/calmjs/parse/tests/lexer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@
501501
('function *gen() { yield 1 }',
502502
['FUNCTION function', 'MULT *', 'ID gen', 'LPAREN (', 'RPAREN )',
503503
'LBRACE {', 'YIELD yield', 'NUMBER 1', 'RBRACE }']),
504+
), (
505+
'es2015_numbers',
506+
(('0b1011 0B1101 0o755 0O644'),
507+
['NUMBER 0b1011', 'NUMBER 0B1101', 'NUMBER 0o755', 'NUMBER 0O644']),
504508
), (
505509
'punctuators',
506510
('=> ...',

0 commit comments

Comments
 (0)