Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Nick Overdijk
@NickNick
If I want some parse to only work on some token, and I have a parser extracting that token, is it like map_parser(extract_token, parse_token) ?
... bit of a poor wording, I hope it's clear.
super-continent
@super-continent

im new to using nom, and i have an idea of how to solve a problem, but i need some guidance on what actual code i need to write
i have strings that follow this format:

nameOfStart: Arg_or_Nothing, ... Arg

Arg can be a couple different types, either an Int, a named value, or a 32/16-byte string
each notated as

(NAMED_VALUE), 32s'32 STRING', 16s'16 STRING', 423532
real example:
Unknown2213: 32s'entry_default', 32s'', 0
i can figure out how to make it get the function name, but how would i parse these args correctly?
i want to make it return something like a tuple of (function_name, Option<Vec<Arg(val)>>)
Nick Overdijk
@NickNick
@super-continent: I'm new too, so take this with a grain of salt: many_till(alpha1, tag(":")) for the name, right?
or just alpha1 really.
NOt sure what you names can be, but some set of characters not including : I hope ;-)
skip the : with let (i, _) = tag(":")(i)?
then the spaces with let(i, _) = multispace0(i)?;
then the type, make a function for that.
super-continent
@super-continent
name should be alphanumeric actually, but beside that yeah
i was doing named!(get_func_name<&str, &str>, take_until!(":"));
Nick Overdijk
@NickNick
Ah, the macro style. I haven't used that...
for the type parsing, I use something like: https://gist.github.com/rust-play/99c0eb230720455e0c27d805ce9dd27f
super-continent
@super-continent
oh huh i didnt know there was macro and non-macro stuff
Nick Overdijk
@NickNick
of course that doesn't match 32s, 16s.. but you get the idea.
extract the part with nom, then just match.
super-continent
@super-continent
is there a way i do that with variable sizes? like the named value is only delimited with ( and )
but all string sizes are SIZEs
i want to match on the value without taking characters that might be used for the data extraction
Nick Overdijk
@NickNick
I'm not sure what you mean.
What do you want to match?
super-continent
@super-continent
the beginning of the string
like 32s, 16s, (
but the number has nothing conveying that its an int
Nick Overdijk
@NickNick
ah, yes.
super-continent
@super-continent
if i take some values wont it cut off a part of the number?
Nick Overdijk
@NickNick
yes, so you should try and be a bit greedy, trying to find a 32s before finding 'a number'
super-continent
@super-continent
i could search for 32s before the number, but wouldnt that take(3) from the string before it has the ability to process the full number?
Nick Overdijk
@NickNick
If parsers fail, they don't take anything from the input.
super-continent
@super-continent
wouldnt i need to take from the input before matching though? i assumed that would take something regardless
or would i just take the full argument and then match it on the parsers for each argument type until one works
Nick Overdijk
@NickNick
Yes :)
The last bit, exaclty.
At least.. I'm new.
super-continent
@super-continent
thank you for the help! this definitely seems correct
gonna stop using macros also cause theyre a bit confusing, going to try and make it return the right things now
super-continent
@super-continent
is there a way to resolve ``cannot resolve_: nom::error::ParseError<&str>````?
it happened on let (line, _) = tag(":")(line)?;
i need to use the ? operator to unwrap the value or return the error
but when i do that it causes this error
Kubik
@xNxExOx
/// helper trait for the [permutation()] combinator
///
/// this trait is implemented for tuples of up to 21 elements
pub trait Permutation<I, O, E> {
  /// tries to apply all parsers in the tuple in various orders until all of them succeed
  fn permutation(&mut self, input: I) -> IResult<I, O, E>;
}
but I need 54 :( 21 is not enough, what can I do about it?
Denis Lisov
@tanriol
@xNxExOx Do you really want a tuple of 54 elements? :-)
Kubik
@xNxExOx
I want the 54 elements, they does not need to be as tuple, because on next line I construct struct with them
obrazek.png
I adding tables one by one to be sure parsing of each of them works, and the parse_ignored_table is defined in way that it just skips the tables that do not have a parsing method yet
Denis Lisov
@tanriol
How about just implementing that manually?
Kubik
@xNxExOx
I go to permutation, because manual implementation seems quite crazy, by having 54 fields initialized to None, then running for with 54 case match, then checking if all 54 fields are Some(...)
or is there less crazy way to do this?