Lexer Issue with numbers

SyntaxEditor for WPF Forum

Posted 2 years ago by Josh
Version: 18.1.0
Platform: .NET 4.6
Environment: Windows 10 (64-bit)


We have the following lexical regex pattern for numbers (int and reals):

(these patterns and look-ahead we are using from the samples)

{Digit}* \. {Digit}+ ([Ee] [\+\-]? {Digit}+)?
{Digit}+ [Ee] [\+\-]? {Digit}+

When we use the following look-ahead pattern:


And trying to get tokens with the following code:

graphic 2a

We never get a number token, just a "default" token.

We get the following tokens (ignoring whitespace)

GraphicToken = "graphic"

Default = "2"


However, if we remove the look-ahead, we get the following tokens, which seems correct:

GraphicToken = "graphic"

Number = "2"


Is this working as intended?  What is the look-ahead actually doing?

Comments (1)

Answer - Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA


Yes that is working as intended.  The look-ahead pattern "{NonWord}|\z" is saying the character following the number pattern must be a non-word character (i.e. not a letter) or must be document end.  Since you don't have a space or other non-word character between the "2" and "a" characters, the lexing fails to complete a match on "2" due to the look-ahead not passing. 

That particular look-ahead is generally used to ensure identifiers and numbers are delimited from other identifiers and numbers that may follow right after.  I hope that explains it.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.