0
votes

New to XText, I am struggling with two issues with the following MWE grammar.

Metamodel:
    (classes += Type)*
;

Type:
    Enumeration | Class
;


Enumeration:
    'enumeration' name = ValidID '{' (literals += EnumLiteral ';')+ '}'
;
EnumLiteral:
    ValidID
;


Class:
    'class' name = ValidID '{'
        (references += Reference)*
'}'
;

Reference:
    'reference'  name = ValidID ':' type = Class ('#' opposite = [Reference])?
;

So my questions are:

  1. Since the enumeration literals list is ValidID, it seems to be represented by EStrings. The documentation does not seem to deal with the case of primitive types in ECore. How is it possible to check for non-duplicates in literals, and report it adequately in the editor (i.e., the error should be at the first occurence of a repeated literal)?

  2. Despite my best efforts, I was unable to write a custom scope for the opposite reference. Since XText uses reflection for retrieving the scoping methods, I suspect I don't have the correct one: I tried def scope_Reference_opposite(Reference context, EReference r), is it correct? An example would be really appreciated, from which I am confident I can easily adapt to my "real" DSL.

Thanks a lot for the help, you will save me a lot of time looking again and again for a solution in documentation...

1

1 Answers

0
votes
  1. Errors can be attached to a certain index of a many-values feature. Write a validation for the type Enumeration and check the the list of literals for duplicates. Attach the error to the index in the list.
  2. The signature is correct. Did you import the correct 'Reference' or did you use some other class with the same simple name by accident. Also please not that your grammar appears to be wrong for the type of the reference. This should be type=[Class] or more likely type=[Class|ValidID]. If you plan to use or do already use Xbase, things may look different. Xbase doesn't use the reflective scope provider.