[x3d-public] X3D regular expression (regex) improvements

Don Brutzman brutzman at nps.edu
Fri Aug 17 12:15:15 PDT 2018


details follow on current regex progress.

On 8/7/2018 8:21 AM, Don Brutzman wrote:
> [...]
> http://www.web3d.org/specifications/X3dRegularExpressions.html#Design
> http://www.web3d.org/specifications/X3dRegularExpressions.png
> 
> Continuing:
> 
> On 8/6/2018 11:52 AM, Andreas Plesch wrote:
>> Two quick points:
>>
>> The hexadecimal pattern got corrupted. SFImage uses this pattern:
>>
>> 0x([a-f]|[A-F]|\d]){1,8}
>>
>> where \d is the digit character class.
> 
> Thanks, will work on that pattern next.

Currently using 0x[0-9a-fA-F]{1,8} for hexadecimal value, from Regular Expressions Cookbook.

Preliminary pattern for SFImage is there, but also need to allow integers as alternatives for hex values.

>> There are two equivalent +- patterns
>> (\+|\-)?
>> [+|-]?
>> Probably only one should be recommended and used subsequently.
> 
> Good catch, thank you.  Will scrutinize and normalize.

[+-]? for sign and [Ee] for scientific-notation exponent.

>> I have no good idea how to detect a leading 0 0 0 as non-matching. My
>> not so good idea would be to explicitly allow
>> non-0 followed by x x or
>> x followed by non-0 followed by x or
>> x x followed by non-0
>>
>> where non-0 is something [+-]?0?\.?[0-9]*[1-9]+[0-9]*([e|E][+-]?[0-9]+)*
>> and x is a floating point number
>>
>> -Andreas
> 
> Possibly, but am thinking it adds serious complexity that is hard to maintain.  So probably not but will think about it.

It is great when we find those patterns, am trying to keep things maintainable.  The color-coding on web page definitely helps.

Negative lookahead is good for avoiding illegal values, but not allowed in XML Schema (probably to avoid computational denial of service attacks_.  Have listed a pattern nevertheless, other languages/tools might want to use it.

==================
Disallowed values:

* Negative lookahead filters can disqualify attributes that contain illegal values.
* W3C Recommendation for XML Schema (XSD) unfortunately does not support this construct.
* (?!((0|0.0*|.0+)\s+){3}) prohibits 0 0 0 since zero vector is illegal as initial axis triplet of an SFRotation.
* (?!\s*,\s*,) prohibits multiple adjacent commas in intermediate whitespace, for example 0 0 0, ,0 0 0 is an illegal set of MFColor values.
==================

> Thanks for the continuing review!  Very helpful.
Steadily better and better... need to check each regex101 unit test to make sure properly updated.  SF/MFImage are next, then matrix types.

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list