Question

Using Regex look-around in LexicalPatternGroup

Posted 7 years ago by Avatar ori
Hello,

I tried several options but just could not do it. I want to create a lexical state for a sub language.
Start delimiter is '['
End delimiter is ']'

I also want to support escape char - when the '\' sign is before the end delimiter I want the end delimiter to be a normal token in the language.

I tried:
new LexicalPatternGroup(LexicalPatternType.Regex, "EndToken",
                                    language.HighlightingStyles["DelimiterStyle"],
                                    "(?<!\\\\)]");

Thanks.

Comments (8)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Offhand I think it would be something like: "(?<! \\) \]"

Or you can do like we do in many of the string states in our languages where double quotes are the delimiters and \" are escape characters. The dynamic C# language and many others show this.

Actipro Software Support
Posted 7 years ago by ori
I tried it but it doesn't work. I also tried to look at the other option - but I don't get what I have to do... can you please explain. I'm using code to build a dynamic language - I'm not using a syntax file
Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
My recommendation would be to write you language and get it working in the dynamic language XML format. Just so you can get the patterns correct. Then take that code and translate it to code if needed. It will be much easier to debug if you work with the XML format, plus you can copy/paste from our code samples for similar concepts this way.

Actipro Software Support
Posted 7 years ago by ori
Hello,

I looked at it, but it did not help. I think there is an internal problem, and the documentation on the LexicalPatternGroup constructor does not explain the difference between the 'pattern' parameters and the 'lookAheadPattern' parameter.

I used the code from the example project (dynamic language, xml and c#) and changed the separators to '[' and ']'

this code works, but with look-ahead instead of look-behind:
lexicalScope.EndLexicalPatternGroup =
                new LexicalPatternGroup(LexicalPatternType.Regex, "EndToken",
                    language.HighlightingStyles["DelimiterStyle"], "](?!\\\\)");
if I change the pattern from "](?!\\\\)" to "](?<!\\\\)" I get an error during the syntax highlighting: "Op code not implemented: 11"

Thanks,
Ori

[Modified at 08/13/2007 02:32 AM]

[Modified at 08/13/2007 02:33 AM]
Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Here's what I did... went into DynamicallyCreateForm in the sample project, in the CreateDirectiveXmlToCSharpLanguage method, and updated the code for the end lexical pattern group to be:
lexicalScope.EndLexicalPatternGroup = 
    new LexicalPatternGroup(LexicalPatternType.Regex, "ASPDirectiveEndToken", 
        language.HighlightingStyles["ASPDirectiveDelimiterStyle"], "](?!\\\\)");
When I ran it, I didn't have any problems and everything worked correctly. If you think there is a bug in the latest maintenance release then please do those same steps and post the steps when typing in the SDI editor to repro it. Thanks!

Actipro Software Support
Posted 7 years ago by ori
it works for me too. The problem occurs when you change the look-ahead "](?!\\\\)" pattern to look-before pattern: "](?<!\\\\)");
Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Sorry I misread your post, yes there does appear to be a bug here. I'll add it to the TODO list. Thanks!

Actipro Software Support
Posted 7 years ago by ori
Thanks. If you find a solution for it it the current version please write it here.
Information The latest build of this product (2014.1 build 0321) was released 1 month ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.