Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Working with unordered groups
Working with unordered groups [message #1798555] Tue, 20 November 2018 07:14 Go to next message
Eclipse UserFriend
Hi,

My use case is; I have written a xtext grammar to create classes. The grammar looks like this:

RSELClass:
    'Class' name=ID ('subClassOf' '('subClassOf+=[RSELClass|QualifiedName]+ ')')? | {RSELClass}  ('instanceOf' '(' instanceOf=[RSELClass|QualifiedName] ')')? 
    '{'
    (   
     	('partitions'  partitions+=[RSELClass]+ EndStmt)? &
     	('subOrdinateTo' subOrdinateTo+=[RSELClass]+ EndStmt)? &
     	('disjointCategorizes'  disjointCategorizes+=[RSELClass]+ EndStmt)? &
     	('strongSubOrdinateTo' strongSubOrdinateTo+=[RSELClass]+ EndStmt)? 
    )
    '}';

EndStmt:
     ';'
;


The instance of this grammar looks like this:

Class class {
	
}

Class B {
	
}

Class A subClassOf (B) instanceOf (class) {
	
	partitions B;
	subOrdinateTo B;
	disjointCategorizes B;
	strongSubOrdinateTo B;	
}


The problem is:

When I am trying to write the code for validation in the RSELModelValidator.xtend, only class member "subClassOf" is getting populated in the instance of RSELClass A. Rest all data members "instanceOf", "partitions", "subOrdinateTo", "disjointCategorizes ", "strongSubOrdinateTo " are null.

However, when I change the grammar and set these elements (data members of class) as ordered:

RSELClass:
    'Class' name=ID ('subClassOf' '('subClassOf+=[RSELClass|QualifiedName]+ ')')?  ('instanceOf' '(' instanceOf=[RSELClass|QualifiedName] ')')? 
    '{'
    (   
     	('partitions'  partitions+=[RSELClass]+ EndStmt)? 
     	('subOrdinateTo' subOrdinateTo+=[RSELClass]+ EndStmt)? 
     	('disjointCategorizes'  disjointCategorizes+=[RSELClass]+ EndStmt)? 
     	('strongSubOrdinateTo' strongSubOrdinateTo+=[RSELClass]+ EndStmt)? 
    )
    '}';

EndStmt:
     ';'
;


It works fine. i.e. all the data members are populated.

Can anyone please guide me what I am missing/doing wrong? Is it a bug in Xtext/Xtend? I want these data members to be unordered.

Any help is much appreciated.

Regards,
Yash
Re: Working with unordered groups [message #1798556 is a reply to message #1798555] Tue, 20 November 2018 07:21 Go to previous messageGo to next message
Eclipse UserFriend
"Class A subClassOf (B) instanceOf (class) {"

is not allowed by this grammar. did you check eResource.getErrors() for parse errors?
Re: Working with unordered groups [message #1798567 is a reply to message #1798556] Tue, 20 November 2018 08:33 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian for the reply.

No, rselClass.eResource.getErrors() does not return any error.

On further investigation, I have observed that it's the OR between subClassOf and instanceOf is creating issue.

RSELClass:
'Class' name=ID ('subClassOf' '('subClassOf+=[RSELClass|QualifiedName]+ ')')? | {RSELClass} ('instanceOf' '(' instanceOf=[RSELClass|QualifiedName] ')')?

If there's no OR here, the data members are populated otherwise they are null. I don't understand what's the magic here.
Re: Working with unordered groups [message #1798570 is a reply to message #1798567] Tue, 20 November 2018 08:39 Go to previous messageGo to next message
Eclipse UserFriend
A|B says

either parse a A or parse a B
but you have A B in your model

=> do you want to have both? then you should use an unordered group here too.
also the position of the | is bogus and the {RSELClass}

can you please example what should be possible?

'Class' name=ID (('subClassOf' '('subClassOf+=[RSELClass|QualifiedName]+ ')')? & ('instanceOf' '(' instanceOf=[RSELClass|QualifiedName] ')')? )

????

Re: Working with unordered groups [message #1798571 is a reply to message #1798570] Tue, 20 November 2018 09:16 Go to previous messageGo to next message
Eclipse UserFriend
Probably I misunderstood the use of | here.

I came across another follow problem after making the changes are you suggested.

The grammar for RSELClass looks like this (I have removed the un-necessary parts):
RSELClass:
     'Class' name=ID ('instanceOf' '(' instanceOf=[RSELClass|QualifiedName] ')')? 
    //name=ID ('instanceOf' instanceOf+=[RSELClass|QualifiedName] (',' instanceOf+=[RSELClass|QualifiedName])* )?
    //('subClassOf' subClassOf+=[RSELClass|QualifiedName] (',' subClassOf+=[RSELClass|QualifiedName])*)? 
    '{'
      	 
        (
        ('subClassOf' '(' subClassOf+=[RSELClass|QualifiedName]+ ')' EndStmt)? &	   
       	('attribute' '{'
       		attributes+=RSELAttribute+ 
       		'}'
     	)? &
     	('deep_instantiation' body=RSELBlock)? 
     )
    '}';
   
RSELBlock:
    {RSELBlock}  '{' statements+=RSELStatement* '}';

RSELStatement:
    RSELExpression ';' ;
        
RSELExpression:
    RSELAssignment;

RSELAssignment returns RSELExpression:
    RSELSelectionExpression
    ({RSELAssignment.left=current} '=' right=RSELTerminalExpression)?; // Right associativity

RSELSelectionExpression returns RSELExpression:
    {RSELExpression} (
     [color=red]   attribute+=[RSELAttribute][/color]
    )*;

RSELTerminalExpression returns RSELExpression:
    {RSELStringConstant} value=STRING |
    {RSELIntConstant} value=INT |
    {RSELPropFormula} value=ReqExpr |
    {RSELBoolConstant} value=('true' | 'false') |
    {RSELNull} 'null' |
    '(' RSELExpression ')';



The instance of this grammar looks like this:

Class class instanceOf (class) {
	
}

Class B instanceOf (class){
	
}

Class A  instanceOf (class) {
	
	subClassOf (C);
	partitions B;
	subOrdinateTo B;
	
	
	disjointCategorizes B;
	strongSubOrdinateTo B;	
	
	attribute {
		name : String [1..*];
	}
	
	deep_instantiation {
		name = "Yash";
	}
	
}

Class C  instanceOf (class){
	deep_instantiation {
		name = "Yash";  //It shows an error that name cannot be resolved. 
	}
	
}



However, this scoping error was not there when I was mistakenly using | between subClassOf and instanceOf.

Sorry, I am exploring xtext and may be doing a blunder here with scoping. Thanks for your patience.
Re: Working with unordered groups [message #1798573 is a reply to message #1798571] Tue, 20 November 2018 09:23 Go to previous messageGo to next message
Eclipse UserFriend
please open the model element dialog crtl+shift+f3 or navifate menu to find out how the names of the attributes are.
i dont know how the rules in your case are. how do you want to reference?
simple name / qualified name?
you can either adapt your name provider or scoping.
unfort. your snippets are not in a way to try out (e.g. grammar incomplete. dont see where name is defined in the snippet.
Re: Working with unordered groups [message #1798574 is a reply to message #1798571] Tue, 20 November 2018 09:25 Go to previous messageGo to next message
Eclipse UserFriend
Also this might be useful:


RSELAttribute:
     name=ID ':' type=Type  cardinality=Cardinality? EndStmt
;


enum Cardinality:
	ExactlyOne='[1]' | OneorMore='[1..*]' | ZeroOrMore='[*]' | ZeroOrOne='[0..1]'
;

Type:
    IntegerType | StringType | BooleanType | ClassType | JVMType | PropFormula | PredFormula
;

IntegerType:
    id='Integer'
;

StringType:
    id='String'
;

BooleanType:
    id='Boolean'
;

ClassType:
    id=[RSELClass|QualifiedName]
;

PropFormula:
	id='PropFormula'
;

PredFormula:
	id='PredFormula'
;

Re: Working with unordered groups [message #1798575 is a reply to message #1798574] Tue, 20 November 2018 10:21 Go to previous messageGo to next message
Eclipse UserFriend
Please find attached grammar file and corresponding instance.

The problem is:

When I am having | between subClassOf and instanceOf (as shown in the previous snippets) on opening the model element dialog using cntrl+shft+f3
the attributes names are name and sn

index.php/fa/34377/0/


However when making the changes as suggested by you. (The attached grammar file contains these changes) these attributes names are A.name and A.sn .

index.php/fa/34376/0/

How is this getting impacted?

All I want is to be able to access these attributes from other class as well.

[Updated on: Tue, 20 November 2018 10:22] by Moderator

Re: Working with unordered groups [message #1798579 is a reply to message #1798575] Tue, 20 November 2018 10:45 Go to previous messageGo to next message
Eclipse UserFriend
as i said. if you want simple name (bogus from my perspective) you need to adapt the name provider.
without my change it seems to be working by accident (cause the part that gives the bad parent name = the class) is skipped
(you should see the classes having no name too - in fact you should have a class with the name and one without)
Re: Working with unordered groups [message #1798629 is a reply to message #1798579] Wed, 21 November 2018 06:12 Go to previous messageGo to next message
Eclipse UserFriend
"you need to adapt the name provider."

Any tips how can I do that? Code snippet for that? and where should I write that code?
Re: Working with unordered groups [message #1798634 is a reply to message #1798629] Wed, 21 November 2018 07:39 Go to previous messageGo to next message
Eclipse UserFriend
there should be gazillions of examples in the forum and there is this old blogpost
https://www.dietrich-it.de/xtext/2011/07/16/iqualifiednameproviders-in-xtext-2-0.html
Re: Working with unordered groups [message #1798661 is a reply to message #1798634] Thu, 22 November 2018 05:57 Go to previous message
Eclipse UserFriend
Thanks a lot Christian :)
Previous Topic:IQualifiedName references to object inherited from other DSL
Next Topic:Xpect Test case issue
Goto Forum:
  


Current Time: Tue Jun 24 19:46:17 EDT 2025

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

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

Back to the top