How to handle an escaped string delimiter?

SyntaxEditor for Windows Forms Forum

Posted 19 years ago by shark92651
Avatar
I have a MySQL script that contains an embedded single-quote character in the string. MySQL allows you to escape that character with a backslash but my language definition does not know how to deal with it and is highlighting the entire rest of the script as a comment. Any ideas how to deal with this?

Here is an example:

INSERT INTO mytable VALUES (1, 'The embedded string\'s escaped quote');

Comments (3)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Check our our C# sample language def for the strings there. It shows how to do escape characters.


Actipro Software Support

Posted 19 years ago by shark92651
Avatar
I guess it's in there somewhere but I have to admit my knowledge of regular expressions and how to define this type of syntax in the language definition is somewhat limited. Can you give an example of how this would be accomplished?

I see this sort of syntax in the C# defintion but not sure how I would adapt this to allow the \' to be considered part of the string and not a string delimiter itself:


<State Key="StringState" Token="StringDefaultToken" Style="StringDefaultStyle">

<Scopes>
<Scope>
<ExplicitPatternGroup Type="StartScope" Token="StringStartToken" Style="StringDelimiterStyle" PatternValue="&quot;" />
<RegexPatternGroup Type="EndScope" Token="StringEndToken" Style="StringDelimiterStyle" PatternValue="[\&quot;\n]" />
</Scope>
</Scopes>

<PatternGroups>
<RegexPatternGroup Token="StringEscapedCharacterToken" PatternValue="\\x {HexDigitMacro}{1,4}" />
<RegexPatternGroup Token="StringEscapedCharacterToken" PatternValue="\\u {HexDigitMacro}{4,4}" />
<RegexPatternGroup Token="StringEscapedCharacterToken" PatternValue="\\U {HexDigitMacro}{8,8}" />
<RegexPatternGroup Token="StringEscapedCharacterToken" PatternValue="\\." />
<RegexPatternGroup Token="StringWhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />
<RegexPatternGroup Token="StringWordToken" PatternValue="\w+" />
<RegexPatternGroup Token="StringDefaultToken" PatternValue="[^\&quot;\n]" />
</PatternGroups>
</State>
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You'd probably do something like this (haven't tested it but I think it's correct):

<State Key="StringState" Token="StringDefaultToken" style="StringDefaultStyle"> 
<Scopes> 
<Scope> 
<ExplicitPatternGroup Type="StartScope" Token="StringStartToken" Style="StringDelimiterStyle" PatternValue="'" /> 
<RegexPatternGroup Type="EndScope" Token="StringEndToken" Style="StringDelimiterStyle" PatternValue="['\n]" /> 
</Scope> 
</Scopes> 
<PatternGroups> 
<RegexPatternGroup Token="StringEscapedCharacterToken" PatternValue="\\'" /> 
<RegexPatternGroup Token="StringWhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" /> 
<RegexPatternGroup Token="StringWordToken" PatternValue="\w+" /> 
<RegexPatternGroup Token="StringDefaultToken" PatternValue="[^'\n]" /> 
</PatternGroups> 
</State>


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.