Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar Problem
Grammar Problem [message #1803745] Fri, 08 March 2019 08:38 Go to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
Hello,

I'm having a problem writing my grammar.
What I'm trying to do is create a grammar that allows me to do this:

import things
from otherThings import potatoes
import bananas
import apples as ap

use :
       filex
       filey

import moreThings
...


But I can't do this. "use" if appear in the document, should appear only once, and I should be able to make "import" in the hole document.

Can you help me?

[Updated on: Fri, 08 March 2019 08:38]

Report message to a moderator

Re: Grammar Problem [message #1803746 is a reply to message #1803745] Fri, 08 March 2019 09:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6458
Registered: July 2009
Senior Member
Hi

You appear to have three regions
pre-amble - import ...
body - use ...
post-amble - import ...

so write a grammar that sequences the three regions with their distinctive content.

(Free form grammars are harder to write and often have poor error diagnostics / completion assist; you will find it much easier if you have distinctive terminators such as ";" and sub-clauses such as "{" ... "}")

Regards

Ed Willink
Re: Grammar Problem [message #1803747 is a reply to message #1803746] Fri, 08 March 2019 09:54 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
Hello,

Thanks for your reply.

I have more than one import region. Instead of Import we can see this like variables. I want to be able to specify in any place of my document "imports" (or variables) without a fix position as you are proposing. Besides that I want to specify "use" only one time in the document, and without a fix position.

[Updated on: Fri, 08 March 2019 10:08]

Report message to a moderator

Re: Grammar Problem [message #1803748 is a reply to message #1803747] Fri, 08 March 2019 09:57 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
isnt that a

Model: (imports+=Import | a+=AThing| b+=BThing)*;



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar Problem [message #1803749 is a reply to message #1803748] Fri, 08 March 2019 10:06 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
Thanks for your reply.

No, because I can only specify "use" in the document once.
Re: Grammar Problem [message #1803750 is a reply to message #1803749] Fri, 08 March 2019 10:08 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
well. a good advice when writing xtext grammars is:

you do NOT have to put everything into the grammar. it is always possible to write semantic validations which will make your live much easier


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar Problem [message #1803751 is a reply to message #1803750] Fri, 08 March 2019 10:13 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
Maybe it will be better to do that. Thanks :D
Re: Grammar Problem [message #1803752 is a reply to message #1803751] Fri, 08 March 2019 10:35 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6458
Registered: July 2009
Senior Member
Hi

Perhaps you should reread/understand my earlier answer. It can have 'use' exactly once as a body, surrounded by preamble/postamble.

Regards

Ed Willink
Previous Topic:Xtext Error Recovery
Next Topic:Template language
Goto Forum:
  


Current Time: Sat Sep 21 06:58:47 GMT 2019

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

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

Back to the top