rustmatic icon indicating copy to clipboard operation
rustmatic copied to clipboard

Identifier which starts with a keyword

Open NOP0 opened this issue 5 years ago • 2 comments

tried to add RETURN as a keyword, but the test parse_a_function fails, since the function in the test is called ReturnFive.

I guess it fails here?

identifier = @{
    !keyword ~ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")*
}

Is there a limitation in the standard that you can't start an identifier with a keyword?

NOP0 avatar Dec 02 '19 11:12 NOP0

Is there a limitation in the standard that you can't start an identifier with a keyword?

I think it's just the way that pattern was written. Instead of using !keyword to make sure an identifier isn't a keyword, it should use some sort of word boundary. I'm not sure how we'd express the equivalent using Pest though.

Michael-F-Bryan avatar Dec 03 '19 03:12 Michael-F-Bryan

I see that if I remove the requirement for not starting with a keyword, that is:

identifier = @{
    ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")*
}

, then I'm allowed to add ^"return" and all tests pass. Are the grammar rules searched from top to bottom in the .pest file? I didn't have time to investigate further now, just wanted to drop you a note.

NOP0 avatar Dec 03 '19 07:12 NOP0