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

parser has state? #129

Closed
uriva opened this issue Oct 1, 2016 · 3 comments
Closed

parser has state? #129

uriva opened this issue Oct 1, 2016 · 3 comments
Labels

Comments

@uriva
Copy link
Contributor

uriva commented Oct 1, 2016

I ran into some trouble using feed iteratively, then saw in the docs that it is meant for reading input in parts.

This means that if you want to parse multiple times you need to create a new parser object every time. Is that as intended?

@kach
Copy link
Owner

kach commented Oct 1, 2016

Yes, exactly. You need to instantiate a fresh parser to parse a fresh string.

@multimeric
Copy link

Do you think we should make a nicer API for people who want to parse many separate strings? For example a .reset() method that clears state so we don't have to make parser factories every time?

@tjvr tjvr added the question label Feb 16, 2017
@tjvr
Copy link
Collaborator

tjvr commented Feb 16, 2017

Despite the name, the instantiation of Parser is intended to be cheap; you shouldn't worry about creating a fresh one each time. In particular, initialising the first column of the table is something that needs to be done afresh for each parse*.

The only avoidable work that's done in the constructor is this line, making the Rules, but that will go away when I refactor Grammar into its own thing.

Ideally we'd rename it Parse, I suppose, but that seems awkward; and, well, backwards compatibility.

[* @Hardmath123: FWIW, I'm slightly lying here. Assuming the grammar doesn't change, you can preserve the first column. But you can do that yourself by rewind(0), if we add a rewind feature #165 .]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants