Skip to content

Try to lift the dependency on unstable rust #3

@Evelyn-H

Description

@Evelyn-H

I already attempted to try to use proc-macro-hack instead, but it failed to work, likely because of they weird (and honestly, probably bad) construction it builds to allow the user to use the . operator to access the different sub-parsers / non-terminals:

// user code
let parser = grammar! {
    something = ...
    something_else = ...
}

would essentially expand to this:

let parser = {
        struct PEGParser {}
        impl PEGParser {
            fn something<'input>(&self, input: &'input str) -> ... 
                ...
            }
             fn something_else<'input>(&self, input: &'input str) -> ... 
                ...
            }
        }
    PEGParser {}
    }
}

and then it can be used like this:

let result = parser.something("some string");

An alternative way to (hopefully) circumvent the use of the currently unstable #![feature(proc_macro_hygiene)] could be to do something like this instead:

// user code
mod parser {
    grammar! {
        something = ...
        something_else = ...
    }
}

and then expand to this, without the weird struct/impl construction:

mod parser {
    fn something<'input>(&self, input: &'input str) -> ... 
        ...
    }
    fn something_else<'input>(&self, input: &'input str) -> ... 
        ...
    }
}

and the use would be slightly different, but not much:

let result = parser::something("some string");

This should "just work" on stable rust AFAIK, and in the worst case it should definitely work using proc-macro-hack.

(Note: wrapping the grammar! invocation in a mod is simply to avoid namespace pollution, it could technically be left out if the user wants that.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions