Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 09:46 Go to next message
Jakob Sachs is currently offline Jakob SachsFriend
Messages: 15
Registered: May 2018
Junior Member
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 10:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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 '}';


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Writing java-style If statements in XText results in an error [message #1810542 is a reply to message #1810540] Tue, 13 August 2019 10:14 Go to previous message
Jakob Sachs is currently offline Jakob SachsFriend
Messages: 15
Registered: May 2018
Junior Member
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 Apr 25 23:17:51 GMT 2024

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

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

Back to the top