Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Error in Rules(A class may not be a super type of itself)
Error in Rules [message #1799969] Tue, 18 December 2018 03:55 Go to next message
Eclipse UserFriend
Hi,

I have a code written in ANTLR4 grammar which I need to convert to Xtext. I have converted a part of it and the below part gives an error: -

offline_expression
   : offline_or_expression
   ;

offline_or_expression
   : offline_and_expression ( 'or' offline_and_expression=offline_and_expression )*
   ;

offline_and_expression
   : offline_equals_expression ( 'and' offline_equals_expression=offline_equals_expression )*
   ;

offline_equals_expression
   : offline_not_equals_expression ( '=' offline_not_equals_expression=offline_not_equals_expression )*
   ;

offline_not_equals_expression
   : offline_greater_expression ( '!=' offline_greater_expression=offline_greater_expression )*
   ;

offline_greater_expression
   : offline_less_than_equals_expression ( '>' offline_less_than_equals_expression=offline_less_than_equals_expression )*
   ;

offline_less_than_equals_expression
   : offline_greater_equals_expression ( '<=' offline_greater_equals_expression=offline_greater_equals_expression )*
   ;

offline_greater_equals_expression
   : offline_less_than_expression ( '>=' offline_less_than_expression=offline_less_than_expression )*
   ;

offline_less_than_expression
   : offline_subtraction_expression ( '<' offline_subtraction_expression=offline_subtraction_expression )*
   ;

offline_subtraction_expression
   : offline_addition_expression ( '-' offline_addition_expression=offline_addition_expression )*
   ;

offline_addition_expression
   : offline_multiplication_expression ( '+' offline_multiplication_expression=offline_multiplication_expression )*
   ;

offline_multiplication_expression
   : offline_division_expression ( '*' offline_division_expression=offline_division_expression )*
   ;

offline_division_expression
   : offline_mod_expression ( '/' offline_mod_expression=offline_mod_expression)*
   ;

offline_mod_expression
   : offline_in_expression ( '%' offline_in_expression=offline_in_expression )*
   ;

offline_in_expression
   : ( offline_not_expression ( 'in' offline_not_expression=offline_not_expression )* )
   ;

offline_not_expression
   : ( '!' )? offline_boolean_expression
   ;

offline_boolean_expression
   : ( offline_method_call_expression | ( 'true' | 'false' ) )
   ;

offline_method_call_expression
   : ( offline_expression_atom | ( offline_method_call_expression_referenced_name ( '(' ')' | '(' offline_expression=offline_expression ( ',' offline_expression2=offline_expression )* ')' )* ) )
   ;

offline_method_call_expression_referenced_name
   : ( 'record' '.' )? ( identifier | CAMELCASE_IDENTIFIER ) ( '.' ( identifier | CAMELCASE_IDENTIFIER ) )*
   ;

offline_expression_atom
   : ( '(' offline_expression ( ',' offline_expression=offline_expression )* ')' | ( '-' )? INTEGER | ( '-' )? DECIMAL | STRING | offline_expression_atom_reference_name | 'null' )
   ;

offline_expression_atom_reference_name
   : ( 'record' '.' )? ( identifier | CAMELCASE_IDENTIFIER ) ( '.' ( identifier | CAMELCASE_IDENTIFIER ) )*
   ;



All the rule names in this code are underlined in red except 'offline_expression_atom_reference_name' and 'offline_method_call_expression_referenced_name'.
The error states "A class may not be a super type of itself".

Could anyone please explain why this is happening and how to overcome this error?
Regards!
Re: Error in Rules [message #1799970 is a reply to message #1799969] Tue, 18 December 2018 03:57 Go to previous messageGo to next message
Eclipse UserFriend
read here on how to write a expression grammar: https://typefox.io/parsing-expressions-with-xtext https://www.eclipse.org/Xtext/documentation/307_special_languages.html#expressions
Re: Error in Rules [message #1799973 is a reply to message #1799970] Tue, 18 December 2018 04:18 Go to previous messageGo to next message
Eclipse UserFriend
See also here https://speakerdeck.com/kthoms/introduction-to-expression-languages-with-xtext
And "Implementing Domain-Specific Languages with Xtext and Xtend " from Lorenzo Bettini.
Re: Error in Rules [message #1799982 is a reply to message #1799973] Tue, 18 December 2018 05:20 Go to previous messageGo to next message
Eclipse UserFriend
Thank You Christian and Karsten! I will refer these documents.
Re: Error in Rules [message #1800037 is a reply to message #1799982] Wed, 19 December 2018 04:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

As a side question, does it take a long time to generate artifacts of a considerably long xtext grammar file (1236 lines of code)? I started generating artifacts but now it's been about 6 hours and it is still not done. I do not understand whether it is working properly or not.

Regards!
Re: Error in Rules [message #1800044 is a reply to message #1800037] Wed, 19 December 2018 05:28 Go to previous messageGo to next message
Eclipse UserFriend
it should never take 6 hours. if so there might be somthing strange with your grammar or you ran into a bug
Re: Error in Rules [message #1800045 is a reply to message #1800037] Wed, 19 December 2018 05:28 Go to previous messageGo to next message
Eclipse UserFriend
Depends on the grammar complexity (not size) and heap. I never had a grammar compiling that long, not even close to that. I would consider everything above 1 min already as really long.

Please understand that we can't give detailed answers without knowing internals of the project. Usually customers that we serve directly and where we are involved into the language development can be helped much better than we can here in the forum.
Re: Error in Rules [message #1800302 is a reply to message #1800045] Sun, 23 December 2018 22:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I have the below rule in my grammar,

QUESTION_LINE_COMMENT
   : ( '//?' ~('\r'|'\n')* )  
 
   ;


I get an error as given in the image I have attached.
Could you please tell why this error occurs, and if possible, how to eliminate it?
Regards!
  • Attachment: ~error.png
    (Size: 5.65KB, Downloaded 144 times)
Re: Error in Rules [message #1800307 is a reply to message #1800302] Mon, 24 December 2018 02:06 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Did you mean ! as in

terminal SL_COMMENT:
'--' !('\n' | '\r')* ('\r'? '\n')?;

Regards

Ed Willink
Re: Error in Rules [message #1800311 is a reply to message #1800307] Mon, 24 December 2018 03:32 Go to previous messageGo to next message
Eclipse UserFriend
Yes, it worked. Thank you very much!

I have another question, if you wouldn't mind.

My Grammar looks like below: -

Model:
	(test+=Test)*
;

//OfflineExpressionParser

Test:
	Comment | Exp | MainExp 
;

Comment:
	comment=COM
;
Exp:
	exp='Hello'
;

MainExp:
	'start' '{' (Exp=Exp)+ '}'
;

terminal COM:
	( '---' ('-')+ (' ') (('A'..'Z'|'0'..'9')+ (' '))+ ('-')+ )
;



Now, when I try the 'Comment' rule in the runtime, the resulting responses are given in the attached image.

Could you please tell me the reason for the Comments to be recognized/not recognized by the program at different instances?
I tried modifying the grammar as below, but it gave the same results: -

Model:
	(test+=Test)*
;

Test:
	Comment | Exp | MainExp 
;

Comment:
	comment=COM
;
Exp:
	exp='Hello'
;

MainExp:
	Comment | ('start' '{' (Exp=Exp)+ '}')
;

terminal COM:
	( '---' ('-')+ (' ') (('A'..'Z'|'0'..'9')+ (' '))+ ('-')+ )
;


What if I wanted for the program to recognize Comments anywhere in the file? Could you please tell me how I could modify the grammar?
Regards!

[Updated on: Mon, 24 December 2018 03:33] by Moderator

Re: Error in Rules [message #1800329 is a reply to message #1800311] Mon, 24 December 2018 11:35 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Your grammar does not allow comments in Exps.

Regards

Ed Willink
Re: Error in Rules [message #1800337 is a reply to message #1800311] Mon, 24 December 2018 16:13 Go to previous messageGo to next message
Eclipse UserFriend
P J wrote on Mon, 24 December 2018 03:32
What if I wanted for the program to recognize Comments anywhere in the file? Could you please tell me how I could modify the grammar?!


The easiest way to have comments anywhere is to hide them just like whitespace. e.g

grammar org.eclipse.ocl.xtext.base.Base hidden(WS, ML_COMMENT, SL_COMMENT) //with org.eclipse.xtext.common.Terminals


The hidden comments are recoverable from the leaf nodes of an Xtext Node element.

Regards

Ed Willink
Re: Error in Rules [message #1800370 is a reply to message #1800337] Wed, 26 December 2018 00:36 Go to previous messageGo to next message
Eclipse UserFriend
Thank You Ed! Hiding the Comments worked for me. :-)
Re: Error in Rules [message #1800503 is a reply to message #1800370] Mon, 31 December 2018 00:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I have the below rule in the antlr4 grammar that I'm converting to xtext: -

copy_on_crud_default_to
   : dataitem_reference ( ( ',' dataitem_reference )+ )?
   ;


I get a warning for the optional symbol (?) at the end stating "More than one cardinality was set. Merging '?' with previously assigned cardinality to '*'."
I know the error is because the two cardinalities give different meanings.
Does the above rule convey a non-greedy operator?

Could you please tell me how I should convert this correctly to xtext?
Re: Error in Rules [message #1800506 is a reply to message #1800503] Mon, 31 December 2018 02:01 Go to previous message
Eclipse UserFriend
You should use assignments and assign to lists
Previous Topic:Error in building shadowJar from project with multiple xtext files (Cross-reference)
Next Topic:Non-Standard import and namespace
Goto Forum:
  


Current Time: Tue Jun 17 17:04:25 EDT 2025

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

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

Back to the top