Comments (5)
My reasoning is twofold: A putState
parser would make it really simple to port things from (F)Parsec. Second, I'd like userState
state to revert if the parser needs to backtrack, and that won't happen automatically if I'm always mutating it in place (right?).
from parjs.
@mgreenbe Interesting! I never really thought about reverting user state. And yeah, you're right, it's probably not possible unless I allow replacing user state in the first place.
Now that I see the reasoning, it's definitely something I'll add. The two techniques can be complementary.
from parjs.
Nope. It's sort-of by design. In Haskell, there is no way to mutate anything at all, so you have to be able to replace the user state. In F# or similar, you can't just define properties on the state object willy-nilly either, so again you need to have a way to alter it.
In JavaScript though, I think it's not needed and keeping the same user state object throughout the parsing session has advantages. There is no problem of parallelism, since this is totally synchronous JS we're talking about. You need to allocate fewer objects, and there is no problem of erasing data other parsers need to function. It also just seems appealing in terms of API, since that way there is a single, unified method of modifying user state, and you can do it from pretty much any parser/combinator.
If you don't want to add/delete properties from the object whenever you want, you can always create a specific property, e.g. immutable
, and update only that property with a new object every time. The result is quite similar to a putState
parser.
But if you really don't like it, I can just add it in. Can you explain why it's important to you?
from parjs.
Thanks! This will be a big help to me.
from parjs.
Now there is a replaceState
combinator that fulfills this role. It replaces the state in the context of the parser you're applying it to.
from parjs.
Related Issues (20)
- Proposal - venturing outside the Basic Multilingual Plane
- Proposal - parser and combinator modifiers HOT 3
- StringLen parser uses substring incorrectly, leading to incorrect results HOT 1
- Not (not) capturing HOT 2
- Publishing new versions is broken on the master branch HOT 1
- docs: add a friendly guide for users
- docs: create documentation explaining how to create new parsers
- refactor: replace overloaded functions with mapped types HOT 1
- Reconsider “quiet” parsers
- refactor: Get rid of namespaces HOT 1
- Debugging feature: textual descriptions for parsers HOT 2
- Debugging feature: a zero key
- docs: add performance comparison to other parsing techniques
- test: assert parser positions after combinator failures
- test: add type level tests HOT 2
- feature: Case insensitive string parsing HOT 4
- Example of custom parser from `README.md` doesn't work HOT 4
- Releasing a new version is having challenges HOT 4
- Main documentation describes an upcoming version instead of the current one HOT 1
- More unicode support for character parsing: `anyUniCharOf` and `uniCharCodeWhere` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parjs.