0

I want to build an Editor for a language with different groups of variable types, but have problems with the generated content assistant.

Type:
   'TYPE' ':' name=ID '(' type=[ANY] ')' ';'
;
ANY:
   ANY_NUM | Type
;
ANY_NUM:
   ANY_REAL | ANY_INT ...
;
ANY_REAL:
   'real' | 'float'
;
ANY_INT:
   'int' | 'sint' | 'lint'
;

The idea is, that specific types are not allowed everywhere, so I want to use type=(ANY_REAL) for example in some cases. The generated content assistant does not show anything here, so I want to know if this is the correct approach to specify variable types and groups.

abs
  • 71
  • 6

1 Answers1

0

OK. The answer is quite simple. Each Variable type has to be defined within an enum (EnumRule), the structure itself is a simple type reference (ParserRule):

TR_Any:
  TR_AnyDerived | TR_AnyElementary
;
TR_AnyDerived:
  ...
;
TR_AnyElementary:
  TR_AnyReal | TR_AnyInt |...
;
TR_AnyReal:
  type = E_AnyReal
;
TR_AnyInt:
  type = E_AnyInt
;
enum E_AnyReal:
  FLOAT = "float" |
  DOUBLE = "double" |
  ...
;
enum E_AnyInt:
  INT = "int"
;

The types can be referenced as described in the xtext documentation:

MyRule:
  anyvar = [TR_Any]
  intvar = [TR_Int]
;
abs
  • 71
  • 6