Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Two-step validation question
Two-step validation question [message #762802] Thu, 08 December 2011 16:31 Go to next message
Jonathan Whitall is currently offline Jonathan WhitallFriend
Messages: 18
Registered: July 2009
Junior Member
I essentially have a two-step validation process for my DSL. The first step is a purely syntactical (non-contextual) validation step. All of these validations can occur in parallel using the @Check annotation. I have this working beautifully.

Step two is a contextual validation step, i.e. it's a walk through the model, step-by-step, determining if each expression makes sense in the context in which it's used. It is meant to execute when there are no validation errors in step 1.

Right now I have step one validations annotated with @Check(FAST) and the step two validation annotated with @Check(NORMAL). I'm thinking that I can't actually annotate the step two validation because it runs as if it doesn't have a dependency on the result of the step one validations. What should I do instead?

I'm currently using Xtext 2.1.
Re: Two-step validation question [message #762844 is a reply to message #762802] Thu, 08 December 2011 17:36 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2011-08-12 17:31, Jonathan Whitall wrote:
> I essentially have a two-step validation process for my DSL. The first
> step is a purely syntactical (non-contextual) validation step. All of
> these validations can occur in parallel using the @Check annotation. I
> have this working beautifully.
>
> Step two is a contextual validation step, i.e. it's a walk through the
> model, step-by-step, determining if each expression makes sense in the
> context in which it's used. It is meant to execute when there are no
> validation errors in step 1.
>
> Right now I have step one validations annotated with @Check(FAST) and
> the step two validation annotated with @Check(NORMAL). I'm thinking that
> I can't actually annotate the step two validation because it runs as if
> it doesn't have a dependency on the result of the step one validations.
> What should I do instead?
>
> I'm currently using Xtext 2.1.

I am doing the second level type of validation during linking (in
callback afterModelLinked). If you want to include cross references in
your validation, this is the place they need to go.

Regards
- henrik
Re: Two-step validation question [message #762918 is a reply to message #762844] Thu, 08 December 2011 20:13 Go to previous messageGo to next message
Jonathan Whitall is currently offline Jonathan WhitallFriend
Messages: 18
Registered: July 2009
Junior Member
This is more than cross linking. I'm essentially trying to capture the runtime validation errors of program and put the diagnostic messages at the appropriate place in the editor.

Imagine I defined a "rock tracker" program using some imaginary grammar (with keywords in all-caps):

PUT 8 rocks IN box
LET n = 6
ASSERT n rocks IN box

My "step 2" validation would mark the ASSERT part of the model with an error because it's expecting 8 rocks in the box, not 6. Now imagine that I had a typo on my LET statement:

PUT 8 rocks IN box
LETT n = 6
ASSERT n rocks IN box

This would make my "step 1" validation fail, but "step 2" validation would still run with a syntactically incorrect model, throwing an erroneous error when it hits the assert (such as an "undefined variable n").

Or are you saying that afterModelLinked() is only called when the syntax check passes?
Re: Two-step validation question [message #762978 is a reply to message #762918] Thu, 08 December 2011 22:39 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2011-08-12 21:13, Jonathan Whitall wrote:
> This is more than cross linking. I'm essentially trying to capture the
> runtime validation errors of program and put the diagnostic messages at
> the appropriate place in the editor.
>
> Imagine I defined a "rock tracker" program using some imaginary grammar
> (with keywords in all-caps):
>
> PUT 8 rocks IN box
> LET n = 6
> ASSERT n rocks IN box
>
> My "step 2" validation would mark the ASSERT part of the model with an
> error because it's expecting 8 rocks in the box, not 6. Now imagine that
> I had a typo on my LET statement:
>
> PUT 8 rocks IN box
> LETT n = 6
> ASSERT n rocks IN box
>
> This would make my "step 1" validation fail, but "step 2" validation
> would still run with a syntactically incorrect model, throwing an
> erroneous error when it hits the assert (such as an "undefined variable
> n").
>
> Or are you saying that afterModelLinked() is only called when the syntax
> check passes?
It is called before validation, but after linking. So if you need to
perform either additional linking, or evaluation (such as computing the
number of rocks in the box), you can do that in afterModelLinked.

E.g. afterModel is linked, you evaluate everything statically and issue
errors as you find asserts that do not hold true.

You would naturally skip an Assert that does not hold a valid expression
(as this problem is caught by other parts of your validation).

You can probably do the same in a check of "heavier kind" - it is only
if you need to performs something between linking and validation that
you would place the logic in afterModelLinked. One reason would be if
you have a large number of files, and values are computed for those
files, and you need the result, but do not want to evaluate everything
for every thing you validate. (There are a number of ways to make those
values available, and a good place to pick them up is in a "custom
linker" that picks up values). (I can elaborate on that if you are
interested).

Regards
- henrik
Re: Two-step validation question [message #763086 is a reply to message #762978] Fri, 09 December 2011 06:11 Go to previous message
Jonathan Whitall is currently offline Jonathan WhitallFriend
Messages: 18
Registered: July 2009
Junior Member
So what I'm actually doing in this scenario is converting the EMF model into a POJO (EMF-agnostic) model. The "step 2" validation runs on the POJO model, but I'm tracing back any exceptions thrown from the POJO model validation to the EMF object it was converted from.

I have the POJO model because not all inputs are going to be from the DSL. I actually have an XML Schema based format for this language which will ultimately be used as an interchange format between various other software programs. That and the EMF-based model has some constructs in it which are very natural language specific but not particularly processor friendly, and the decoupling of the two models seems to make sense.
Previous Topic:Define own scope: Reference C methods
Next Topic:What is new in Xtext 2.2.0 ?
Goto Forum:
  


Current Time: Thu Apr 25 13:43:01 GMT 2024

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

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

Back to the top