Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Usage of externally defined symbols in grammar
Usage of externally defined symbols in grammar [message #1815028] Tue, 24 September 2019 12:03 Go to next message
Jozsef Klespitz is currently offline Jozsef KlespitzFriend
Messages: 34
Registered: September 2019
Member
Hello everyone,

I am building a language where I want to use externally defined items.
Let's say these are enumerations, classes and global variables in a different project. I want to collect these items and I want to see them in the grammar editor with syntax highlight and auto-completion (as if they were part of the original grammar).
What is the preferred method to do this?

My current best guess is to add a custom Inferrer with Xbase, but I am uncertain about the details.

Thanks for the suggestions!

[Updated on: Tue, 24 September 2019 12:03]

Report message to a moderator

Re: Usage of externally defined symbols in grammar [message #1815070 is a reply to message #1815028] Wed, 25 September 2019 07:21 Go to previous messageGo to next message
Jozsef Klespitz is currently offline Jozsef KlespitzFriend
Messages: 34
Registered: September 2019
Member
An example, maybe itt will help.
I have an enumeration in my project somewhere else (which is shared with "common" developers):
enum: {
    sparkling_white
    awsome_green
    cool_red
}


And my grammar has the following structure:
Car:
    'Order' type=Type color=Color
Type:
    name=ID
Color:
   enumeration_from_above


I want to have a solution which reads the enumeration from the production code (let's say at the moment of generation of grammar /->Generate Xtext Artifacts.../) and works as if it was defined within the grammar.

Is this possible?

Thank you for your support.
Re: Usage of externally defined symbols in grammar [message #1815140 is a reply to message #1815070] Thu, 26 September 2019 03:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
The question is: why not encode these in library.mydel files and put them on the class path of the model projects

And then use cross references in the grammar

But in your example you talk about changing the grammar
So I am not sure if we talk about the same thing


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 26 September 2019 03:34]

Report message to a moderator

Re: Usage of externally defined symbols in grammar [message #1815162 is a reply to message #1815140] Thu, 26 September 2019 12:08 Go to previous messageGo to next message
Jozsef Klespitz is currently offline Jozsef KlespitzFriend
Messages: 34
Registered: September 2019
Member
Dear Christian,

thank you for the feedback.
It would be possible to encode these in .mydel files, but it would mean "hard wiring" the names.
The content of enumerations (and number of classes, etc.) is dynamically changing (currently) in the project. It would be cumbersome to follow the modifications by hand in the .mydel files.
That is why I want to collect these information somehow and embed it into the grammar.

I hope my answer gives some more insight.
Re: Usage of externally defined symbols in grammar [message #1815164 is a reply to message #1815162] Thu, 26 September 2019 12:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
no, i mean: ship the libary in a jar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Usage of externally defined symbols in grammar [message #1815166 is a reply to message #1815164] Thu, 26 September 2019 12:22 Go to previous messageGo to next message
Jozsef Klespitz is currently offline Jozsef KlespitzFriend
Messages: 34
Registered: September 2019
Member
Could you please clarify what do you mean under "ship the library in a jar"?
Re: Usage of externally defined symbols in grammar [message #1815167 is a reply to message #1815166] Thu, 26 September 2019 12:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
you introduce a concept color declaration (somewhere in your or as separate dsl)

Model:
colorDecls+=ColorDeclaration+;
ColorDeclaration: "Color" name=ID

then you refer to that decl in your place

Color:
value=[ColorDeclaration|ID];

the you create a colors.mydsl
Color red
Color green
Color blue
and package that to a jar.

this jar you put on the classpath of the model project


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Usage of externally defined symbols in grammar [message #1815168 is a reply to message #1815167] Thu, 26 September 2019 12:38 Go to previous messageGo to next message
Jozsef Klespitz is currently offline Jozsef KlespitzFriend
Messages: 34
Registered: September 2019
Member
Thank you very much, I will give it a try!
Re: Usage of externally defined symbols in grammar [message #1817161 is a reply to message #1815168] Sun, 17 November 2019 04:18 Go to previous messageGo to next message
Parvesh Jain is currently offline Parvesh JainFriend
Messages: 1
Registered: November 2019
Junior Member
Hi Jozsef

Are you able to make the solution work. I wish to achieve the same and struggling for approach.
If it worked with you, please share your approach.

King Regards
Parvesh
Re: Usage of externally defined symbols in grammar [message #1817447 is a reply to message #1817161] Fri, 22 November 2019 10:00 Go to previous message
Jozsef Klespitz is currently offline Jozsef KlespitzFriend
Messages: 34
Registered: September 2019
Member
Hello Parvesh,

the final solution was not exactly what I've asked here.
There is a saying to implement the grammar and only the grammar in xtext file. Every other functionality can be later added on.
In my case I have created the initial grammar description and I have used the external dependencies in validations, quick-fixes and other additional features.

Hope this helps you too.
Previous Topic:Unable to Install Xtext
Next Topic:Programmatically Generate DSL Files - Head Spinning
Goto Forum:
  


Current Time: Wed Sep 18 23:29:35 GMT 2024

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

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

Back to the top