FIXES #383: Numbers that start with . not recognized
This commit is contained in:
parent
bf1f9f4b95
commit
385b18f588
12
lib/lexer.js
12
lib/lexer.js
|
@ -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]*)/;
|
||||
|
|
|
@ -106,8 +106,12 @@ exports.Lexer: class Lexer
|
|||
# Matches numbers, including decimals, hex, and exponential notation.
|
||||
number_token: ->
|
||||
return false unless number: @match NUMBER, 1
|
||||
@token 'NUMBER', 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
|
||||
|
||||
# Matches strings, including multi-line strings. Ensures that quotation marks
|
||||
|
@ -481,7 +485,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]*)/
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
class Issue380
|
||||
# Issue #380: problem with @ and instanceof
|
||||
class ClassName
|
||||
am_i: ->
|
||||
@ instanceof Issue380
|
||||
@ instanceof ClassName
|
||||
|
||||
ok (new Issue380()).am_i()
|
||||
obj: new ClassName()
|
||||
ok obj.am_i()
|
||||
|
||||
|
||||
# Issue #383: Numbers that start with . not recognized
|
||||
value: .25 + .75
|
||||
ok value is 1
|
||||
value: 0.0 + -.25 - -.75 + 0.0
|
||||
ok value is 0.5
|
||||
|
||||
deepEqual [0..10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
deepEqual [0...10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
|
Loading…
Reference in New Issue