Posted 20 years ago by Jan van de Pol
Avatar
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.

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;
}
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?

Comments (3)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Maybe add a look-ahead that says only accept the { pattern if the next character is not a {.


Actipro Software Support

Posted 20 years ago by Jan van de Pol
Avatar
Thanks for your suggestion.

Tried something with a look-ahead, but then the second '{' became the start of my VBExpression...

Is it possible to recognize '{{' before recognizing a single '{'?
Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You need to define {{ as a pattern in your parent state. That way, the parser will pass by both characters after not recognizing it as a child state transition.


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.