Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to lift the dependency on unstable rust #3

Open
Evelyn-H opened this issue May 5, 2019 · 0 comments
Open

Try to lift the dependency on unstable rust #3

Evelyn-H opened this issue May 5, 2019 · 0 comments

Comments

@Evelyn-H
Copy link
Collaborator

Evelyn-H commented May 5, 2019

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant