Regular Expression for Ada/IEC 61131-3 Based Literals

SyntaxEditor for WPF Forum

Posted 11 years ago by Andrew Hollom - Senior Software Developer, ABB Motion
Version: 13.1.0311


I'm trying to build a lexer for a prorietary language that uses based literals that include the form <base>#<digits>, so the hexadecimal value "123abc" will be encoded as "16#123abc". The problem I'm having concerns the hash character, which seems to not be recognised by the patterns that I have so far used, listed below.

<RegexPatternGroup TokenKey="HexIntegerNumber" ClassificationTypeKey="Number" LookAheadPattern="{NonWord}|\z">
  <RegexPattern Value="16 # {HexDigit}+" />
  <RegexPattern Value="16 \# {HexDigit}+" />
  <RegexPattern Value="16 \043 {HexDigit}+" />
  <RegexPattern Value="0 [xX] {HexDigit}+" />

I have a feeling that it may be due to the {NonWord} look-ahead pattern, but if this is so, then how should it be encoded?

Many thanks.

Comments (2)

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

Hi Andrew,

It showed up fine for me when I pasted what you had in a language definition here.  My guess is that you are running into an issue with pattern order.  So there is probably some pattern group before this pattern group in your same lexical state that matches numbers at the start.  It's important to note that patterns try to match in the order they are defined, so be sure to adjust your pattern order accordingly.  If you load your language project in our Language Designer, you can use the tester tab to see what token is getting matched at the "16".  That might help you narrow this down.

Actipro Software Support

Posted 11 years ago by Andrew Hollom - Senior Software Developer, ABB Motion

Thanks for that, it was simply that the integer literal pattern was ahead of the based literal pattern, and now I've rearranged the sequencing it works fine.

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.