Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validate parser rules
Validate parser rules [message #1817588] Tue, 26 November 2019 10:16 Go to next message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
Hi guys,

I have another newbie question regarding xtext. I hope you guys can help me out.

When I have the following code:
ImageSrc : STRING;


Multiple parts in my dsl grammer are linking to this parserrule. I would like to be able to validate each instance referring to ImageSrc by using the validator.

Is there a way that I can state in the validator that ImageSrc should always follow a specific set of rules?

Thanks in advance.

Re: Validate parser rules [message #1817590 is a reply to message #1817588] Tue, 26 November 2019 10:30 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

If you write it like this we call this a Datatype Rule. It does not use any AST element. If you would make this to a parser rule with its own AST element, you could validate that element type.
Re: Validate parser rules [message #1817591 is a reply to message #1817590] Tue, 26 November 2019 10:40 Go to previous messageGo to next message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
Thanks for your answer.

Is there a way to give it a hidden AST element, so it won't influence the users input?

EDIT: Or am I asking really dumb questions now

[Updated on: Tue, 26 November 2019 10:45]

Report message to a moderator

Re: Validate parser rules [message #1817594 is a reply to message #1817591] Tue, 26 November 2019 11:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Could you give some more context (more of the grammar, sample model, what you exactly want to validate)

if you want just to do some check on the string (e.g. may not contain certain chars etc) you can also have a look at the concept of an IValueConverter


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validate parser rules [message #1817597 is a reply to message #1817594] Tue, 26 November 2019 11:57 Go to previous messageGo to next message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
Right now I only validate src from Image with a validation rule.

What I want is to apply this validationrule to ImageSrc so that every instance(?) of it will be validated.

I hope this makes it more clear what I want to achieve.


[Updated on: Tue, 26 November 2019 17:49]

Report message to a moderator

Re: Validate parser rules [message #1817598 is a reply to message #1817597] Tue, 26 November 2019 12:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
this would be a usecase for a value converter

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:What's the recommended way to implement refactoring on my DSL files
Next Topic:Question: Cross-reference to external model does not return values
Goto Forum:
  


Current Time: Thu Mar 28 09:52:23 GMT 2024

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

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

Back to the top