Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Jeremy Day
@z2oh
which throws away the parsed result and replaces it with some value (an instance of an Operator enum variant, for example)
whentze
@whentze
oh, i see
that's nice
thank you
i think i can group them somewhat usefully
Jeremy Day
@z2oh
The alt! macro I don't think is limited, since macros can emulate variadic arguments
Here is the relevant issue on the limitations of alt: Geal/nom#994
whentze
@whentze
can i combine macro-based parsers with function-based ones?
Jeremy Day
@z2oh
When grouping operators you need to be careful about ordering though. If you have ">" and ">>" operators for example, you should be careful that the ">>" appears as an earlier alt branch
whentze
@whentze
yeah, but as i said, I'm lucky and there are no operators that are prefixes of others
so i can group freely :)
Jeremy Day
@z2oh
Oh excellent :) I have had some level of success mixing macros and functions but I don't think it is supported
whentze
@whentze
does the limitation about length mentioned in the docs for alt! still apply to the alt function?
i.e. if i have a longer tag first in the list, will it parse too far when matching a later tag?
Denis Lisov
@tanriol
If you're using the complete version of the tag parser, should not be a problem.
whentze
@whentze
ah, right, i am
the macros are always the streaming version, i forgot
whentze
@whentze
are there utilities for parsing decimal numbers in nom?
Denis Lisov
@tanriol
Floating point or specifically decimal?
whentze
@whentze
ascii decimal integers
like "14"
of course std can do this, but then i'd have to wrap that in something to make it work with nom's combinators (right?)
ah, the s_expression example does this as well
Simon Thornington
@sthornington
quick question, just trying to get up to speed on nom. a lot of the docs still refer to macros, like https://github.com/Geal/nom/blob/master/doc/choosing_a_combinator.md -- in nom 5, is it safe to assume that for all of these, I should instead be looking for like-named functions ?
dangrabcad
@dangrabcad
@sthornington yes, that's right
whentze
@whentze
somehow i'm still seeing different behavior when swapping the order of arguments to alt(), even though all the lowest-level parsers are "complete" variants
is this expected?
i.e. I have alt(parser1, parser2), which errors because parser1 fails, even though parser2 would match
alt(parser2, parser1) accepts the same string
Denis Lisov
@tanriol
Does parser1 fail with an Err::Error or with an Err::Failure?
whentze
@whentze
Err::Error
Denis Lisov
@tanriol
Sounds like a bug to me.
whentze
@whentze
Err::Error(Tag) to be precise
Simon Thornington
@sthornington
okay cool thanks @dangrabcad . I'm actually pretty happy it's switched to functions, all the macros was my #1 reason for being wary of nom :)
whentze
@whentze
the parser is already quite complicated, let's see if i can make a more simple example that has the same behavior
Simon Thornington
@sthornington
do nom functional parsers have to return an impl trait, or can they also return a boxed trait ?
Denis Lisov
@tanriol
They can return anything that implements the trait.
Simon Thornington
@sthornington
what is the non-macro version of switch! ? I'm trying to parse a 'type'-prefixed streaming protocol
Denis Lisov
@tanriol
Parse the first value and then match on the result?
Simon Thornington
@sthornington
Yeah at the moment I’m doing let (input, discriminator) = one_of(“ABC”)(input)?
Then doing a match to a parser I also run on I put. Was just wondering if there was anything else I could do.
Jordan Mack
@jordanmack
Any good sources of additional Nom 5 examples?
I'm brand new to it, and I'm struggling a bit with syntax. More examples beyond the color examples would help.
Jordan Mack
@jordanmack
How would I take all a-z until ":", and error if there is something not a-z before the ":"?
Simon Thornington
@sthornington
Jordan Mack
@jordanmack
Thanks! 👍
Wait a sec, it disappeared.
Simon Thornington
@sthornington
because I am not good at gitter