gll icon indicating copy to clipboard operation
gll copied to clipboard

Basic proc-macro identifier vs keyword disambiguation.

Open eddyb opened this issue 5 years ago • 1 comments

If the built-in proc-macro IDENT rule is computed after regular rules are added, it could depend on a user-defined rule, let's say KEYWORD, such that:

KEYWORD = "be" | "in" | "lambda" | "let";

would result in IDENT matching any proc-macro identifier except let and lambda.

That would make this grammar less ambiguous (e.g. for (lambda x x) y or let x be y in (x x)):

Expr
    = Var:IDENT
    | Paren:{"(" inner:Expr ")"}
    | Lambda:{"lambda" var:IDENT body:Expr}
    | LetIn:{"let" var:IDENT "be" init:Expr "in" body:Expr}
    | Call:{callee:Expr arg:Expr}
    ;

To recover the old behavior, one could add a IdentOrKw = IDENT | KEYWORD; rule.

While implementing this efficiently would be difficult at this time, proc-macro support isn't exactly fast either, as it has to work with a limited API.

eddyb avatar Mar 21 '20 08:03 eddyb

One way to prototype this would be to add an argument to the proc_macro::builtin grammar, and have it generate the requisite rules - including an IDENT_OR_KEYWORD with the same (cheap) implementation as today.

EDIT: in the interest of testing, I should just do the full thing, and I can still expose IDENT_OR_KEYWORD.

eddyb avatar Mar 28 '20 14:03 eddyb