reworking fix for Issue #383 with a more sensitive regex. (decimals without a leading zero)
This commit is contained in:
parent
a5478b0712
commit
a577b81eb3
13
lib/lexer.js
13
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]*)/;
|
||||
|
|
|
@ -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]*)/
|
||||
|
|
Loading…
Reference in New Issue