Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove feed() and add remaining() #44

Merged
merged 3 commits into from
Apr 9, 2017
Merged

Remove feed() and add remaining() #44

merged 3 commits into from
Apr 9, 2017

Conversation

tjvr
Copy link
Collaborator

@tjvr tjvr commented Apr 5, 2017

Closes #43.

@nathan
Copy link
Collaborator

nathan commented Apr 5, 2017

What is remaining() good for?

@tjvr
Copy link
Collaborator Author

tjvr commented Apr 5, 2017

It's supposed to help implement the streaming strategies in #43. But now you mention it, I suppose you can workaround this by taking token.index + token.size, and keeping a copy of the buffer yourself.

This reverts commit 81a0ac8.
@nathan
Copy link
Collaborator

nathan commented Apr 5, 2017

So if you're using streams you'd now do the following?

const lexer = moo.compile({})

let state
fs.createReadStream(INPUT)
.pipe(split())
.pipe(new Transform({
  readableObjectMode: true,
  transform(chunk, _, cb) {
    lexer.reset(chunk.toString(), state)
    for (const t of lexer) this.push(t)
    state = lexer.save()
    cb()
  },
})

EDIT: state

@tjvr
Copy link
Collaborator Author

tjvr commented Apr 5, 2017

Yes, although you need to save() state between chunks and restore it.

@tjvr tjvr merged commit 09767a7 into master Apr 9, 2017
@tjvr tjvr deleted the remove-feed branch April 9, 2017 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants