|
|
Re: Xtext Symbol [message #1746158 is a reply to message #1746113] |
Mon, 24 October 2016 08:32   |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
There is no built-in notion of a Symbol. In Xtext, rules create instances of a class model when they are processing the text. The example says that the rule Name returns an instance of the class Symbol when it matches. The definition of classes like Symbol are, depending on the model definition in your grammar, either derived from the grammar or imported from an existing Ecore model.
You can build any kind of inheritance hierarchy in the Ecore model, e.g. by defining
Symbol:
SymbolVar | SymbolConst | SymbolData | SymbolModule;
You will make SymbolVar etc. inherit from Symbol, even if you never call the rule explicitly. Common features, e.g. a String attribute called name will be uplifted to the super class.
A cross-reference to a Symbol, as in you Ref rule, can then point to any subclass of Symbol. For the details of the linking and the special meaning of an attribute called name, please read the docs.
Have a look at the Grammar section of Xtext documentation for details on the Ecore model / Xtext relationship.
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
|
Re: Xtext Symbol [message #1751493 is a reply to message #1751486] |
Tue, 10 January 2017 18:39   |
|
Hi, can you please share a test model as well? the following grammar works fine for me
Algo: // Un Algo se compose de :
varglobales+=VarDecls // Déclarations de varaibles globales
modules+=Module*; // De modules
VarDecls: {VarDecls} 'Variable:' variables+=VarDecl*;
VarDecl: name=VarName;
VarName returns SymbolVar: name=ID;
VarRef: {SymbolVarRef} symbol=[SymbolVar];
Module returns SymbolModule:
'Module' name=ID '(' ')'
varglocales+=VarDecl*
'Début'
statements+=Statement*
'Fin'
;
Statement: StatementVar;
StatementVar: var = VarRef;
with this model/test
@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest{
@Inject
ParseHelper<Algo> parseHelper
@Test
def void loadModel() {
val result = parseHelper.parse('''
Variable: a b c
Module m1 ()
m1a m1b m1c
Début
a
m1a
Fin
Module m2 ()
m2a m2b m2c
Début
b
m2b
Fin
''')
Assert.assertNotNull(result)
EcoreUtil2.resolveAll(result)
println(result.eResource.errors)
}
}
Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.02243 seconds