AzureMarker / intellij-lalrpop

Jetbrains plugin for the LALRPOP parser-generator
MIT License
16 stars 2 forks source link

Cannot correctly parse an enum of an extern lexer. #4

Closed dnbln closed 4 years ago

dnbln commented 4 years ago

I have some code that looks like this:

extern {
    enum lexer::Tok {
        "+=" => lexer::Tok::AddEq(<TokLoc>),
        "-=" => lexer::Tok::SubEq(<TokLoc>),
        "*=" => lexer::Tok::MulEq(<TokLoc>),
        "/=" => lexer::Tok::DivEq(<TokLoc>),
        "%=" => lexer::Tok::ModEq(<TokLoc>),
        "=" => lexer::Tok::Eq(<TokLoc>),
        // and so on
    }
}

The error that I get is at the lexer::Tok::AddEq(<TokLoc>) saying LALRPOP.COMMA or LALRPOP.RBRACE expected, got 'lexer::Tok::AddEq(<T...'

AzureMarker commented 4 years ago

Turns out when I was converting the lalrpop grammar to Grammar-Kit, I didn't properly account for this section of the grammar. This is related to #2, because lalrpop invokes a second parser in the first parser, to parse a "pattern":

https://github.com/lalrpop/lalrpop/blob/723678f364790b41d66e747d4eb982897c0edce9/lalrpop/src/parser/lrgrammar.lalrpop#L345-L351

It looks like this "pattern" is just a subset of Rust grammar, so we can probably inject Rust here like we do for the action code, and just replace the odd <Type> notation with whatever it's supposed to be.

AzureMarker commented 4 years ago

Parsing now completes successfully as of https://github.com/Mcat12/intellij-lalrpop/commit/7095024cd6a1ed1280bd4c8667e175dd0f5e1b45.