Comments (4)
I made it that way to match Parsec's IResult
type, although passing a closure into Incomplete
proved too difficult for Rust.
I am not sure using Result
would be better, since depending on the context, Incomplete
can be an error case or a correct case.
If you need more helper functions, though, I could add them, that's not a problem.
from nom.
understood.
As for "more helper functions":
In examples i found only one case that needs it (this).
match keys_and_values_aggregator(input) {
IResult::Done(i,tuple_vec) => {
for &(k,v) in tuple_vec.iter() {
h.insert(k, v);
}
IResult::Done(i, h)
},
IResult::Incomplete(a) => IResult::Incomplete(a),
IResult::Error(a) => IResult::Error(a)
}
But in this code we can remove the explicit mapping (like this: IResult::Incomplete(a) => IResult::Incomplete(a),
) using map!
macro?:
named!(keys_and_values_aggregator<&[u8], Vec<(&str,&str)> >, many0!(key_value));
fn keys_and_values(input: Vec<(&str,&str)>) -> HashMap<&str, &str> {
let mut h: HashMap<&str, &str> = HashMap::new();
for &(k,v) in input.iter() {
h.insert(k, v);
}
h
}
named!(keys_and_values_hashmap<&[u8], HashMap<&str, &str> >, map!(keys_and_values_aggregator, keys_and_values));
In short, helper functions enough. Just instead of the standard functionality necessary to use helper functions.
from nom.
I see what you mean. I wrote the INI parser a few months ago, and there was not as much tooling (and I did not know I could do if let IResult::Done(i,o) = ...
).
The map!
and flat_map!
macros are useful for those cases. At one point, I had implemented those as a trait on IResult
, but the generic types and the lifetimes made the code impossible to maintain.
from nom.
Thanks for the answer.
from nom.
Related Issues (20)
- How to parse until a range of tags HOT 3
- Mention difference between is_not and take_until in their respective docs.
- I was going to complain about an issue in the function take_while_m_n, but [update : and I will do] ...
- Add u48 number parser HOT 1
- I want to implement `separated_tuple` for 8.0 HOT 7
- `tag_no_case` panicks while matching certain unicode capitalized characters.
- Ergonomics of `alt()` taking tuple versus slice HOT 3
- A new release for 8.0?
- FromStr-esque parsing trait HOT 1
- Float parsing with trailing `e` broken
- A fix has to be implemented by those dependencies HOT 7
- FlatMap does not properly implement Parser HOT 2
- Feature Request: Add branching parser combinator for `exclude()` and `depend()` HOT 1
- Document (or fix?) the fact that escaped() succeeds on empty inputs HOT 7
- Stack overflow before parsing HOT 1
- fold's param init func should be FnOnce instead of FnMut HOT 3
- Profile-Guided Optimization (PGO) benchmark results
- Fn / FnMut HOT 7
- Suprised by error from `is_not` on empty result
- feature request: `maybe_delimited` 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 nom.