Comments (4)
Ah yes! Thank you those are exactly what I need
from chumsky.
Perhaps .filter(...)
is what you're looking for? You can do a.filter(|a| a.is_foo())
. I think you might be a bit confused about how parser outputs work though: Fallibility is built in to a parser, if the filter closure returns false
, then the parser just won't parse anything.
from chumsky.
No, that's not really what i'm looking for. I'm not looking for a fallible parser, but for one that will parse something or not parse something based on a condition independent of what is being parsed. So condition(true, just('a'))
is a parser with output Option<char>
, specifically Some(a)
.
from chumsky.
Ah, are you trying to dynamically change the behaviour of your parser at runtime based on some configuration for the parser? I assumed that the condition was dependent on the output of the parser. In that case, there are a few approaches you can take:
-
Parsers can be dynamically dispatched, so you can do
if condition { a.map(Some).boxed() } else { empty().to(None).boxed() }
and this should type-check just fine (the parser in theelse
branch always succeeds while parsing no tokens) -
Use
custom
like so:
custom(|inp| if condition { inp.parse(a).map(Some) } else { Ok(None) })
this approach avoids the dynamic dispatch of the previous approach.
from chumsky.
Related Issues (20)
- Better Developer Experience HOT 1
- alpha-1.0.0-alpha.6 release broken? HOT 4
- Indentation example: incorrect "end of input" HOT 2
- or combinator prefers output of second parser, even if first parser succeeds HOT 14
- when use tokio::spawn i meet problem anyone can help HOT 6
- `nested_in()` + `repeated()` produce incorrect error spans. HOT 5
- Failed to compile benches: no method named `slice` found
- `ContainerExactly` impls for `Rc` and `Arc` are unsound HOT 2
- Clone trait bounds not satisfied HOT 2
- Trait bound not satisfied on foldl HOT 2
- Input lifetimes HOT 4
- bug: couldn't build `examples/foo.rs` HOT 1
- Query : Create a parser that parses a vec of patterns HOT 7
- Crashed while parsing markup text HOT 4
- Fix SpannedInput HOT 1
- Trying to run the `nano_rust.rs` example using `chumsky = "1.0.0-alpha.6"` HOT 4
- Question: Using `map_with` to get spans HOT 2
- Question: Writing a Ternary Operator Parser HOT 5
- Can't build example 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 chumsky.