Skip to content

Commit 3f5fe3b

Browse files
committed
Don't use objects for lexing idents
1 parent de04de4 commit 3f5fe3b

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

jmespath.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
};
130130
}
131131

132-
133132
// Type constants used to define functions.
134133
var TYPE_NUMBER = 0;
135134
var TYPE_ANY = 1;
@@ -142,7 +141,6 @@
142141
var TYPE_ARRAY_NUMBER = 8;
143142
var TYPE_ARRAY_STRING = 9;
144143

145-
146144
var TOK_EOF = "EOF";
147145
var TOK_UNQUOTEDIDENTIFIER = "UnquotedIdentifier";
148146
var TOK_QUOTEDIDENTIFIER = "QuotedIdentifier";
@@ -192,16 +190,6 @@
192190
"@": TOK_CURRENT
193191
};
194192

195-
var identifierStart = {
196-
a: true, b: true, c: true, d: true, e: true, f: true, g: true, h: true,
197-
i: true, j: true, k: true, l: true, m: true, n: true, o: true, p: true,
198-
q: true, r: true, s: true, t: true, u: true, v: true, w: true, x: true,
199-
y: true, z: true, A: true, B: true, C: true, D: true, E: true, F: true,
200-
G: true, H: true, I: true, J: true, K: true, L: true, M: true, N: true,
201-
O: true, P: true, Q: true, R: true, S: true, T: true, U: true, V: true,
202-
W: true, X: true, Y: true, Z: true, _: true
203-
};
204-
205193
var operatorStartToken = {
206194
"<": true,
207195
">": true,
@@ -223,15 +211,26 @@
223211
"-": true
224212
};
225213

226-
var identifierTrailing = merge(identifierStart, numbers);
227-
228214
var skipChars = {
229215
" ": true,
230216
"\t": true,
231217
"\n": true
232218
};
233219

234220

221+
function isAlpha(ch) {
222+
return (ch >= "a" && ch <= "z") ||
223+
(ch >= "A" && ch <= "Z") ||
224+
ch === "_"
225+
}
226+
227+
function isAlphaNum(ch) {
228+
return (ch >= "a" && ch <= "z") ||
229+
(ch >= "A" && ch <= "Z") ||
230+
(ch >= "0" && ch <= "9") ||
231+
ch === "_"
232+
}
233+
235234
function Lexer() {
236235
}
237236
Lexer.prototype = {
@@ -242,7 +241,7 @@
242241
var identifier;
243242
var token;
244243
while (this.current < stream.length) {
245-
if (identifierStart[stream[this.current]] !== undefined) {
244+
if (isAlpha(stream[this.current])) {
246245
start = this.current;
247246
identifier = this.consumeUnquotedIdentifier(stream);
248247
tokens.push({type: TOK_UNQUOTEDIDENTIFIER,
@@ -314,7 +313,7 @@
314313
consumeUnquotedIdentifier: function(stream) {
315314
var start = this.current;
316315
this.current++;
317-
while (identifierTrailing[stream[this.current]] !== undefined) {
316+
while (this.current < stream.length && isAlphaNum(stream[this.current])) {
318317
this.current++;
319318
}
320319
return stream.slice(start, this.current);

0 commit comments

Comments
 (0)