Ox.tokenize: handle hex numbers and numbers with exponent

This commit is contained in:
rolux 2012-06-04 15:36:25 +02:00
parent c4ad59bdb6
commit 56c6ef98c7

View file

@ -892,8 +892,9 @@ Ox.tokenize <f> Tokenizes JavaScript
14
> Ox.tokenize('return /foo/g;')[2].value.length
6
> Ox.tokenize('[0xFF, 1e1, 1e+1, 1e-1, 1e+1+1]').length
17
@*/
// FIXME: numbers (hex, exp, etc.)
Ox.tokenize = (function() {
// see https://github.com/mozilla/narcissus/blob/master/lib/lexer.js
@ -989,7 +990,14 @@ Ox.tokenize = (function() {
while (linebreak.indexOf(source[++cursor]) > -1) {}
} else if (number.indexOf(char) > -1) {
type = 'number';
while ((number + '.').indexOf(source[++cursor]) > -1) {}
while ((number + '.abcdefxABCDEFX+-').indexOf(source[++cursor]) > -1) {
if (
source[cursor - 1] != 'e' && source[cursor - 1] != 'E'
&& (source[cursor] == '+' || source[cursor] == '-')
) {
break;
}
}
} else if (char == '/' && isRegExp(tokens)) {
type = 'regexp';
while ((char = source[++cursor]) != '/' && cursor < length) {