Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xbase: overwrite the Operator '='
Xbase: overwrite the Operator '=' [message #879947] Fri, 01 June 2012 07:25 Go to next message
Hans-Georg Glöckler is currently offline Hans-Georg GlöcklerFriend
Messages: 88
Registered: July 2009
Member
I use Xtext with Xbase.
My Grammar is

grammar org.eclipse.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.xbase.Xbase

generate domainmodel "http://www.xtext.org/example/Domainmodel"

DomainModel:
	elements+=AbstractElement*;

AbstractElement:
	PackageDeclaration | Entity | Import;

PackageDeclaration:
	'package' name=QualifiedName elements+=AbstractElement* ';'	;

Import:
	'import' importedNamespace=QualifiedNameWithWildCard';';

Entity:
	'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
		features+=Feature*
	'}';

Feature:
	Property | Operation;

Property:
	(modifier=Modifier)+ 'var' name=ValidID ':' type=JvmTypeReference ';';

Operation:
	(modifier=Modifier)+ 'def' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' ':' type=JvmTypeReference 
		body=XBlockExpression ';';

Modifier:
	 final?='final' & static?='static' & visibility=Visibility;

enum Visibility:
	 PACKAGE='package' | PRIVATE='private' | PROTECTED='protected' |  PUBLIC='public';

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


I have 3 questions:

Question 1) Why is the following line of sourcecode not working
Property:
	(modifier=Modifier) 'var' name=ValidID ':' type=JvmTypeReference ';';

I get the following jvmmodelinferrer:
rule ruleModifier failed predicate: {getUnorderedGroupHelper().canLeave(grammarAccess.getModifierAccess().getUnorderedGroup())}?

Question 2) Why is the following line of sourcecode not working
Operation:
	(modifier=Modifier) 'def' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' ':' type=JvmTypeReference 
		body=XBlockExpression ';';

I get the following jvmmodelinferrer:
Multiple markers at this line
- rule ruleModifier failed predicate: {getUnorderedGroupHelper().canLeave(grammarAccess.getModifierAccess().getUnorderedGroup())}?
- missing ';' at 'private

Question 3) How can I overwrite the Operator '=' with ':=' in Xbase
I want to write in the model
val int value3 := value1 + value2;



I send you a picture of the error in the model.
  • Attachment: Unbenannt.png
    (Size: 176.08KB, Downloaded 118 times)

[Updated on: Fri, 01 June 2012 07:46]

Report message to a moderator

Re: Xbase: overwrite the Operator '=' [message #879959 is a reply to message #879947] Fri, 01 June 2012 07:49 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Hans-Georg:

1+2) please refer to the docs on unordered groups. The group's elements
have to be optional in order to .. well .. make them optional.

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

Am 01.06.12 09:25, schrieb hans-georg Mising name:
> I use Xtext with Xbase.
> My Grammar is
>
> grammar org.eclipse.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.xbase.Xbase
>
> generate domainmodel "http://www.xtext.org/example/Domainmodel"
>
> DomainModel:
> elements+=AbstractElement*;
>
> AbstractElement:
> PackageDeclaration | Entity | Import;
>
> PackageDeclaration:
> 'package' name=QualifiedName elements+=AbstractElement* ';' ;
>
> Import:
> 'import' importedNamespace=QualifiedNameWithWildCard';';
>
> Entity:
> 'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
> features+=Feature*
> '}';
>
> Feature:
> Property | Operation;
>
> Property:
> (modifier=Modifier) 'var' name=ValidID ':' type=JvmTypeReference ';';
>
> Operation:
> (modifier=Modifier) 'def' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' ':' type=JvmTypeReference
> body=XBlockExpression ';';
>
> Modifier:
> final?='final'& static?='static'& visibility=Visibility;
>
> enum Visibility:
> PACKAGE='package' | PRIVATE='private' | PROTECTED='protected' | PUBLIC='public';
>
> QualifiedNameWithWildCard :
> QualifiedName ('.' '*')?;
>
>
> I have two questions:
>
> Question 1) Why is the following line of sourcecode not working
>
> Property:
> (modifier=Modifier) 'var' name=ValidID ':' type=JvmTypeReference ';';
>
> I get the following jvmmodelinferrer:
> rule ruleModifier failed predicate: {getUnorderedGroupHelper().canLeave(grammarAccess.getModifierAccess().getUnorderedGroup())}?
>
> Question 2) Why is the following line of sourcecode not working
>
> Operation:
> (modifier=Modifier) 'def' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' ':' type=JvmTypeReference
> body=XBlockExpression ';';
>
> I get the following jvmmodelinferrer:
> Multiple markers at this line
> - rule ruleModifier failed predicate: {getUnorderedGroupHelper().canLeave(grammarAccess.getModifierAccess().getUnorderedGroup())}?
> - missing ';' at 'private'
>
> I send you a picture of the error in the model.
Re: Xbase: overwrite the Operator '=' [message #879960 is a reply to message #879947] Fri, 01 June 2012 07:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

the problem may be your errorneous Modifier definition

Modifier:
	 final?='final'? & static?='static'? & visibility=Visibility;


or

Modifier:
	 final?='final'? & static?='static'? & visibility=Visibility?;


(depending on your semantics if visibility is required)
may do the trick

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase: overwrite the Operator '=' [message #879981 is a reply to message #879960] Fri, 01 June 2012 08:27 Go to previous message
Hans-Georg Glöckler is currently offline Hans-Georg GlöcklerFriend
Messages: 88
Registered: July 2009
Member
Thanks,
with this trick Question 1+2 are working.
Have a lot of thanks.
Previous Topic:[Solved] How to configure a custom QualifiedNameProvider?
Next Topic:How do I create a FOR loop that runs once?
Goto Forum:
  


Current Time: Thu Sep 26 00:04:13 GMT 2024

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

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

Back to the top