Error Handling in Grammar kit
Hey,
me again with a problem I don't know how to handle any more...
I defined my Grammar for my custom language, Lua (with extensions). Everything works fine as far as nothing is wrong in the tree.
I have defined a Block Object, which is everything:
Block ::= BlockStatement | BlockLastStatement
private BlockStatement ::= Statements Statements* [LastStatement]
private BlockLastStatement ::= Statements* LastStatement
LastStatement is just a return Statement and a Statement is something like Declarations, Loops and something like that.
My problem so far is in:
FunctionDeclaration ::= [local] function functionName functionBody end
AnonymousFunction ::= [local] function functionBody end
private functionParameter ::= '(' [ParameterList] ')' | '(' ThisIdentifier ')'
private functionBody ::= functionParameter [Block] {pin=1} //this Block argument
private functionName ::= [preFuncName] Identifier
private preFuncName ::= ClassField [simpleVarChain] FunctionCallToken
As far as I understood all the other posts here, the Grammar-Kit HOWTO and tutorial and stuff, I have to pin the opening bracket to cover a broken rule after that, right? In this case that could be my either the function-token, the functionName or the functionParameter. Well, this does not work and I can't wrap my head around how to do that.
I read about this recoverWhile attribute, but the functionality or usefulness is not clear to me yet. when and how it is matched, why it is matched, what should be in that predicated rule and so on. The examples I saw so far weren't explaining enough for me
I didn't post my .bnf-File because it is pretty big and i didn't want to make this post too big :D
Please sign in to leave a comment.
bump.
Someone has any idea what to do?
Error recovery in GK helps in 2 situations:
1. something is missing - use 'pin'
2. something extra is present - use 'recoverWhile'
Just see the generated code, it is pretty straightforward. Start small.
The following sections strive to explain it:
https://github.com/JetBrains/Grammar-Kit/blob/master/README.md#attributes-for-error-recovery-and-reporting
https://github.com/JetBrains/Grammar-Kit/blob/master/HOWTO.md#22-using-recoverwhile-attribute
Thank you!
Here my full .bnf-file: http://pastebin.com/Sp3jgCpE
I tried that already, as you can see, there are some outcommented parts with the pin and recoverwhile-attributes. I got how the pin is working, that is, like you said, pretty straightforward. What I don't get is the functionality of recoverwhile (not from a technical point of view but from a design pov). I don't see, yet, how the recoverwhile is helping me to get where I want to be.
I read the github pages, I also read most of the other threads regarding error recovery, but I still didn't get my solution to work as I want to expect it.
My expactation for example:
CoronaFunctionDeclaration
PsiElement(function)
PsiElement(Name)
PsiElement(()
PsiElement())
CoronaBlock
PsiErrorElement (expected stuff)
PsiElement(end)
Something like that. Right know I have:
PsiElement(function)
PsiElement(Name)
PsiElement(()
PsiElement())
PsiErrorElement (expected stuff)
PsiElement(end)
So, not even Treelike form. pins didn't do it so far. As I understood them, nearly every rule would have to be pinned, right? So, I guess, only the recoverWhile-Attribute is a possibility but without the understanding I need and don't have, that is until now not an option :D So, please, would you mind telling me what to do here with this rule? What is expected to be where? Which rule should be attributed? The Statements, as I understood the posts so far, right? But what kind of rule has to be in the attribute? Something like "!(Name)"?
Sorry for the long post, I hope you get what I am trying to say :D