added exponential and hex numbers

This commit is contained in:
Jeremy Ashkenas
2009-12-17 20:59:19 -05:00
parent 398251ff90
commit 2c90e8b002
3 changed files with 11 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ class Lexer
"super"]
IDENTIFIER = /\A([a-zA-Z$_]\w*)/
NUMBER = /\A([0-9]+(\.[0-9]+)?)/
NUMBER = /\A\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b/i
STRING = /\A("(.*?)[^\\]"|'(.*?)[^\\]')/m
JS = /\A(`(.*?)`)/
OPERATOR = /\A([+\*&|\/\-%=<>]+)/
@@ -65,8 +65,7 @@ class Lexer
def number_token
return false unless number = @chunk[NUMBER, 1]
float = number.include?('.')
token(:NUMBER, float ? number.to_f : number.to_i)
token(:NUMBER, number)
@i += number.length
end