-
Notifications
You must be signed in to change notification settings - Fork 809
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
Reduce syntactic noise #1408
Comments
My personal way to import nom module is as follow: use nom::{
branch, bytes::complete as bytes, character::complete as character, combinator, multi,
sequence, AsChar, IResult as Outcome,
};
pub(crate) fn dec_int(input: &str) -> IResult<&str, &str> {
combinator::recognize(sequence::tuple((
combinator::opt(multi::alt((character::char('+'), character::char('-')))),
multi::alt((
character::char('0'),
combinator::map(
sequence::tuple((
character::satisfy(|c| ('1'..='9').contains(&c)),
multi::take_while(is_dec_digit_with_sep),
)),
|t| t.0,
),
)),
)))(input)
} You get the idea. I think it's quite clear that way, that easy to read and write. I opposite to flattering module.
That should be possible, for char yes, for u8 I'm not sure could be confusing and allow mistake, yes for &[u8] and &str. |
I could see a world where we inverse
|
These look like interesting suggestions, and more methods in Parser would be nice. I'm not sure about putting too much emphasis on method calls though (well, for map it's natural). Personally I like that there are multiple styles available, and maybe that is what the docs should show. |
For the module hierarchy and allowing
|
Prerequisites
Here are a few things you should provide to help me understand the issue:
Test case
I wanted to experiment with porting
toml_edit
to nom. Papercuts I ran intouse nom::...::*;
led to conflicts between nom, my parserr, andstd
(especiallychar
0combine
, a lot of the syntactic noise of nom stands out (though I still prefer nom)An example parser
Ideal:
EDIT: version based on https://github.com/epage/nom-experimental
Unsure how much is even possible or what downsides there might be, but ideas include
many0
,many_m_n
) #1393 can help keep it navigatable)impl Parser
foru8
,&[u8]
,char
, and&str
, reducing the need forchar
andtag
Maybe even implement parsers for ranges ofu8
andchar
streaming
vscomplete
prevents thisimpl Parser
for tuples, reducing the need fortuple(())
, impl Parser for tuples #1417Parser::map
in "choose your combinator" and docs (I didn't know it existed until I started writing this), Update docs to point toParser::map
overnom::combinator::map
. #1415Parser
, likeParser::between(first, third)
Parser::terminated_by(second)
Parser::preceded_by(first)
Parser::recognize()
Parser::consumed()
Parser::verify(bool)
Parser::cut()
Parser::complete()
Parser::context(ctx)
foo.not()
, grantedpreceded_by
somewhat violates that)self
should be a parser that is returning its valuemap_res
/map_opt
combinators to Parser #1562Figured I'd create this on issue for exploring the ideas and then create individual ones, rather than flood the issue list with every random idea
The text was updated successfully, but these errors were encountered: