Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext validation for custom terminal rules(How to write validation for terminal rules)
Xtext validation for custom terminal rules [message #1793424] Wed, 08 August 2018 06:15 Go to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Hello,

I have written a custom terminal rule similar to SL and ML comments.
I have marked that in hidden rules.
I need to validate this custom terminal rule for particular format.
How can I write validation for my scenario?
I am not able to use @Check method, as there is no Interface created for hidden terminal rules.

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden(ML_COMMENT, SL_COMMENT, MY_STMT)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;

Greeting:
	'Hello' name=ID '!';
	
terminal MY_STMT :  'STMT' ->  'END_STMT';


How can I write validation for MY_STMT.

Thanks and regards,
Virag Purnam
Re: Xtext validation for custom terminal rules [message #1793425 is a reply to message #1793424] Wed, 08 August 2018 06:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi the thing you are looking for is called "value converter" see org.eclipse.xtext.common.services.DefaultTerminalConverters and org.eclipse.xtext.conversion.IValueConverter

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext validation for custom terminal rules [message #1793440 is a reply to message #1793425] Wed, 08 August 2018 11:27 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Thanks.
That's what I was looking for.
Re: Xtext validation for custom terminal rules [message #1793441 is a reply to message #1793425] Wed, 08 August 2018 11:27 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Thanks.
That's what I was looking for.
Re: Xtext validation for custom terminal rules [message #1793486 is a reply to message #1793440] Thu, 09 August 2018 06:22 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
In runtime module
override Class<? extends IValueConverterService> bindIValueConverterService() {
		return MyDslValueConverter
	}


public class MyDslValueConverter extends DefaultTerminalConverters {
         @ValueConverter(rule = "MY_STMT ")
	public IValueConverter<String> MY_STMT () {
		return new IValueConverter<String> () {

			@Override
			public String toValue(String string, INode node) throws ValueConverterException {
				// TODO Auto-generated method stub
				return "";
			}

			@Override
			public String toString(String value) throws ValueConverterException {
				// TODO Auto-generated method stub
				return "";
			}
			
		};
	}
}


I have just returned empty string. But execution never comes to this Custom Value converter. Where am I doing wrong ?

Thanks and regards,
Virag Purnam
Re: Xtext validation for custom terminal rules [message #1793497 is a reply to message #1793486] Thu, 09 August 2018 07:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
your hello world grammar does not use MY_STMT

whitespace is important rule = "MY_STMT " is not rule = "MY_STMT"


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext validation for custom terminal rules [message #1793498 is a reply to message #1793497] Thu, 09 August 2018 08:08 Go to previous message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Ok. Thanks.
I will check this.

Best regards,
Virag Purnam
Previous Topic:Using Keywords as Identifiers
Next Topic:What builds my webxml for my war-file
Goto Forum:
  


Current Time: Tue Apr 23 16:33:46 GMT 2024

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

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

Back to the top