Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with unordered groups(Experiencing some problems with unordered groups in combination with namespaces)
Problem with unordered groups [message #558445] Sun, 12 September 2010 21:41 Go to next message
Nikolay Kasyanov is currently offline Nikolay KasyanovFriend
Messages: 30
Registered: September 2010
Location: Russia
Member
Hi there,

I tried to add namespaces (from chapter "Adding a Namespace Concept", XText manual) to my grammar. Problems started here, I started to get following error in my sample code:
rule ruleEntity failed predicate: {getUnorderedGroupHelper().canLeave(grammarAccess.getEntityAccess().getUnorderedGroup())}?

on any element placed after package declaration.

Note that I've unordered group in one rule. When unordered group removed everything is ok.

simplified version of grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	elements+=AbstractElement*;
	
AbstractElement:
	PackageDeclaration | Entity | Import;	

Import:
	'import' importedNamespace=QualifiedNameWithWildCard;

PackageDeclaration:
	"package" name=QualifiedName '{'
		(elements+=AbstractElement)*
	'}';

QualifiedName:
  ID ('.' ID)*;
  
QualifiedNameWithWildCard:
  QualifiedName '.*'?;	

Entity:
	"entity" name=ID
	"{"
		("const:" (constParams+=SystemParameter)*)? & // this rule...
		("in:" (inParams+=SystemParameter)*)? &
		("out:"	(outParams+=SystemParameter)*)?
	"}";
	
SystemParameter:
	name=ID;


Sample code:
package test.test.test {
	
}

package test1 { // error on this line
	
}


Is it the same problem?

I'm using latest Xtext with Helios.

Re: Problem with unordered groups [message #558468 is a reply to message #558445] Mon, 13 September 2010 07:27 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
I've got the same problem, even when trying to duplicate the example from the User Guide. It seems all elements of the unordered group have to be present for the parser to not fail, which kind of defies the purpose.

I'm not sure the link you've provided is the same problem. In any case: the bug registered for it is postponed to the next full release.


Re: Problem with unordered groups [message #558472 is a reply to message #558468] Mon, 13 September 2010 07:43 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

please enclose the unordered group in parentheses.

"{"
(
("const:" (constParams+=SystemParameter)*)? & // this rule...
("in:" (inParams+=SystemParameter)*)? &
("out:" (outParams+=SystemParameter)*)?
)
"}";

@Meinte: If an element of the unordered group is to be optional, you have to use the "optional"-multiplicity, otherwise each element of the group is indeed mandatory:

//pseudo code
Group: mandatory & optional?

Alex
Re: Problem with unordered groups [message #558478 is a reply to message #558472] Mon, 13 September 2010 08:07 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
@Alexander: hmmm, I thought I had tried that particular idiom... Well, I'll try it (again) anyway.


Re: Problem with unordered groups [message #558480 is a reply to message #558445] Mon, 13 September 2010 08:01 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Nicolas,

the parenthesis seem to be wrong:


Entity:
"entity" name=ID
"{"
( // <- added this one
("const:" (constParams+=SystemParameter)*)? & // this rule...
("in:" (inParams+=SystemParameter)*)? &
("out:" (outParams+=SystemParameter)*)?
) // <- and this one
"}";

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 12.09.10 23:41, schrieb Nicholas Kasyanov:
> Hi there,
>
> I tried to add namespaces (from chapter "Adding a Namespace Concept",
> XText manual) to my grammar. Problems started here, I started to get
> following error in my sample code:
> rule ruleEntity failed predicate:
> {getUnorderedGroupHelper().canLeave(grammarAccess.getEntityA ccess().getUnorderedGroup())}?
>
>
> on any element placed after package declaration.
>
> Note that I've unordered group in one rule. When unordered group removed
> everything is ok.
>
> simplified version of grammar:
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Model:
> elements+=AbstractElement*;
>
> AbstractElement:
> PackageDeclaration | Entity | Import;
>
> Import:
> 'import' importedNamespace=QualifiedNameWithWildCard;
>
> PackageDeclaration:
> "package" name=QualifiedName '{'
> (elements+=AbstractElement)*
> '}';
>
> QualifiedName:
> ID ('.' ID)*;
>
> QualifiedNameWithWildCard:
> QualifiedName '.*'?;
>
> Entity:
> "entity" name=ID
> "{"
> ("const:" (constParams+=SystemParameter)*)? & // this rule...
> ("in:" (inParams+=SystemParameter)*)? &
> ("out:" (outParams+=SystemParameter)*)?
> "}";
>
> SystemParameter:
> name=ID;
>
> Sample code:
> package test.test.test {
>
> }
>
> package test1 { // error on this line
>
> }
>
> Is http://www.eclipse.org/forums/index.php?t=tree&goto=5373 00 the same
> problem?
>
> I'm using latest Xtext with Helios.
>
>
Re: Problem with unordered groups [message #558500 is a reply to message #558480] Mon, 13 September 2010 09:33 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
@Alexander: that solved it.

From the example in the User Guide I had guessed that the unordered group semantics would already take care of the optionality.

It seems that any unordered group has to be enclosed (in the grammar def., not in the syntax) in parentheses to behave correctly. Also, the error message given in the editor in case you didn't do that, is not very helpful... -> Bugzilla?


[Updated on: Mon, 13 September 2010 09:48]

Report message to a moderator

Re: Problem with unordered groups [message #558656 is a reply to message #558500] Mon, 13 September 2010 20:08 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

depending on which version of the User Guide you looked at, the explanation may have been a bit misleading as to the optionality. But this should have been fixed (check the Xtext sources, if you are still not happy, file a bug).

As to the error message (I did not really look at it, but only tested whether explicit grouping would help), I guess a bugzilla does not hurt.

Alex
Re: Problem with unordered groups [message #558724 is a reply to message #558480] Tue, 14 September 2010 08:36 Go to previous messageGo to next message
Nikolay Kasyanov is currently offline Nikolay KasyanovFriend
Messages: 30
Registered: September 2010
Location: Russia
Member
Thanks for answer, additional parenthesis helped.
Re: Problem with unordered groups [message #558772 is a reply to message #558724] Tue, 14 September 2010 11:44 Go to previous message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
To muse a little more before filing Bugzillas (or ブグジラ, as the Japanese probably would have it), I had a look at the Xtext grammar def. which happens to be in Xtext, as it should Very Happy

I was a bit surprised that the part of the language for defining parser rules actually uses an expression language for everything between : and ; In this language there are several infix operators, ordered in increasing precedence: |=alternative, &=unordered alternative and concatenation of "abstract tokens", not separated by anything other than (optional) whitespace!, meaning assignments, keywords, rule calls, actions and everything parenthesized.

So,
optional?='optional'? & 'entity' name=ID

actually means the same as
optional?='optional'? & ( 'entity' name=ID )

because the (invisible) token concatenation operator has higher precedence than the unordered group operator. The grammar fragment accepts both "optional entity Foo" and "entity Foo optional" with identical ASTs. This also explains why the additional parentheses help in our examples. The optionality thing is covered in the 1.0.1 version of the User Guide (not before), but the expression/operator nature is not and would clarify quite a bit.

I also noticed that keywords and rule calls can have cardinality postfixes as well, at least syntax/grammar-wise -haven't checked what happens at and after generation and what semantics hold then, though... It's certainly something I haven't seen in any grammar so far Very Happy


[Updated on: Tue, 14 September 2010 11:48]

Report message to a moderator

Previous Topic:Hyperlinks in Strings/Comments
Next Topic:Filtering proposals made by ReferenceProposalCreator
Goto Forum:
  


Current Time: Sat Apr 27 00:28:34 GMT 2024

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

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

Back to the top