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
@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
Bruno Bigras
@bbigras
Is it possible to use nom with a BufReader? or maybe on a file directly.
Alberto
@0X1A
@bbigras Sure, just pass the data to a parser function
Alberto
@0X1A
I know it might not be so clear from the documentation but all you have to do is crack open a file, read as str or bytes and pass that str/bytes to nom functions
Bruno Bigras
@bbigras
yeah I already do that. but I was wondering if I could use nom without having to read into a variable first.
especially since I want to read a log file and follow it like tail does.
Alberto
@0X1A
Ah, no. Nom doesn't have any kind of convenience functions like that
Bruno Bigras
@bbigras
I already do it with nom 4 in some project but I was wondering if nom supported the Read trait or that maybe BufReader was usable directly.
Bruno Bigras
@bbigras
In other words, I think I wanted nom to use a BufReader directly and consume it. Right now I use a buffer that I fill and empty if nom can parse a part of it.
David Holroyd
@dholroyd
hi! is there an existing nom5 combinator for character ranges?
would like to express, for example,
Char       ::=       #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]    /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
...and variants on that
I think I could copy'n'paste my own parser based on an example from nom::character::complete::, but maybe I've missed an easier way! :)
jtenner
@jtenner
Seems like the docs could use some work