Posted 20 years ago
by Jan van de Pol
![Avatar](https://secure.gravatar.com/avatar/17c1957f80643c67df466f11a517cbba.jpg?s=64&d=identicon&r=g)
Hi,
In my application it is possible to load different type of expressions. Each expression type has it's own Syntaxeditor language. Each language however has the capability of encapsulating a VBExpression between '{' and '}'. For syntaxchecking it uses the VBDotNet.xml syntax language file. The following function adds the VB language to an existing language.My problem is when entering '{{' which must not start a VBExpression but interpreted as an escaped single '{'. The parser is already correct about this behaviour, but I can't get editor to not switch to VB mode. Anyone have a suggestion?
In my application it is possible to load different type of expressions. Each expression type has it's own Syntaxeditor language. Each language however has the capability of encapsulating a VBExpression between '{' and '}'. For syntaxchecking it uses the VBDotNet.xml syntax language file. The following function adds the VB language to an existing language.
private static void AddEmbeddedVBNet( SyntaxLanguage language )
{
SyntaxLanguage lngVB = LoadLanguage( "VBDotNet.xml" );
AddReferenceTriggers( lngVB );
language.IsUpdating = true;
// Add a highlighting style
language.HighlightingStyles.Add( new HighlightingStyle( "ExpressionDelimiterStyle", null, Color.Black, Color.Yellow, false, false, false ) );
// Create a new lexical state
LexicalState defaultState = new LexicalState( "ExpressionDirectiveState" );
defaultState.DefaultTokenKey = "ExpressionDirectiveDefaultToken";
defaultState.DefaultHighlightingStyle = language.HighlightingStyles[ "DefaultStyle" ];
defaultState.LexicalStateTransitionLexicalState = lngVB.LexicalStates[ "DefaultState" ];
language.LexicalStates.Add( defaultState );
// Add the new lexical state at the beginning of the child states...
// Remember that with an NFA regular expression, the first match is taken...
// So since a < scope pattern is already in place, we must insert the new one before it
language.LexicalStates[ "DefaultState" ].ChildLexicalStates.Insert( 0, defaultState );
// Create a lexical scope with a lexical state transition
LexicalScope lexicalScope = new LexicalScope();
defaultState.LexicalScopes.Add( new LexicalScope() );
defaultState.LexicalScopes[0].StartLexicalPatternGroup =
new LexicalPatternGroup( LexicalPatternType.Explicit, "ExpressionStartToken",
language.HighlightingStyles[ "ExpressionDelimiterStyle" ], "{" );
defaultState.LexicalScopes[0].EndLexicalPatternGroup =
new LexicalPatternGroup(LexicalPatternType.Explicit, "ExpressionEndToken",
language.HighlightingStyles["ExpressionDelimiterStyle"], "}" );
language.IsUpdating = false;
}