-
Notifications
You must be signed in to change notification settings - Fork 96
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
Please, provide guideline with example for creating a parser #85
Comments
Something like this should work for parser(|input: &str| {
let mut iter = input.graphemes();
match iter.next() {
Some(g) => {
// Since we have consumed something to get to this point we need tell the caller this so it knows
// whether to try other alternatives (if this errors later on)
Ok((g, Consumed::Consumed(iter.as_str()))
}
None => Err(ParseError::end_of_input()),
}
}) For a more generic parser I think that we need to at least limit the parser to I am thinking that maybe I can add another method to // `remaining` returns the entire remaining range which can be inspected letting one determine
// the length one need to pass to `uncons_range`
fn remaining(&self) -> Self::Range;
There is really nothing special about any of these. |
I was not asking for help, I was suggesting you enhance the documentation. The response is not useful here (I've already decided I am not rewriting the nom thing). It would be somewhat useful in the documentation though—as long as you improve documentation of ParseError—I see all of 2 lines for the struct and nothing for most methods. |
Ok. |
Well, but it's what one comes at when looking up the return type. So you either need to document them there, or you need to put a documentation somewhere up the chain describing how to create errors—which would mean in ParseResult, because there the error type is directly |
I needed to parse something that has rather simple structure, but I needed one element to be a grapheme (the rest is mostly ascii symbols with specific meanings). Now no parser library provides such parser out of the box and it is not surprising; the functionality to split string to graphemes is only provided by the unicode-segmentation crate.
I had something already slapped together in nom, except I was not (and still am not) happy with it, because it should operate on
&str
, but has to operate on&[u8]
, because nom lacks&str
variants of some important primitives. So I considered rewriting it incombine
, but gave up, because I had trouble figuring how to write the function that would work withparser()
regarding:How generic/specific it can be. The
unicode-segmentation
only works on&str
(because of shortcomings of Rust iterators; another story) and I always have that to provide, but I didn't see documentation about what might/might not come in the inner parser. The example in description ofparse()
appears to take just&str
in the closure, but I didn't see description.How to properly construct the error. The
ParseError
/Error
/Info
construct is pretty complicated and would deserve some explanation, but I failed to run across any. And perhaps also some helpers to create the Expected and Unexpected primary errors from a stream state and (in the first case; unexpected does not need one) message easily.The text was updated successfully, but these errors were encountered: