Grammar-Kit: toy grammar fails with recoverWhile

Answered

I am using Grammar-Kit to create a language plugin. However, I am struggling with Grammar-Kit's poor documentation (in contrast to excellent JFlex) and with possible bugs within Grammar-Kit itself. I managed to have the language parse, but as soon as I try to add error recovery, I am at a total loss. Moreover, additional errors seem to emerge if I do white space handling in the grammar itself.

Basically, I would be satisfied if I could provide a single rule where to restart the grammar and let the parser skip tokens and retry until the number of parseable tokens exceeds a threshold.

Anyway, I think I could condense one of my many problems to the following toy grammar and example. Please help as I cannot see what I am doing wrong:

Toy.bnf:

{
tokens = [
space='regexp:\s+'
id = "regexp:\p{Alpha}\w*"
eq = "="
colon = ":"
brace1 = "{"
brace2 = "}"
]
}
value ::= id | object
object ::= '{' (prop | expr) '}'
prop ::= id ':' value {pin = 2 recoverWhile = recover}
expr ::= id '=' id
private recover ::= !(':' | '=' | '}' | '{')

Toy.bnf.preview:

{a=b}

This expressions parses without the pin/recover rules, but NOT as is posted above (red mark below '=', "id expected, got '='"). The value I use for pin doesn't matter.

I assume the prop rules gets pinned despite there not being any ':'.

Is it a bug or am I doing anything wrong?

Moreover, I regularly get more such problems if I include my own rules for white space. Is there any specification document about what stuff Grammar-Kit supports in {}? The three .md files from the Grammar-Kit source only provide examples, never explain anything.

 

Any help would be highly appreciated.

Thanks, Falk

0
3 comments

Hi,

"prop" rule defines
id ':' value

where value allows both "id" and "object", whereas "object" starts with '{'

Now for "prop" rule, recover rule specifies not to match '{'. So AFAIU this is contradicting the "valid" use case.

0

Hi Yann,

thanks for your appreciated response and sorry for the late reply. I was diverted by another project as grammar-kit slows down our progress ... ;)

Can you explain what you mean by "valid" use case? I cannot find any documentation about use cases :(

Moreover, I change the recover expression to ANYTHING which would render the expression valid. Deleting the '{' | '}' certainly doesn't help. Only completely deleting it makes the preview example valid. And it IS valid by the grammar!

So, my claim is that grammar-kit's pin feature is broken and cannot be used with the grammar above at all. Ou do you see a way out?

Thanks, Falk

0

Please sign in to leave a comment.