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

Contextual keywords with custom lexer #112

Closed
jnicklas opened this issue May 3, 2016 · 4 comments
Closed

Contextual keywords with custom lexer #112

jnicklas opened this issue May 3, 2016 · 4 comments

Comments

@jnicklas
Copy link

jnicklas commented May 3, 2016

I'm trying to write a parser for GraphQL with LALRPOP. Since GraphQL has some rather odd lexing rules I have to use a custom lexer. Unfortunately, GraphQL also uses contextual keywords a lot. I haven't been able to figure out how to get both a custom lexer and contextual keywords working with LALRPOP.

One thing I can do to work around this is define a rule which maps all keywords to their respective string, kind of like this:

Identifier: &'input str = {
    "schema" => { "schema" },
    "query" => { "query" },
    "mutation" => { "mutation" },
    "type" => { "type" },
    "implements" => { "Implements" },
    "on" => { "on" },
    <value:"identifier"> => { value },
};

But this is very tedious, and it feels like there must be a better way.

@jnicklas
Copy link
Author

jnicklas commented May 3, 2016

The ideal would be to get the behaviour of the default lexer, where I can just use literals inline and not have to lex them separately at all.

@nikomatsakis
Copy link
Collaborator

@jnicklas the workaround you listed is what I have done when modeling contextual keywords, but it might indeed be nice to have this more as a "builtin" feature. Contextual keywords don't mesh well with the "lexer-parser" divide that LALRPOP is based on. :(

@nikomatsakis
Copy link
Collaborator

I guess I could imagine some sort of option that makes a "pseudo-terminal" identifier that is equal to a given set of other terminals. e.g. if you could say "let identifier by all terminals that match r[a-zA-Z]+" or something.

@nikomatsakis
Copy link
Collaborator

Closing in favor of #195

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

2 participants