FIXES #383: Numbers that start with . not recognized

This commit is contained in:
Stan Angeloff
2010-05-20 00:20:33 +03:00
parent bf1f9f4b95
commit 385b18f588
3 changed files with 30 additions and 8 deletions

View File

@@ -157,12 +157,18 @@
};
// Matches numbers, including decimals, hex, and exponential notation.
Lexer.prototype.number_token = function() {
var number;
var leading, number;
if (!(number = this.match(NUMBER, 1))) {
return false;
}
this.token('NUMBER', number);
this.i += number.length;
if (starts(number, (leading = '.') + leading)) {
while (starts(number, leading)) {
this.token(leading, leading);
number = number.substring(leading.length);
}
}
this.token('NUMBER', number);
return true;
};
// Matches strings, including multi-line strings. Ensures that quotation marks
@@ -655,7 +661,7 @@
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
// Token matching regexes.
IDENTIFIER = /^([a-zA-Z\$_](\w|\$)*)/;
NUMBER = /^(\b((0(x|X)[0-9a-fA-F]+)|([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]*)/;