Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Need help getting started on a grammar (again) (SOLVED)
Need help getting started on a grammar (again) (SOLVED) [message #1380003] Sun, 25 May 2014 00:14 Go to next message
Jordan Wallet is currently offline Jordan WalletFriend
Messages: 16
Registered: December 2013
Junior Member
Some of you may remember me from earlier this year in that I was completely unable to get Xtext working at all and managed to waste quite a fair bit of people's time in the process. The thread ended with a resolution to buy Lorenzo Bettini's book, Implementing Domain-Specific Languages with Xtext and Xtend.

I finally had a chance this weekend to crack open the book and follow along, and I'm running into a problem. I learned from my last shot at this that trying to fix it myself without some expert advice isn't going to get me anywhere.

Here's my grammar resulting from following the book through about halfway down page 38:
grammar org.example.entities.Entities with org.eclipse.xtext.common.Terminals

generate entities "http://www.example.org/entities/Entities"

Model:
	entities += Entity*;
	
Entity:
	'entity' name = ID ('extends' superType=[Entity])? '{'
		attributes += Attribute*
	'}'
;

Attribute:
		type=[Entity] array?=('[' ']')? name=ID ';'
;


The grammar was previously working; since, the only modification was to change '[]' to '[' ']' to allow arbitrary whitespace between the square brackets.

I get a syntax error under ']' claiming: extraneous input "]" expecting ')'

I've dug around the web a little and found examples of this sort of putting two string literals right next to each other, so I suspect it's not so much an issue with the grammar as a problem with my setup. Any ideas on how to proceed would be greatly appreciated.

[Updated on: Sun, 25 May 2014 00:16]

Report message to a moderator

Re: Need help getting started on a grammar (again) (SOLVED) [message #1380012 is a reply to message #1380003] Sun, 25 May 2014 00:19 Go to previous messageGo to next message
Jordan Wallet is currently offline Jordan WalletFriend
Messages: 16
Registered: December 2013
Junior Member
The error was in that not only should array's value be optional, but the entire field (feature?).

Copying from a paper reference is surprisingly difficult when you don't know what you're doing!
Re: Need help getting started on a grammar (again) (SOLVED) [message #1381425 is a reply to message #1380012] Sun, 25 May 2014 14:52 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I don't know enough about it to offer you a specific answer. My suggestion would be to separate mandatory features from nice-to-haves (such as allowing arbitrary whitespace). Get the thing working first so at least you can get something done. Then later you can try to add convenience options.

I struggled for about a month getting two DSLs working. Didn't have the slightest idea what I was doing especially at first. I wasn't spoonfed any answers here for sure, but got enough hints and persevered.
Re: Need help getting started on a grammar (again) [message #1383799 is a reply to message #1380003] Mon, 26 May 2014 14:47 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 25/05/2014 02:14, Jordan Wallet wrote:
> Some of you may remember me from earlier this year in that I was
> completely unable to get Xtext working at all and managed to waste quite
> a fair bit of people's time in the process. The thread ended with a
> resolution to buy Lorenzo Bettini's book, Implementing Domain-Specific
> Languages with Xtext and Xtend.
>
> I finally had a chance this weekend to crack open the book and follow
> along, and I'm running into a problem. I learned from my last shot at
> this that trying to fix it myself without some expert advice isn't going
> to get me anywhere.
>
> Here's my grammar resulting from following the book through about
> halfway down page 38:
> grammar org.example.entities.Entities with
> org.eclipse.xtext.common.Terminals
>
> generate entities "http://www.example.org/entities/Entities"
>
> Model:
> entities += Entity*;
>
> Entity:
> 'entity' name = ID ('extends' superType=[Entity])? '{'
> attributes += Attribute*
> '}'
> ;
>
> Attribute:
> type=[Entity] array?=('[' ']')? name=ID ';'
> ;
>
>

On page 38 the modified rule is

Attribute: type=[Entity] (array?='[' ']')? name=ID ';';


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Deploy xtext plugin and install the correct version of xtext automatically in the client
Next Topic:Extending a DSL with Plugins
Goto Forum:
  


Current Time: Fri Apr 19 02:48:46 GMT 2024

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

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

Back to the top