Cross referencing pre-defined "terminals" [message #1758809] |
Mon, 03 April 2017 08:28  |
Eclipse User |
|
|
|
Hi all.
I'm working on a DSL and have come across a problem.
I want to have syntax that goes off of this:
namespace fully.qualified.name
public class Test parent SuperClass inherits ImplementType {
int i;
Test j;
fully.qualified.name.Test k;
}
The class portion works fine, except when I define a variable, the bottom two work fine, except int will fail.
Below is my DSL so far:
Model:
package=PackageDeclaration
imports+=(ImportDeclaration)*
types+=Type*
;
PackageDeclaration:
'namespace' name=FQN
;
ImportDeclaration:
'use' name=FQN
;
FQN: ID ('.' ID)*;
TypeType:
Primitive | FQN
;
Primitive:
'int' |
'float'
;
Type:
ClassType | EnumType
;
Field:
VariableDefinition | JavaStatement
;
ClassType:
modifiers+=Modifier* 'class' name=ID
('parent' superType=[Type | FQN])?
('inherits' implementations+=[Type | FQN]*)?
LBRACE fields+=Field* RBRACE
;
EnumType:
modifiers+=Modifier* 'enum' name=ID LBRACE values+=ID* RBRACE
;
VariableDefinition:
modifiers+=Modifier* type=[Type | TypeType] name=ID
;
JavaStatement:
'java' statement=STRING
;
Modifier:
'public' |
'static'
;
terminal LBRACE: '{';
terminal RBRACE: '}';
The important part is where the variable rule makes cross-reference to either a Type, a Fully Qualified Name, or a primitive that doesn't need previous defining.
This however fails, and I have no idea how to solve it. So my question is, how can I make cross-reference to types, fully qualified names AND primitives without defining them initially, in Xtext?
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04614 seconds