This project has moved and is read-only. For the latest updates, please go here.

validating numerical range with and without unit

Sep 25, 2013 at 4:58 PM
I have a scenario where I need to make sure that a NumberLiteral is entered in the correct range. The valid range changes with the addition of an optional unit specified right after the NumberLiteral. Essentially we have:

Distance + (Empty | "m" | "mi" | "km")

I need to validate that chunk as a whole. How do I do that?

I'm using KeyTerm for the individual units. Each of those is a Terminal, and I've had success validating using the ValidateToken event in conjunction with the args.Context.PreviousToken available there. My Distance also has a ValidateToken that works when the unit is absent. I just don't know how to ignore that Distance validation event when the optional unit is specified.
Sep 25, 2013 at 8:35 PM
you should probably use the Reduced event on parent nonterminal. so if you have
DistanceSpec.rule = Distance + (Empty | "m" ...);
DistanceSpec.Reduced += ValidateDistanceMethod;
There you would have both tokens available
Sep 25, 2013 at 10:48 PM
The Reduced event is working fine. Thanks.