Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Writing java-style If statements in XText results in an error
Writing java-style If statements in XText results in an error [message #1810536] Tue, 13 August 2019 05:46 Go to next message
Eclipse UserFriend
I'm writing a custom Xtext editor for my own DSL-Language and now want to add If-Statements to my language.
The Statements look something like this:
if (TRUE) {
    (...)
}



But when I try adding them in, I get an error "A class may not be a super type of itself".

This is my code so far:

grammar XtextTest with org.eclipse.xtext.common.Terminals

generate xtextTest "http://www.my.xtext/Test"

Model:
	statements+=Statement*;

Statement:
	VariableAssignment |
	IfStatement;

IfStatement:
	'if' '(' BooleanExpression ')' '{' Statement '}';
	
BooleanExpression:
	'TRUE' | 'FALSE';

VariableAssignment:
	name=ID "=" INT ';';


How can I implement this? Or am I doing something obviously wrong?

Any help is appreciated ^^
Re: Writing java-style If statements in XText results in an error [message #1810540 is a reply to message #1810536] Tue, 13 August 2019 06:09 Go to previous messageGo to next message
Eclipse UserFriend
hi, assignments are a important thing in Xtext. if you just call rules without assigning them it influences the supertype hierarchy that is inferred. => it is better to change the grammar to

IfStatement:
'if' '(' condition=BooleanExpression ')' '{' statement=Statement '}';
Re: Writing java-style If statements in XText results in an error [message #1810542 is a reply to message #1810540] Tue, 13 August 2019 06:14 Go to previous message
Eclipse UserFriend
Wow okay, that was easy. Thank you very much ^^
Previous Topic:XtextSerializationException for cross references to existing objects
Next Topic:Web editor code generation
Goto Forum:
  


Current Time: Thu May 15 16:52:20 EDT 2025

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

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

Back to the top