Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Denis Lisov
@tanriol
take_while1 will probably be more readable.
Adrien FAURE
@adfaure
Yes, but take_while1 needs &[u8], I could not understand how to work with this function.
Denis Lisov
@tanriol
That's really not obvious from the module path, but it does work for strings too.
Adrien FAURE
@adfaure

By doing:

println!("{:?}", take_while1(is_alphanumeric)("c15a23cd-22d8-4351-b738-396b274599f8"));

I get error:

error[E0271]: type mismatch resolving `<&str as nom::InputTakeAtPosition>::Item == u8`
   --> src/main.rs:207:22
    |
207 |     println!("{:?}", take_while1(is_alphanumeric)("c15a23cd-22d8-4351-b738-396b274599f8"));
    |                      ^^^^^^^^^^^ expected char, found u8

error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.
error: Could not compile `trust`.
Denis Lisov
@tanriol
The one not working with strings here is nom::character::is_alphanumeric, not take_while1
Adrien FAURE
@adfaure
Using alphanumeric1 is even worse
Denis Lisov
@tanriol
Something like take_while1(|c| c.is_alphanumeric() || c == '-') should work
Being more precise, take_while1(|c| c.is_ascii_hexdigit() || c == '-')
Adrien FAURE
@adfaure
\0/ Ok, it works. Thank you. It was simple as I expected...
I could not find it myself.
eignnx
@eignnx
Hi all, is there a way to sequence parsers so that they concatenate the &strs they match? Like tuple but where I get one &str back instead of an n-tuple of &strs?
matrixbot
@matrixbot
bspeice Given that the &strs could be non-contiguous, I don't think that's possible. You could use that tuple to build a new String though.
eignnx
@eignnx
@matrixbot ahh I see :/ that's too bad. Thanks
Denis Lisov
@tanriol
@eignnx Maybe check recognize?
Alberto
@0X1A
Hi folks, does anyone know if nom_methods supports nom 5's non-macro functions? AFAICT from looking at the macros it seems like it doesn't?
Denis Lisov
@tanriol
IIUC, one does not need nom_methods to have nom parsers implemented as methods :-)
Alberto
@0X1A
Oh wow, all this time I was still thinking parser functions had some magic and had to be fn x(input: i) -> IResult!
Good to know
prbs23
@prbs23_gitlab
Hey folks, is there an existing parser for matching a character that is inside a range of values? For example match any character between 'A' and 'Z'
character::streaming::one_of() is close, but it appears you need to enumerate every valid character
eignnx
@eignnx
@tanriol recognize is exactly what I was looking for, thank you!
Alberto
@0X1A
@tanriol So it turns out choice combinators don't quite work with parser methods :\
Denis Lisov
@tanriol
What do you mean - the fact changes are not undone if the branch fails?
Alberto
@0X1A
No, methods can't be passed to alt as it expects functions with only one argument
Denis Lisov
@tanriol
You can pass closures like |input| my_struct.method_parser(input)
Alberto
@0X1A
Gracias :pray:
Geoff Shannon
@RadicalZephyr
hi all, I'm trying to write a combinator that ensures that the first character is alphabetic, but the remainder of the string is alphabetic. Is there a better way than parsing with alphanumeric1 and then checking the first character is alphabetic?
Michael P. Jung
@bikeshedder
@RadicalZephyr You mean something like that?
named!(parse_identifier<CompleteStr, String>, do_parse!(
    first: take_while1!(char::is_alphabetic) >>
    rest: take_while!(char::is_alphanumeric) >>
    (first.0.into() + rest.0)
));
Michael P. Jung
@bikeshedder
I just realized I'm still using nom 4 and CompleteStr is no longer a thing. whops
Gotta try migrating to nom 5. Looks like I'm going to like the changes. Less macro magic.
Denis Lisov
@tanriol
@RadicalZephyr Something like recognize(tuple((alpha1, alphanumeric0)))?
Geoff Shannon
@RadicalZephyr
@tanriol heh, I got too focused on ensuring that only the first character was alphanumeric, but that do exactly what I want! thanks!
Michael P. Jung
@bikeshedder
Is there anywhere a migration guide for nom 4->5. When starting with nom 4 I got confused by the CompleteStr and with nom 5 it seams everything has changed.
Denis Lisov
@tanriol
Something like this?
jtenner
@jtenner
Hey guys. How can I assert the end of input?
    input.len() == 0;
Just want to be idiomatic :)
jtenner
@jtenner
I think I have a fundamental misunderstanding here.
jtenner
@jtenner
I come from a peg background, and I know what to expect in terms of parsing logic.
I'm just having a hard time with the rust api and rust itself.
fn parse_expression(expression: &str) -> IResult<&str, DiceNode, &str> {
    let (input, taken) = space0(expression)?;
It's saying that space0() has a problem
jtenner
@jtenner
I just need to consume some whitespace lol
Geoff Shannon
@RadicalZephyr
@jtenner I think to assert end of input the ‘combinator::complete’ combinator is what you want in addition to whatever combinators actually consume the input
jtenner
@jtenner
Okay!
Can I personally message you? I think I need a human to explain this to me like I'm five.
Geoff Shannon
@RadicalZephyr
Sure
Denis Lisov
@tanriol
Probably not complete, but all_consuming
Alberto
@0X1A
@tanriol Hello again, seems alt kinda breaks when using it with a &mut self
The trait is only for Fn and not FnMut and I'm not sure the borrow checker will like passing around FnMut with mutable self with the way alt works