From 58ecfeb81501020222bbdcd958d2183560581fda Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 17 Dec 2009 20:59:19 -0500 Subject: [PATCH] added exponential and hex numbers --- TODO | 6 ++++++ examples/code.cs | 4 +++- lib/coffee_script/lexer.rb | 5 ++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 93dbd7f7..3eedb434 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,11 @@ TODO: +* Add TextMate syntax highlighter to the download. + +* Code Cleanup. + +* Add JS-style exponential number literals. + * Is it possible to close blocks (functions, ifs, trys) without an explicit block delimiter or significant whitespace? diff --git a/examples/code.cs b/examples/code.cs index aa497f1e..67899925 100644 --- a/examples/code.cs +++ b/examples/code.cs @@ -19,7 +19,9 @@ spaced_out_multiline_object: { pi: 3.14159 - list: [1, 2, 3, 4] + a_googol: 1e100 + + list: [-1, 0, 1, 2, 3, 4] regex: /match[ing](every|thing|\/)/gi diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index 17b2d486..41bec240 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -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