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
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?
Kubik
@xNxExOx
for now I only considering forking the repo, and adding more values to:permutation_trait!(FnA A, FnB B, ..., FnT T, FnU U);
because the Nones for match is_some is too crazy for 54 fields/types
I would really like to know if there is any other option, because it would be third crate I need to modify, which is not good for compatibility, and future updates :(
Denis Lisov
@tanriol
Interesting... this sounds like a good use case for a custom derive, but I don't see a fully functional one.
However, how about two-stage parsing?
You have multiple parse_ignored_table, so I assume you can skip a table even if you don't know its type yet... and you probably have a type code in the table header that lets you identify the specific table.
Denis Lisov
@tanriol
How about the following logic? You parse in a loop 54 "unknown" tables and put them in a HashMap with their type code as the key. Then you start building the structure and only now you get each table by its ID and parse its contents, returning an error if any of the required tables is not found or fails to parse.
By the way, if that's not a secret, what were the previous two crates you had to modify?
Kubik
@xNxExOx
pub struct AbstractCffTable<'a> {
    pub id : u32,
    pub unknown1 : u16,
    pub compressed_size : u32,
    pub unknown2 : u16,
    pub decompressed_size : u32,
    pub data : &'a[u8],
}
all tables looks like this, so I can use id and compressed_size for easy skipping