moo icon indicating copy to clipboard operation
moo copied to clipboard

Fix saving and resetting queued groups

Open ictrobot opened this issue 3 years ago • 0 comments

Currently Lexer.prototype.reset and Lexer.prototype.save reference three queued fields: queuedToken, queuedText (added in #169) and queuedThrow.

There only appear to be references to queuedText and queuedGroup elsewhere, so this MR removes queuedToken and queuedThrow and adds queuedGroup to reset and save.

The below example shows how this could be problematic - on master it prints a token when it probably shouldn't:

const moo = require("./moo")

const lexer = moo.compile({
    number: {match: /\d+/},
    text: moo.fallback
})

lexer.reset('test123')
lexer.next()
lexer.reset()
console.log(lexer.next())

ictrobot avatar Jun 22 '22 22:06 ictrobot