Regular Expression limitation?

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Jason Whitted - Owner, Etalisoft, LLC
Avatar
SyntaxEditor 3.1.202.0, .NET 2.0, Windows XP
The language I am working on uses square brackets for comments. Unfortunately, the language allows nested comments, which with most Regex parsers this would be practically impossible, but .NET supports some advanced grouping constructs which should make this work.

I created the following regular expression:
\[
(?>
   [^\[\]]+
   |
   \[(?<depth>)
   |
   \](?<-depth>)
)*
(?(depth)(?!))
\]
Then in Regular Expression Workbench (which is a great utility if anyone hasn't seen it before) I set it up to "Ignore Whitespace" and put in the following text:
This is some text
[ This is a comment [ which has [ embedded ] comments ] inside of it ]
This is some more text
After executing the regular expression it matches (as desired):
[ is a [ comment with [ several [ imbedded ] comments ] inside ] of ]
However, when I try to use the regular expression as a RegexPatternGroup I get the following error:
ActiproSoftware.SyntaxEditor.InvalidRegexPatternException: Unknown regular expression advanced grouping construct.
The error occurred in the lexical pattern group for token 'TestToken' in the pattern '\[(?>[^\[\]]+|\[(?<depth>)|\](?<-depth>))*(?(depth)(?!))\]'.
   at ActiproSoftware.SyntaxEditor.LexicalPatternGroup._1()
   at ActiproSoftware.SyntaxEditor.LexicalState._1()
   at ActiproSoftware.SyntaxEditor.LexicalState._1(StringBuilder , Int32& , Int32 , LexicalPattern& )
   at _23._1(SyntaxLanguage , StringBuilder , Int32& , Int32 , _22 , Token , Int32 )
   at ActiproSoftware.SyntaxEditor.Document._1(DocumentModification )
   at ActiproSoftware.SyntaxEditor.Document.set_Text(String value)
   at ActiproSoftware.SyntaxEditor.Document.LoadFile(String path)
Any way around this, or am I out of luck?

Comments (1)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jason,

While we support almost all of the same constructs as the .NET regex library does, we don't support named captures in lexical parsing which is what you're doing here. I'll write this down as a possible enhancement or maybe with the parsing improvements we're going to do for our 4.0 version, we'd be able to support this better.

For the latter, it would help if you could email us with some info on the language that you're designing. That way we can try and make sure we accommodate these sort of gotchas that don't appear in most other languages.


Actipro Software Support

The latest build of this product (v24.1.1) 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.