Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » package without brackets(package rule)
package without brackets [message #765961] Thu, 15 December 2011 01:42 Go to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Hi,
we all know these rules from the demo

AbstractElement:
PackageDeclaration|Entity|Type;

PackageDeclaration:
'package' name=QualifiedName '{'
(elements+=AbstractElement)*
'}'
my question: this containment mechanism works fine but when i remove the brackets '{' '}' around packagedeclaration rule, i get warnings "Decision can be made by different alternatives.." and still the containment works well??
is there a way to overcome this? because in my DSL the package is called module(moduleName) and then contents without brackets.


Thanks a lot,
mokhtar

Re: package without brackets [message #765972 is a reply to message #765961] Thu, 15 December 2011 02:19 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
As a PackageDeclaration is an AbstractElement you may (using braces) state:

package a { package b {} }
package a { package b {} package c {} }

package a {} package b {} package c {}

Without the braces it is impossible to tell them apart.

package a package b package c

The generator is telling you that it picked one of the interpretations
(assign one more element to elements or go up a level).

Hope that helps you.
- henrik

On 2011-15-12 2:42, Xtexter wrote:
> Hi,
> we all know these rules from the demo
>
> AbstractElement: PackageDeclaration|Entity|Type;
>
> PackageDeclaration:
> 'package' name=QualifiedName '{'
> (elements+=AbstractElement)*
> '}'
> my question: this containment mechanism works fine but when i remove the
> brackets '{' '}' around packagedeclaration rule, i get warnings
> "Decision can be made by different alternatives.." and still the
> containment works well??
> is there a way to overcome this? because in my DSL the package is called
> module(moduleName) and then contents without brackets.
>
>
> Thanks a lot,
> mokhtar
>
Re: package without brackets [message #766178 is a reply to message #765972] Thu, 15 December 2011 10:22 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
And for more info on the meaning of those warnings/errors that ANTLR gives you: http://dslmeinte.wordpress.com/2011/12/05/using-syntactic-predicates-in-xtext-part-1/ (yes, another shameless plug)

Re: package without brackets [message #766462 is a reply to message #766178] Thu, 15 December 2011 20:48 Go to previous messageGo to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Well, how can i use the syntactic predicate => to have the following example code:

module(m1)
  married(tim).
  married(sara).
  single(tim,12,3,2011).


Actually mydsl allows one module definition or none i.e. the previous or this:

  married(tim).
  married(sara).
  single(tim,12,3,2011).

I could do this via this grammar:
 Model:
  ('module' '(' name=ID ')')? 
  elements+=Elements;

but i dont have folding in the eclipse editor although the lines are contained?! i have in this case a Model with some name and a list of the contents as if i borrow the main rule of the model (in grammar level) to represent my module (in code level)
thanks for any help.
Mokhtar
Re: package without brackets [message #766511 is a reply to message #766462] Thu, 15 December 2011 22:57 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Sorry, but I have trouble understanding your question.
Just seeing snippets of the grammar and sample input makes it very
difficult to offer any concrete help.

- henrik
On 2011-15-12 21:48, Xtexter wrote:
> Well, how can i use the syntactic predicate => to have the following
> example code:
>
> module(m1)
> married(tim).
> married(sara).
> single(tim,12,3,2011).
>
>
> Actually mydsl allows one module definition or none i.e. the previous or
> this:
>
>
> married(tim).
> married(sara).
> single(tim,12,3,2011).
>
> I could do this via this grammar:
>
> Model:
> ('module' '(' name=ID ')')? elements+=Elements;
>
> but i dont have folding in the eclipse editor although the lines are
> contained?! i have in this case a Model with some name and a list of the
> contents as if i borrow the main rule of the model (in grammar level) to
> represent my module (in code level)
> thanks for any help.
> Mokhtar
Re: package without brackets [message #766524 is a reply to message #766511] Thu, 15 December 2011 23:33 Go to previous messageGo to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Oh sorry for that trouble. My question is how to use the syntactic predicate in case of the below rule to git rid of braces without getting warnings.
PackageDclaration:
'package' name = QualifiedName '{'
 (elements+=AbstractElement)*
'}'
;
Re: package without brackets [message #766547 is a reply to message #766524] Fri, 16 December 2011 00:47 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Need to see your entire grammar in order to help you.
And, the information regarding if you want to allow nesting (as I
described earlier) or not - I did not understand your response.

You may not need any syntactic predicates at all depending on what it is
you really want. The problem is elsewhere in your grammar.

Without any sort of dividers it is going to be very hard to support
grouping/nesting - but you seem to have them, in your examples I noticed
commas and periods.

Syntactic predicates are typically needed in situations like the common:
if ... then if ... then ... else

Is 'else' part of the last 'then', or the first 'then' - parser
generator does not know so must be told?

You may have the same issue, but it depends on how you want your
language to work.

Regards
- henrik


On 2011-16-12 24:34, Xtexter wrote:
> Oh sorry for that trouble. My question is how to use the syntactic
> predicate in case of the below rule to git rid of braces without getting
> warnings.
>
> PackageDclaration:
> 'package' name = QualifiedName '{'
> (elements+=AbstractElement)*
> '}'
> ;
>
Previous Topic:Why 2.2.1?
Next Topic:Can I somehow include an EOF in a terminal rule as an alternative?
Goto Forum:
  


Current Time: Fri Apr 26 01:00:29 GMT 2024

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

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

Back to the top