Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext Symbol(How extend the concept of Symbol)
Xtext Symbol [message #1746112] Sat, 22 October 2016 02:23 Go to next message
Eclipse UserFriend
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 #1746113 is a reply to message #1746112] Sat, 22 October 2016 02:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi can you please explain what you mean.

In Xtext you have edobjects

Thing: ... someattr=ID ...

And Cross references

ThingReferecigObject: ... ref=[Thing] ...

To be able to reference a thing it needs a attribute named name

name=ID


So please explain your question. From an model perspective
If you can't from a grammar perspective

Or give it a name through IQualifedNameProvide

Re: Xtext Symbol [message #1746158 is a reply to message #1746113] Mon, 24 October 2016 04:32 Go to previous messageGo to next message
Eclipse UserFriend
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 #1751486 is a reply to message #1746158] Tue, 10 January 2017 12:14 Go to previous messageGo to next message
Eclipse UserFriend
For example to do this

grammar fr.infoly.eclipse.xtext.crossreferencescoping.Algo with org.eclipse.xtext.common.Terminals

generate algo "http://www.infoly.fr/eclipse/xtext/crossreferencescoping/Algo"
/*
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: name=ID;
VarRef: ref=[VarName];

Module:
'Module' name=ID '(' ')'
varglocales+=VarDecl*
'Début'
statements+=Statement*
'Fin'
;

Statement: var = VarRef;
*/

// Avec Symbol
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'
;

ModuleRef: {SymbolModuleRef} symbol=[SymbolModule];

Symbol: SymbolModule | SymbolVar ;


Statement: statement=[Symbol];
// or
//Statement: StatementCall | StatementVar;
//StatementCall: cal = ModuleRef;
//StatementVar: var = VarRef;


But it does not work
Re: Xtext Symbol [message #1751493 is a reply to message #1751486] Tue, 10 January 2017 13:39 Go to previous messageGo to next message
Eclipse UserFriend
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)
	}

}
Re: Xtext Symbol [message #1751537 is a reply to message #1746112] Wed, 11 January 2017 05:01 Go to previous message
Eclipse UserFriend
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 '(' ')';
Previous Topic:Keyword Highlighting In A Standalone Application?
Next Topic:Gradle Multi-Language Project (IntelliJ Idea 15, Xtend 2.9 Beta)
Goto Forum:
  


Current Time: Thu May 15 12:59:25 EDT 2025

Powered by FUDForum. Page generated in 0.03413 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top