Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Where do I define new grammar?
Where do I define new grammar? [message #638566] Thu, 11 November 2010 16:10 Go to next message
Chris Ainsley is currently offline Chris AinsleyFriend
Messages: 78
Registered: March 2010
Location: UK
Member
Hi,

Assuming I have just a single .xtext file (derived from one of the tutorial DSLs), how and where do I declare new terminators for my language.

If I declare terminators in another xtext file (adapted from the standard terminators), it is not reachable from my original xtext file. How does xtext resolve grammars.

I read in the user guide that I can declare other grammars but can someone give me a quick guide if I should declare the grammar in the same xtext file, in a separate xtext file, and if in a separate file - how do I make this grammar 'visible'?

Thanks,

Chris
Re: Where do I define new grammar? [message #638579 is a reply to message #638566] Thu, 11 November 2010 16:48 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Either I don't understand your question or(non-exclusive) you don't understand what Xtext is about, I guess. It's perfectly possible to define an entire grammar in one .xtext file: the referencing is primarily there for modularization of the grammar, but it doesn't have effect on the language defined by the grammar.

What do you mean with "terminators"? Maybe you mean terminals, but for the most part you don't have to bother with defining these in Xtext: the keywords and the in-built terminals cover >90% of all situations.


Re: Where do I define new grammar? [message #638587 is a reply to message #638579] Thu, 11 November 2010 17:10 Go to previous messageGo to next message
Chris Ainsley is currently offline Chris AinsleyFriend
Messages: 78
Registered: March 2010
Location: UK
Member
Meinte Boersma wrote on Fri, 12 November 2010 01:48
Either I don't understand your question or(non-exclusive) you don't understand what Xtext is about, I guess. It's perfectly possible to define an entire grammar in one .xtext file: the referencing is primarily there for modularization of the grammar, but it doesn't have effect on the language defined by the grammar.

What do you mean with "terminators"? Maybe you mean terminals, but for the most part you don't have to bother with defining these in Xtext: the keywords and the in-built terminals cover >90% of all situations.


Hi,

I think I do mean 'terminals' and still learning xtext although I'm making a lot of progress today.

I think I may need to define new terminals because of the following language format

* Description of something to do = id : drivername


I wish to capture all the text between the asterisk and the '=' sign.

My grammar is currently defined as:

Item:
    '*' description=STRING '=' id=ID ':' driver=STRING ';';


However, this requires quotes around the string. If I define a new terminal then the mwe2 file does not compile correctly (my mistake obviously).

Can you suggest the best way I might be able to capture all the text between two tokens?

Thanks,

Chris
Re: Where do I define new grammar? [message #638866 is a reply to message #638587] Fri, 12 November 2010 20:00 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

try something like

Item: '*' description=Description '=' id=ID ':' driver=STRING ';';

Description hidden(): (ID|WS)+;

Description is a datatype rule. It is better to use those (if possible) rather than defining new terminals as there may be unintended side effects (in particular if you don't really know what you are doing). You may have to implement a value converter in order to deal with leading and trailing white spaces.

Alex
Re: Where do I define new grammar? [message #639363 is a reply to message #638566] Tue, 16 November 2010 09:14 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Am 11.11.10 17:10, schrieb Chris Ainsley:
> Hi,
>
> Assuming I have just a single .xtext file (derived from one of the
> tutorial DSLs), how and where do I declare new terminators for my language.
>
> If I declare terminators in another xtext file (adapted from the
> standard terminators), it is not reachable from my original xtext file.
> How does xtext resolve grammars.

Xtext searches grammars along the classpath. Make sure your grammars
reside in source folders and the Java dependencies are set up correctly.

>
> I read in the user guide that I can declare other grammars but can
> someone give me a quick guide if I should declare the grammar in the
> same xtext file, in a separate xtext file, and if in a separate file -
> how do I make this grammar 'visible'?
>
> Thanks,
>
> Chris


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Problems in UI tests
Next Topic:ResourceDescriptions in Validator
Goto Forum:
  


Current Time: Thu Apr 25 14:17:51 GMT 2024

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

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

Back to the top