Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText for existing language
XText for existing language [message #1021789] Wed, 20 March 2013 17:21 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 543
Registered: November 2009
Senior Member
Hello,

We have internal language that has its own syntax and leverages support for other languages such as XPath. Currently we have editor that supports code completion, but it works purely on what language API returns. I wanted to try to re-implement this editor using XText, but I am not sure if what I have is enough to describe the grammar. Language is huge, and I don't know if I can just start creating grammar describing the language, or can I? Has anybody done something like this?

Thanks,
Alex
Re: XText for existing language [message #1021941 is a reply to message #1021789] Thu, 21 March 2013 00:28 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
There's no reason not to give it a shot. Defining the grammar is relatively easy once you get going.

I gather that there are a few idiosyncrasies to deal with when things get more complex than what I deal with, but from where I'm standing the basics of defining syntax highlighting is pretty straightforward.

I've seen the recommendation a few times to avoid trying to handle everything with grammar and it makes sense. The grammar defines your tokenizer and basic model description.

My advice is spend three days learning, googling, and trying it out. If you're happy with your progress, keep moving forward. If not, there are alternatives.

I hadn't used the term AST since college and was completely ignorant of EMF, but in the last two weeks I've managed to come up with something that I'm very impressed with so far. There were easier roads to go down, but the end results from XText are very open to further customization and opened up my eyes to a lot of possibilities.

Re: XText for existing language [message #1021969 is a reply to message #1021941] Thu, 21 March 2013 02:29 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-21-03 1:28, Steve Kallestad wrote:
> There's no reason not to give it a shot. Defining the grammar is
> relatively easy once you get going.
> I gather that there are a few idiosyncrasies to deal with when things
> get more complex than what I deal with, but from where I'm standing the
> basics of defining syntax highlighting is pretty straightforward.
>
> I've seen the recommendation a few times to avoid trying to handle
> everything with grammar and it makes sense. The grammar defines your
> tokenizer and basic model description.
> My advice is spend three days learning, googling, and trying it out. If
> you're happy with your progress, keep moving forward. If not, there are
> alternatives.
> I hadn't used the term AST since college and was completely ignorant of
> EMF, but in the last two weeks I've managed to come up with something
> that I'm very impressed with so far. There were easier roads to go
> down, but the end results from XText are very open to further
> customization and opened up my eyes to a lot of possibilities.
>
>

Start with the terminals of your language.
Write the smallest possible grammar to test your terminals.
Try to stick with just the terminals defined by Xtext standard - have
very good reasons to not use them. (This to avoid creating overlapping
terminals, as well as not benefiting from pre-configured support from Xtext.

Continue in small steps. A one rule at a time, or a very small set.
This prevents you from getting hundreds of lines of errors/warnings and
gobbledygook as a result. When you proceed in a stepwise fashion you
know which construct caused things to blow up.

Let Xtext generate the model for you until you are satisfied with your
grammar - at that point switch to an external model (to prevent
accidental generation of an unsatisfactory model.

Read through the Xtext documentation, familiarize yourself with the
concepts.
If you do not already know EMF - read up on that too.
Read the Google Guice documentation.

Have fun.

Regards
- henrik
Re: XText for existing language [message #1022295 is a reply to message #1021969] Thu, 21 March 2013 16:10 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 543
Registered: November 2009
Senior Member
Thanks guys, this is helpful.
Re: XText for existing language [message #1022346 is a reply to message #1021969] Thu, 21 March 2013 17:59 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6566
Registered: July 2009
Senior Member
Hi

Henrik's steps are very sensible.

However you might do well to start with some tutorials to avoid being
biased by 'the old way'.

Xtext is very powerful and you should work with it rather than against
it. As with any powerful
tool you will find that revisiting your early attempts once you have
gained experuence is a bit
embarassing. Expect to make early mistakes.

I migrated OCL from an LALR LPG grammar to Xtext quite quickly, but my
first 'finished' attempt
was about ten times slower because I forced Xtext to work in an
LALR-fashion that wsan't appropriate
When I revisited my approach to work in an LL with EBNF way, the speed
difference fell to two-fold
which is getting close to my instrumentation uncertainties.

Xtext's ability to resolve proxies in the grammar is incredibly powerful
and you need to learn to
use it to advantage. The way you do things at the moment is almost
certainly inferior by
comparison and will benefit from changing.

Regards

Ed Willink




On 21/03/2013 02:29, Henrik Lindberg wrote:
> On 2013-21-03 1:28, Steve Kallestad wrote:
>> There's no reason not to give it a shot. Defining the grammar is
>> relatively easy once you get going.
>> I gather that there are a few idiosyncrasies to deal with when things
>> get more complex than what I deal with, but from where I'm standing the
>> basics of defining syntax highlighting is pretty straightforward.
>>
>> I've seen the recommendation a few times to avoid trying to handle
>> everything with grammar and it makes sense. The grammar defines your
>> tokenizer and basic model description.
>> My advice is spend three days learning, googling, and trying it out. If
>> you're happy with your progress, keep moving forward. If not, there are
>> alternatives.
>> I hadn't used the term AST since college and was completely ignorant of
>> EMF, but in the last two weeks I've managed to come up with something
>> that I'm very impressed with so far. There were easier roads to go
>> down, but the end results from XText are very open to further
>> customization and opened up my eyes to a lot of possibilities.
>>
>>
>
> Start with the terminals of your language.
> Write the smallest possible grammar to test your terminals.
> Try to stick with just the terminals defined by Xtext standard - have
> very good reasons to not use them. (This to avoid creating overlapping
> terminals, as well as not benefiting from pre-configured support from
> Xtext.
>
> Continue in small steps. A one rule at a time, or a very small set.
> This prevents you from getting hundreds of lines of errors/warnings
> and gobbledygook as a result. When you proceed in a stepwise fashion
> you know which construct caused things to blow up.
>
> Let Xtext generate the model for you until you are satisfied with your
> grammar - at that point switch to an external model (to prevent
> accidental generation of an unsatisfactory model.
>
> Read through the Xtext documentation, familiarize yourself with the
> concepts.
> If you do not already know EMF - read up on that too.
> Read the Google Guice documentation.
>
> Have fun.
>
> Regards
> - henrik
>
>
Previous Topic:How can a new character be added to xtext edito?
Next Topic:Check Type of Element
Goto Forum:
  


Current Time: Mon Jan 20 14:50:46 GMT 2020

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

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

Back to the top