-
Notifications
You must be signed in to change notification settings - Fork 126
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
WIP this probably works now? #190
Conversation
My only concern is that state may not be correctly piped through all the combinator functions. This would require a lot of extra testing to validate. The good part is it wasn't much work to make the test suite pass, and I ran this version of the library against three of my programming languages, including Squiggle, and it appeared to function correctly still.
1 similar comment
Well. You will have to either warn everyone about immutable nature of state or simply deepFreeze it. Not sure if there is practical use case for explicit state other then indentation based languages, so probably mapState is not needed unless someone will come up with another use case. |
Yeah, I think I'll just go with a warning in that case. It's an advanced API normally not needed.
That's fair. It's something that could be added later. |
I've come up with a better solution to the problem that doesn't involve introducing state tracking into Parsimmon, so I'm gonna decline this PR despite all the time I've sunk into it >_< |
Summary
3 core functions:
These consume 0 or more space characters, and update the parser state as necessary. Now all parsers take
(string, index, state)
instead of just(string, index)
, and.parse
and.tryParse
take an optional second parameter for the initial state, which defaults to[0]
, the state format expected by theParsimmon.indent*
functions.If you check out
examples/python-ish.js
in this branch you should see it's fairly straightforward to parse a space-indented language with these parsers and internal changes. But it's not extensible at all, so if your indentation is more complicated then you'll have to hook directly into state tracking yourself.Concerns
State currently may not be correctly piped through all the combinator functions. This would require a lot of extra testing to validate. The good part is it wasn't much work to make the test suite pass, and I ran this version of the library against three of my programming languages, including Squiggle, and it appeared to function correctly still.
JavaScript is filled with mutable data structures, which are a poor fit for state tracking, so exposing the internals is a bit dangerous. This state API will need to come with copious warnings.
Maybe?
Parsimmon.indent*
things into functions that take a parser?countSpaces
?TODO: Do not merge into master
python-ish.js