diff --git a/lib/lexer.js b/lib/lexer.js index 31348a48..e8d49c64 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -155,17 +155,14 @@ }; // Matches numbers, including decimals, hex, and exponential notation. Lexer.prototype.number_token = function() { - var leading, number; + var number; if (!(number = this.match(NUMBER, 1))) { return false; } - this.i += number.length; - if (starts(number, (leading = '.') + leading)) { - while (starts(number, leading)) { - this.token(leading, leading); - number = number.substring(leading.length); - } + if (this.tag() === '.' && starts(number, '.')) { + return false; } + this.i += number.length; this.token('NUMBER', number); return true; }; @@ -665,7 +662,7 @@ JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED); // Token matching regexes. IDENTIFIER = /^([a-zA-Z\$_](\w|\$)*)/; - NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|(((\b[0-9]+(\.[0-9]+)?)|([\.]+[0-9]+))(e[+\-]?[0-9]+)?)))\b/i; + NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b/i; HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/; INTERPOLATION = /^\$([a-zA-Z_@]\w*(\.\w+)*)/; OPERATOR = /^([+\*&|\/\-%=<>:!?]+)([ \t]*)/; diff --git a/src/lexer.coffee b/src/lexer.coffee index 8cf1204a..af59d60b 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -102,13 +102,11 @@ exports.Lexer: class Lexer true # Matches numbers, including decimals, hex, and exponential notation. + # Be careful not to interfere with ranges-in-progress. number_token: -> return false unless number: @match NUMBER, 1 + return false if @tag() is '.' and starts number, '.' @i: + number.length - if starts number, (leading: '.') + leading - while starts number, leading - @token leading, leading - number: number.substring leading.length @token 'NUMBER', number true @@ -488,7 +486,7 @@ JS_FORBIDDEN: JS_KEYWORDS.concat RESERVED # Token matching regexes. IDENTIFIER : /^([a-zA-Z\$_](\w|\$)*)/ -NUMBER : /^(((\b0(x|X)[0-9a-fA-F]+)|(((\b[0-9]+(\.[0-9]+)?)|([\.]+[0-9]+))(e[+\-]?[0-9]+)?)))\b/i +NUMBER : /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b/i HEREDOC : /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/ INTERPOLATION : /^\$([a-zA-Z_@]\w*(\.\w+)*)/ OPERATOR : /^([+\*&|\/\-%=<>:!?]+)([ \t]*)/