Help me with grammar kit plz

Sorry for my bad english :_|


I wrote a bnf file for learning grammar kit, this file looks like below:



{
    tokens = [
        string = 'regexp:[\d|\w]+'
    ]
}


root ::= expr *
expr ::= id '=' string { pin=1; recoverUntil='recover' }
recover ::= !(id '=' | ';')





I just want that these expressions like "id=yanglin; id=seventh7;" will work well, but it shows me "  id expected, got ';'  ". Anyway, "id=yanglin id=seventh7" works well
 
I can not understand the real notion of pin and recoverUtil
 
Thank you for your help
 
 
 

0
4 comments
Avatar
Permanently deleted user

Hi there,

From what I understand, you should use the Pin/RecoverUntil attributes when you want to carry on parsing a PSI Tree when the input may not generate a valid tree under normal circumstances.
With this taken into consideration, in the grammar you gave, you don't seem to have consume the semicolons you expect from your example language - which is why you do get errors when entering "id=yanglin; id=seventh7;"

For instance, perhaps your grammar should look something like

root = expr ( ';' expr )*
expr ::= id '=' string ';'

0

Thank you
It works with your code

0


{
    tokens = [
        string = 'regexp:\"([^\\\"]|\\.)+\"'
        id = 'regexp:[\d|\w]+'
    ]
}

root ::= expr *
expr ::= id '=' string ';' { pin=2; recoverUntil=recover }
recover ::= !(id '=')



Here's my take. I've added string and id tokens and ';' at the end of expr.
If you'd really like to use string the input should look like:

id="yanglin"; id="seventh7";


I also removed ';' from recover because you want to skip any garbage until the next expr, and set pin=2 because recover predicate and expr prefix should match.
Try this input and you'll see that the last expr is parsed correctly:

id="yanglin"  ; id="seventh7" this garbage will be skipped ; id="correctly parsed"

0

thank you. i think i can understand pin and recoverUntil better now.
thanks again

0

Please sign in to leave a comment.