dalance / nom-recursive

Extension of nom to handle left recursion
Apache License 2.0
16 stars 4 forks source link

Doesn't work for custom input types #12

Open nv0skar opened 1 year ago

nv0skar commented 1 year ago

Left recursion doesn't work when using a custom input type. Specifically, the input of my parser is LocatedSpan<T, RecursiveInfo> where T is a stream of tokens that contains a vector of an enumeration that defines the tokens variants . When first deriving my recursive function with#[recursive_parser] it complained that I didn't have implemented the AsBytes trait, so this is what I came up with:

impl AsBytes for TokenStream {
    fn as_bytes(&self) -> &[u8] {
        unsafe {
            core::slice::from_raw_parts(
                (self as *const TokenStream) as *const u8,
                ::core::mem::size_of::<TokenStream>(),
            )
        }
    }
}

However, the parser is terminating with the SIGSEV signal when trying to parse with left recursion. Maybe a problem with the AsBytes implementation?