Xtext Symbol [message #1746112] |
Sat, 22 October 2016 02:23  |
Eclipse User |
|
|
|
Eclipse Xtext concept symbol
Is there documentation on the notion of symbol?
That is to say where I found this:
Name returns Symbol:
ValidID
;
Ref:
{SymbolRef} symbol=[Symbol]
;
how is he using?
Is it possible to extend this to:
SymbolVar
SymbolConst
SymbolData
SymbolModule
...
besides Symbol so as to select the symbols used.
|
|
|
|
Re: Xtext Symbol [message #1746158 is a reply to message #1746113] |
Mon, 24 October 2016 04:32   |
Eclipse User |
|
|
|
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.
|
|
|
|
|
Re: Xtext Symbol [message #1751537 is a reply to message #1746112] |
Wed, 11 January 2017 05:01  |
Eclipse User |
|
|
|
I do not understand everything works fine now?
Even this with the module calls in addition:
Variable:
gvar1 // Déclaration var globale 1
gvar2 // Déclaration var globale 2
// Module 1
Module mod1( )
Variable:
lvar11 // Déclaration dans module 1 var locale 1
lvar12 // Déclaration dans module 1 var locale 2
Début
mod2()
gvar1 // Référence à la var globale 1
gvar2 // Référence à la var globale 2
lvar11 // Référence à la var locale 1 du module 1
lvar12 // Référence à la var locale 2 du module 1
Fin
Thank you very much for your help
Yves
// Module 2
Module mod2( )
Variable:
lvar21 // Déclaration dans module 2 var locale 1
lvar22 // Déclaration dans module 2 var locale 2
Début
gvar1 // Référence à la var globale 1
gvar2 // Référence à la var globale 2
lvar21 // Référence à la var locale 1 du module 2
lvar22 // Référence à la var locale 2 du module 2
mod1( )
Fin
With this grammar :
grammar fr.infoly.eclipse.xtext.crossreferencescoping.Algo with org.eclipse.xtext.common.Terminals
generate algo "http://www.infoly.fr/eclipse/xtext/crossreferencescoping/Algo"
/*
* ALGORITHME
*/
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=VarDecls
'Début'
statements+=Statement*
'Fin'
;
ModuleRef: ref=[SymbolModule];
Statement: StatementVar | StatementCall;
StatementVar: var = VarRef;
StatementCall: call = ModuleRef '(' ')';
|
|
|
Powered by
FUDForum. Page generated in 0.03413 seconds