diff --git a/src/calmjs/parse/lexers/es2015.py b/src/calmjs/parse/lexers/es2015.py index 1dce694..62fbc54 100644 --- a/src/calmjs/parse/lexers/es2015.py +++ b/src/calmjs/parse/lexers/es2015.py @@ -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 ` diff --git a/src/calmjs/parse/tests/lexer.py b/src/calmjs/parse/tests/lexer.py index a791750..ba427a0 100644 --- a/src/calmjs/parse/tests/lexer.py +++ b/src/calmjs/parse/tests/lexer.py @@ -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', ('=> ...',