InvalidRegexException problem

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by Richard Matthias
Avatar
Hi, I'm currently evaluating SyntaxEditor and I've spent some time putting together a language definition for the langauge I need to edit. I've got the definition to load but as soon as I type anything I get the exception below:-

An unhandled exception of type 'ActiproSoftware.SyntaxEditor.InvalidRegexPatternException' occurred in actiprosoftware.syntaxeditor.dll

Additional information: Unexpected end in regular expression quoted string.


There is no information on which regex is causing the problem though. Is there a way to find out? I can post the language file if necessary.

Comments (3)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It sounds like you have a quoted string in a pattern your language definition. So since it's XML format, look for any instances of " and make sure that they all are terminated in a pair. If you still can't find it after looking, email it to us.


Actipro Software Support

Posted 19 years ago by Richard Matthias
Avatar
That particular problem turned out to be where I'd copied the StringState from the CSharp grammar but I'd changed the StringLiteralStartToken line to be a RegexPatternToken element because I wanted to have an optional 'L' infront of the double quote so I had "[L]?"" As you can see I needed a backslash infront of the " to make it work.

That wasn't the only problem I had though. I got another weird exception with no help at all. I'd converted some regexs from a lex file and ended up with this rule

<RegexPattern Value="{LSL-D-Macro}*\.{LSL-D-Macro}+({LSL-E-Macro})?{LSL-FS-Macro}?" />

Turns out it needs parenthesis around all the lexical macros where they are followed by + * or ? modifiers. Or maybe it depends on what's in the macro. It gives an exception with the message:-

An unhandled exception of type 'ActiproSoftware.SyntaxEditor.InvalidRegexPatternException' occurred in actiprosoftware.syntaxeditor.dll
Additional information: An invalid character 'L' was found in the range specification following '_30'.

So I have a couple of suggestions which are that the documentation on regexes needs to be expanded a bit as there appear to be subtle differences between from how they work in lex (and I'm sure a lot of people base their editor support on the front-ends of real compilers written using tools like lex).

Also, where exceptions are thrown at runtime due to errors in regexes there needs to be some indication of what rule caused the error by including the TokenKey or other attribute in the exception message. I could only find the errors by taking a backup and then deleting sections of the file until the problem went away.

Anyway, I've got the basic syntax highlighting working now. I'll post another comment if I have any trouble getting the intellisense working :)
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok, this next maintenance release will have improved error messages that tell you exactly what pattern and in what pattern group had the error.

For the case with macros, the { character can be either a quantifier {min,max} or a macro depending on context. If it immediately follows another regex element, it will be interpreted as a quantifier. If there is a space before it or if it is grouped (with parenthesis), it will be interepreted as a macro.

Hope that helps!


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.