Skip to content

Commit 05d93dd

Browse files
committed
Don't use lookup table for lexing numbers
1 parent 3f5fe3b commit 05d93dd

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

jmespath.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,38 +197,28 @@
197197
"!": true
198198
};
199199

200-
var numbers = {
201-
0: true,
202-
1: true,
203-
2: true,
204-
3: true,
205-
4: true,
206-
5: true,
207-
6: true,
208-
7: true,
209-
8: true,
210-
9: true,
211-
"-": true
212-
};
213-
214200
var skipChars = {
215201
" ": true,
216202
"\t": true,
217203
"\n": true
218204
};
219205

220206

221-
function isAlpha(ch) {
207+
function isAlpha(ch) {
222208
return (ch >= "a" && ch <= "z") ||
223209
(ch >= "A" && ch <= "Z") ||
224-
ch === "_"
210+
ch === "_";
225211
}
226212

213+
function isNum(ch) {
214+
return (ch >= "0" && ch <= "9") ||
215+
ch === "-";
216+
}
227217
function isAlphaNum(ch) {
228218
return (ch >= "a" && ch <= "z") ||
229219
(ch >= "A" && ch <= "Z") ||
230220
(ch >= "0" && ch <= "9") ||
231-
ch === "_"
221+
ch === "_";
232222
}
233223

234224
function Lexer() {
@@ -252,7 +242,7 @@
252242
value: stream[this.current],
253243
start: this.current});
254244
this.current++;
255-
} else if (numbers[stream[this.current]] !== undefined) {
245+
} else if (isNum(stream[this.current])) {
256246
token = this.consumeNumber(stream);
257247
tokens.push(token);
258248
} else if (stream[this.current] === "[") {
@@ -362,7 +352,7 @@
362352
var start = this.current;
363353
this.current++;
364354
var maxLength = stream.length;
365-
while (numbers[stream[this.current]] !== undefined && this.current < maxLength) {
355+
while (isNum(stream[this.current]) && this.current < maxLength) {
366356
this.current++;
367357
}
368358
var value = parseInt(stream.slice(start, this.current));

0 commit comments

Comments
 (0)