Closed deltaidea closed 7 years ago
This would also close #47.
You haven't pushed the latest code to GitHub (npm is ahead of master)
Oops, thanks. Fixed!
Your solution looks to be along the right lines; please could you send a PR? Thanks! :-)
Sure! Which implementation style would you prefer: the one above or this:
Lexer.prototype.has = function(tokenType) {
// Both lexer.states and group.keywords are created with no prototype
// so it's safe to iterate without the `hasOwnProperty` check.
for (var s in this.states) {
for (var g = this.states[s].groups.length; g--; ) {
if (this.states[s].groups[g].tokenType === tokenType) return true
if (this.states[s].groups[g].keywords) {
for (var k in this.states[s].groups[g].keywords ) {
if (this.states[s].groups[g].keywords[k].tokenType === tokenType) return true
}
}
}
}
return false
}
It's less verbose but with more property accesses.
I think it should be alright to use in
here (we're not particularly concerned about perf, since one should only call has
at compile-time); so I think I'd prefer the second one, since that seems easier to read—but without the verbosity/repetition :-)
Got it! Did it even better (#51).
You haven't pushed the latest code to GitHub (npm is ahead of master). Here's a solution:
Tests