[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.tmf] Re: How to return a list of objects?

Hi Michael,

it is currently not possible to return a list of objects from a parser rule. You'll have to copy the annotation snippet to every location.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Michael Scharf schrieb:
Hi,

I have a grammar that is a bit like EcoreDsl or emfatic. This language
has annotations, but the syntax is slightly different:

Instead of putting the annotation before the element like in emfatic and EcoreDsl:

  @Annotation1 @Annotation2 attr int foo;

it comes after the element with a colon as a comma separated list:

  int foo: Annotation1, Annotation2;

For EcoreDsl and emfatic the rules are easy because there is no
spparator between them [1]. BUT for my language, I have  to inline a
complicated rule because of the separator:

MyAttributeDecl returns ecore::EAttribute:
.... (':' eAnnotations+=MyAnnotationDecl (',' eAnnotations+=MyAnnotationDecl)*)? ...


I have many elements wit annotation and I have to repeat myeself. I'd like to
create a annotations rule like:


   MyAnnotations:
    ':' annotations+=MyAnnotationDecl (',' annotations+=MyAnnotationDecl)*;

and use it like:

  MyAttributeDecl returns ecore::EAttribute:
    .... (eAnnotations = /*THIS DOES NOT WORK*/ MyAnnotations)? ...

I could not find a way to set get the annotations list form the
Annotations rule and pass it into the eAnnotations of EAttribute...

Michael
--------------------------------------------------------------------------------



[1] the rules for EcoreDsl:

  EAnnotationDecl returns ecore::EAnnotation:
    "@" source=STRING_OR_QID;

and the annotations can easyly be added to the EAttribute

  EAttributeDecl returns ecore::EAttribute:
    (eAnnotations+=EAnnotationDecl)*
    'attr' ...;

the annotation rule looks like:

  AnnotationDecl returns ecore::EAnnotation:
    source=STRING_OR_QID ...;