Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Best Practise for autocompletion during syntax errors
Best Practise for autocompletion during syntax errors [message #1844655] Mon, 20 September 2021 12:58 Go to next message
Konrad Jünemann is currently offline Konrad JünemannFriend
Messages: 93
Registered: December 2018
Member
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?
Re: Best Practise for autocompletion during syntax errors [message #1844783 is a reply to message #1844655] Fri, 24 September 2021 19:43 Go to previous message
Konrad Jünemann is currently offline Konrad JünemannFriend
Messages: 93
Registered: December 2018
Member
I was able to solve this issue. Solution can be found in this thread: https://www.eclipse.org/forums/index.php/t/1109026/
Previous Topic:How to solve this ambiguity problem
Next Topic:Extending XtextBuilder for two DSLs
Goto Forum:
  


Current Time: Fri Apr 19 07:51:48 GMT 2024

Powered by FUDForum. Page generated in 0.01965 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top