Best Practise for autocompletion during syntax errors [message #1844655] |
Mon, 20 September 2021 08:58  |
Eclipse User |
|
|
|
Hi,
in my DSL I implemented Java-like annotations, which can bea appenden to model elements:
"documentation ..."
@MyAnnotation
Entity MyEntity {
// ...
}
"documentation ..."
AnnotationType MyAnnotation {
// ...
}
I would like to implement auto completion for annotation which only shows valid AnnotationTypes. If an AnnotationType is valid or not depends on meta-annotations, which can be added to the respective AnnotationType, and the object-to-annotate. For example:
"documentation ..."
@Target(StringField) // should only be proposed on fields of type String.
AnnotationType MyAnnotation {
// ...
}
My implementation for this works in general. However, when the user just typed the "@" the model is momentarily invalid (as a following ID is expected) and the current model cannot be parsed, which means that I am unable to determine whether the following field is of type String. Consider the following example:
"documentation ..."
@MyAnnotation
Entity MyEntity1 {
@ // <-- syntactically invalid model!
String MyField
}
"documentation ..."
@MyAnnotation
Entity MyEntity2 {
@A // <-- syntactically valid model!
String MyField
}
For MyEntity1, I could not determine if the following field is of type string, for
MyEntity2 I can.
Is there a best practise for this problem?
My Grammar looks like this:
fragment Annotations *:
(annotations+=Annotation)*
;
fragment AnnotationName * hidden():
'@'annotationType=[Annotation | QualifiedName]
;
Annotation:
{Annotation}
AnnotationName
(
'(' (parameters+=Parameter ( ',' parameters+=Parameter)* )? ')'
)?
;
I tried to define the Annotation Type as optional (in the AnnotationName rule), but this leads to an error when generating the DSL, due to ambiguity - I guess some of my annotatable elements start with an ID-rule and not with a keyword. In this case, the name (ID) of the annotated element would be interpreted as the name of the Annotation.
Are there any other solutions for this?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03358 seconds