Custom Language Support - error element ruins structure
Hi, I'm trying to implement support for a pretty easy language. My grammar is the following:
{
parserClass="ge.freeuni.jack.language.parser.JackParser"
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
psiClassPrefix="Jack"
psiImplClassSuffix="Impl"
psiPackage="ge.freeuni.jack.language.psi"
psiImplPackage="ge.freeuni.jack.language.psi.impl"
elementTypeHolderClass="ge.freeuni.jack.language.psi.JackTypes"
elementTypeClass="ge.freeuni.jack.language.psi.JackElementType"
tokenTypeClass="ge.freeuni.jack.language.psi.JackTokenType"
tokens=[
SEMICOLON = ";"
]
}
File ::= Class
Class ::= Property *
private Property ::= (static | field) (int | char | boolean) identifier SEMICOLON {
pin=1
recoverWhile=PropertyRecovery
}
private PropertyRecovery ::= !(static | field | int | char | boolean | identifier | SEMICOLON)
My current problem is that I can't seem to tame error elements, they ruin program structure and I feel like it will be a problem in the future, when I try to implement more complex grammar with completion.
So maybe I am just doing something wrong an someone could put me in the right direction. All I want to achieve is this:
When I start typing a new property, I just want it to be a new PsiErrorElement under the JackClassImpl root and not destroy the structure of other properties. I.E:
File:
|---Class:
|--- |--- // I want to start typing here a new static property,
|--- |--- // but while I am tryping s..t..a... the structure flattens (described below)
|--- |--- Property:
|--- |--- |--- field int bar;
|--- |---
|--- |--- Property:
|--- |--- |--- static char foo;
File:
|---
|--- PsiErrorElement: sta....
|---
|--- PsiElement(JackTokenType.field)
|--- PsiElement(JackTokenType.int)
|--- PsiElement(JackTokenType.identifier)
|--- PsiElement(JackTokenType.SEMICOLON)
|---
|--- PsiElement(JackTokenType.static)
|--- PsiElement(JackTokenType.char)
|--- PsiElement(JackTokenType.identifier)
|--- PsiElement(JackTokenType.SEMICOLON)
I even thought adding a dummy identifier element so it doesn't ruin the structure but couldn't make it an error element, and I thought it was generally a bad idea.
So is there some easy solution, or maybe I have to create some utilities, neither that is a problem, I just really want to achieve this behavior.
请先登录再写评论。
Anybody? Please?