InvalidRegexPatternException: Unquoted string did not contai

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by Steven Liu
Avatar
I defined following end scope pattern:
PatternValue="\n" LookAhead="(( *\n)|(#IF.*\n))*SECTION"
Basically I want to look ahead to next SECTION keyword and possibly one or multiple #IF lines, to terminate current scope.
I can load the syntax file in Language designer, but cannot load a document. It throws an exception box:
InvalidRegexPatternException: Unquoted string did not contain any characters

Complete text:

************** Exception Text **************
ActiproSoftware.SyntaxEditor.InvalidRegexPatternException: Unquoted string did not contain any characters.
at ᐩ.ᐁ(Int32 )
at ᐩ.ᐁ(Int32 , Int32 , Boolean )
at ᐩ.ᐁ(Int32 , Int32 , Boolean )
at ᐩ.ᐁ(Int32 , Int32 , Boolean )
at ActiproSoftware.SyntaxEditor.LexicalPatternGroup.ᐁ()
at ActiproSoftware.SyntaxEditor.LexicalPattern.ᐁ(TextStream )
at ᐚ.ᐁ(SyntaxLanguage , TextStream , ᐙ , Token , Int32 )
at ActiproSoftware.SyntaxEditor.Document.ᐁ(DocumentModification )
at ActiproSoftware.SyntaxEditor.Document.ᐁ(DocumentModificationType , Int32 , Int32 , String )
at ActiproSoftware.SyntaxEditor.Document.UndoableInsert(DocumentModificationType type, Int32 offset, Int32 length, String text)
at ActiproSoftware.SyntaxEditor.EditorView.ᐁ(DocumentModificationType , String )
at ActiproSoftware.SyntaxEditor.EditorView.ᐁ(String )
at ActiproSoftware.SyntaxEditor.EditorView.InsertText(String text)
at ActiproSoftware.SyntaxEditor.Document.ᐁ(Char )
at ActiproSoftware.SyntaxEditor.SyntaxEditor.OnKeyPress(KeyPressEventArgs e)
at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Comments (4)

Posted 15 years ago by Steven Liu
Avatar
I tried following LookAhead pattern as a workaround:
PatternValue="\n" LookAhead="[ \n]*(#IF[^ \n]*)?[ \n]*SECTION"

It works, as a partial solution which only deals with a single #IF line.
I still would like to have a pattern that matches zero or any number of #IF lines.

Maybe nested * in regex pattern cause problems?

As a side note, I really like the powerful lookahead feature, which opens a lot of possibilities to the developer. But sometimes this blessing could become a trouble since it allows usages that was not originally thought of by the author.

Steven
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Remember that with regexs, whitespace needs to be quoted or put in a character class for use. Otherwise it is treated as a delimiter of regex tokens. In your first example you had ( *\n) and since the * had nothing to operate on, it raised the exception. You could have put quotes around the space to make that work.

Here's a pattern I came up with for you that seems to do what you want:
(({WhitespaceMacro}* \n) | ("#IF" .* \n))* "SECTION"
Make sure you convert the double-quotes to " if you put it in XML.

[ 06-14-2004: Message edited by: Actipro Software Support ]


Actipro Software Support

Posted 15 years ago by Steven Liu
Avatar
I added [] around space and it works!
Thanks for the tip. I didn't know your regex engine treats space differently.

Thanks to the LookAhead feature, now I can create even more complex LookAhead pattern which takes more things into consideration: next SECTION keyword, comments, and #IF lines. It behaves as I expected.

Steven
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Just FYI... our regex engine acts as if you had the IgnorePatternWhitespace flag set in the .NET regex engine.


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.