DynamicLexicalPattern Types and Details

SyntaxEditor for WPF Forum

Posted 7 years ago by Ryan Howard
Version: 13.1.0580
Avatar

Hi,

Can someone point me to a tutorial like page that goes over how to create specific types of DynamicLexicalPatterns? I've done a ton of stuff with the grammer and the lexer, but really need to create something specific, and don't quite understand how it works.

Right now if I want to add something like a keyword, I can add something like this:

lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("FROM"));

 

While the default Identifier pattern looks something like this:

lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("(_ | {Alpha})({Word})*"));

 

What I need to know is how the pattern works, because it looks like it almost follows a regex style format, but not totally. I need to create a patter that would match something like this:

"AnyWordOrNumber.AnyWordOrNumber" - With the period in the middle.

 

Thanks,

Ryan

Comments (5)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ryan,

The DynamicLexicalPatternGroup object has a PatternType property that lets you say whether it is Explciit or Regex.  Explicit means that the exact text should be used as you specify it in patterns (with the pattern group's case sensitivity option taken into account).  Regex means interpret the pattern as a regular expression.

So your "FROM" should only be added to an Explicit pattern group.  The Identifier pattern should only be added to a Regex pattern group.  There is a full guide in the documentation on the regex pattern syntax.

For your desired pattern, if it was in a regex pattern group, you could do something like:

{Word}\.{Word}


Actipro Software Support

Posted 7 years ago by Ryan Howard
Avatar

Ahh that makes perfect sense, thanks! However with the "{Word}\.{Word}" pattern, it doesn't seem to work. Depending on the pattern, it either doesn't work, or it blows up on load. Weird. I've tried bunches of different variations, and none work. Any other suggestions?

lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"({Word})(\.)({Word})"));

lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"({Word})({\.})({Word})"));
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"{Word}\.{Word}"));
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("({Word}).({Word})"));
lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[a-z0-9_-]\\.[a-z0-9_-]"));

It just doesn't seem to want to accept the period between two words(something.something).

Thanks,

Ryan

[Modified 7 years ago]

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Sorry I think I forgot to put the quantifiers in there.  That would be a problem since it would just look for one word character, then period, then another word character.  Try this instead:

({Word})+ \. ({Word})+


Actipro Software Support

Posted 7 years ago by Ryan Howard
Avatar

Yeah I'm not sure what I'm doing wrong anymore, and I've done regex in the past....maybe it doesn't like my '@' at the beginning of the string? It does require it though to escape the backslash..it still fails by giving the red squiggily on "something.something"

 

lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"({Word})+ \. ({Word})+"));

 

Thanks,

Ryan

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ryan,

I'm not sure without being able to have something to debug.  Did you try using the Language Designer to build your dynamic lexer?  The benefit of doing it there is that you don't need to worry about escaping C# characters and it even has a Live Test tab where you can see how it's tokenizing text.  Maybe that would help you out here.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.