NOP0 / rustmatic

PLC programming in Rust!
Apache License 2.0
35 stars 2 forks source link

Identifier which starts with a keyword #16

Open NOP0 opened 4 years ago

NOP0 commented 4 years ago

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?

Michael-F-Bryan commented 4 years ago

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.

NOP0 commented 4 years ago

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.