Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using LocalDateTime in Xtext Grammar
Using LocalDateTime in Xtext Grammar [message #1843217] Tue, 20 July 2021 12:48 Go to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
Hello together,

can someone tell me how to use LocalDateTime in Xtext?

I defined this in xcore and convert it to Xtext dsl
class Event{
	String ^id
	String title
	String summary
	String location
    String description
	LocalDateTime start
	LocalDateTime end
	LocalDateTime created
	LocalDateTime lastModified
	String status
	String source
}

type LocalDateTime wraps LocalDateTime
create{
	LocalDateTime.parse(it, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
}convert{
	if( it !== null ) DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(it)
}


The result looks likethis
[Event returns Event:
	{Event}
	'Event' '('
		('start' start=LocalDateTime)?
		('end' end=LocalDateTime)?
		('title' title=EString)?
		('location' location=EString)?
	')';

EIntegerObject returns ecore::EIntegerObject:
	'-'? INT;

LocalDateTime returns LocalDateTime:
	'LocalDateTime' /* TODO: implement this rule and an appropriate IValueConverter */;


How can I fill my LocalDateTime as String in the dsl and after that convert it to LocalDateTime?

How should I use the IValueConverter?

Best regards
Dimg

[Updated on: Tue, 20 July 2021 12:49]

Report message to a moderator

Re: Using LocalDateTime in Xtext Grammar [message #1843218 is a reply to message #1843217] Tue, 20 July 2021 12:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
yes you should implement an IValueConverter.
the first question i did not understand.

maybe something like

LocalDateTime:
INT "-" INT "-" INT INT ":"INT;
and then make sure the stuff is correct in value converter


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

[Updated on: Tue, 20 July 2021 12:58]

Report message to a moderator

Re: Using LocalDateTime in Xtext Grammar [message #1843219 is a reply to message #1843218] Tue, 20 July 2021 13:23 Go to previous messageGo to next message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
Thank you, yes I ask for the LocalDateTime pattern.

Where should I initialized the implemented ValueConverter?

Currently I use this grammar to generate the xmi file. At which point should I use the IValueConverter then?
Re: Using LocalDateTime in Xtext Grammar [message #1843220 is a reply to message #1843219] Tue, 20 July 2021 13:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14026
Registered: July 2009
Senior Member
subclass and bind DefaultTerminalConverters

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: Using LocalDateTime in Xtext Grammar [message #1843222 is a reply to message #1843219] Tue, 20 July 2021 14:51 Go to previous message
Dimg Cim is currently offline Dimg CimFriend
Messages: 59
Registered: December 2015
Member
Thank you I found it, the point is I have to bind the subclass of DefaultTerminalConverters to the RuntimeModule. It works!
Previous Topic:XtextDocument/Node does not update offset ?
Next Topic:Deadlock between Job and event listener on Display thread
Goto Forum:
  


Current Time: Wed Jul 28 22:42:48 GMT 2021

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

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

Back to the top