Posted 19 years ago
by Jason Whitted
-
Owner,
Etalisoft, LLC
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: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:
After executing the regular expression it matches (as desired):
However, when I try to use the regular expression as a RegexPatternGroup I get the following error:
Any way around this, or am I out of luck?
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)(?!))
\]
This is some text
[ This is a comment [ which has [ embedded ] comments ] inside of it ]
This is some more text
[ is a [ comment with [ several [ imbedded ] comments ] inside ] of ]
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)