Lexer Issue with numbers

SyntaxEditor for WPF Forum

Posted 1 year ago by Josh
Version: 18.1.0
Platform: .NET 4.6
Environment: Windows 10 (64-bit)
Avatar

Hello,

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}+
{Digit}+

When we use the following look-ahead pattern:

{NonWord}|\z

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"

Identifier="a"

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

GraphicToken = "graphic"

Number = "2"

Identifier="a"

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

Comments (1)

Answer - Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

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 (v22.1.4) 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.