Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to use multi line in XBlockExpression of a dsl
How to use multi line in XBlockExpression of a dsl [message #1817729] Thu, 28 November 2019 09:47 Go to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 53
Registered: December 2015
Member
Hi,

I have a small dsl to store sql statements with variables. Currently I can define this statments in one line. Are there possibility to use the xtend multi line in XblockExpression?

My dsl looks like
Model returns Model:
	{Model}
	'package' package=QualifiedName
	
	'class' name=ID '{'
		(queries+=Query ( queries+=Query)* )?
	'}'
	;
	
Query returns Query:
	{Query}
	'Query' name=EString '(' (parameters+=JvmFormalParameter ( "," parameters+=JvmFormalParameter)* )? ')' 
		statement=XBlockExpression
	;
	
EString returns ecore::EString:
	STRING | ID;


For complex statments it is better to separate it by line breaks, but here it is ok
package hello.world
 
class QueryManager{ 
	
	Query HelloWorld(String param1){ 
		val sql = "SELECT * from Table where name = "
		sql
	}
}


How can I defined the XBlockExpression to use that
Query HelloWorld(String param1, String param2){ 
		val sql = '''SELECT * from Table 
                where name = param1 and forename = param2
                order by name asc               
'''
		sql
	}


Regards
dimg

P.S. I tried to use the

terminal STATEMENT: "'''" -> "''''";

But how can I Escape the character ' ?
Further how can I get this result as String with linebreaks in my ModelInferer?
Maybe it is better to reuse that one from Xtend Grammar

[Updated on: Thu, 28 November 2019 09:55]

Report message to a moderator

Re: How to use multi line in XBlockExpression of a dsl [message #1817731 is a reply to message #1817729] Thu, 28 November 2019 10:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13643
Registered: July 2009
Senior Member
you have to care about that yourself. (e.g. have a look what xtend does which uses jflex for lexing
p.s. do you know that "" and '' are already Multiline?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to use multi line in XBlockExpression of a dsl [message #1817734 is a reply to message #1817731] Thu, 28 November 2019 10:26 Go to previous messageGo to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 53
Registered: December 2015
Member
Okay thanks for feedback, maybe I use this terminal STATEMENT: '```' -> '```';

And cleaned up the result in the ModelInferrer. Because the result of this description
class QueryManager{ 
	
	Query HelloWorld(String param1)```
	SELECT * from Table where name = <param1>
	```
	
}


returns the JavaCode with
@SuppressWarnings("all")
public class QueryManager {
  public static String HelloWorld(final String param1) {
    return ```
    	SELECT * from Table where name = <param1>
    	```;
  }
}
Re: How to use multi line in XBlockExpression of a dsl [message #1817739 is a reply to message #1817734] Thu, 28 November 2019 11:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13643
Registered: July 2009
Senior Member
you need to implement a value converter for your terminals

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to use multi line in XBlockExpression of a dsl [message #1817740 is a reply to message #1817739] Thu, 28 November 2019 11:30 Go to previous message
Dimg Cim is currently offline Dimg CimFriend
Messages: 53
Registered: December 2015
Member
Thank you very much this is what I need.
Previous Topic:Unable to run unit tests
Next Topic:Testing code generation
Goto Forum:
  


Current Time: Thu Oct 29 17:50:27 GMT 2020

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

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

Back to the top