Language transition using WPF Syntax Editor

SyntaxEditor for WPF Forum

Posted 10 years ago by John Athanasoulopoulos
Version: 13.2.0592

We evaluate your product and we are trying to set up a fully functionall language transition project using Syntax Editor. Our markup content is XHTML with javascript tags and asp-like tags (<@ @>).  We managed to have coloring into <script></script> block , but no parser, no classification provider, no completion are triggered,  intelliprompt doesn't work.

We did many experiments so far and we need your help.

We use code from Actipro Software\WPF-Controls\v13.2.0592\SampleBrowser\ProductSamples\SyntaxEditorSamples\QuickStart\CodeOutliningRangeBased\ sample for JavascriptLanguage class.

We want to include your product to our solution and this issue is very important to be solved in order to proceed.

Is the above scenario possible to work?  Please give us your directions. If you could provide us a working sample would be much better.



namespace LanguageTransitions {

/// <summary>
/// Represents a <see cref="SyntaxLanguage"/> for XML that has a tag-style language transition to C#.
/// </summary>
public class TagStyleTransitionSyntaxLanguage : XmlSyntaxLanguage {


/// <summary>
/// Initializes a new instance of the <see cref="ASPStyleTransitionSyntaxLanguage"/> class.
/// </summary>
public TagStyleTransitionSyntaxLanguage() {

SyntaxLanguage JavaScriptLanguage = new ActiproSoftware.ProductSamples.SyntaxEditorSamples.QuickStart.CodeOutliningRangeBased.JavascriptSyntaxLanguage();

// Get the lexer for the parent language
DynamicLexer parentLexer = this.GetLexer() as DynamicLexer;

// Get the lexer for the child language
DynamicLexer childLexer = JavaScriptLanguage.GetLexer() as DynamicLexer;

// Get the classification types that will be used (they were already registered by the XML language load)
IClassificationType xmlNameClassificationType = AmbientHighlightingStyleRegistry.Instance["XmlName"];
IClassificationType xmlDelimiterClassificationType = AmbientHighlightingStyleRegistry.Instance["XmlDelimiter"];

// Since we will be dynamically modifying the parent lexer, wrap it with a change batch
using (IDisposable batch = parentLexer.CreateChangeBatch()) {
// Create a new transition lexical state in the parent language that will serve as the bridge between the two languages...
// Add child states similar to the XML's 'StartTag' state so that attributes are allowed in the 'script' tag
DynamicLexicalState lexicalState = new DynamicLexicalState(0, "ScriptStartTag");
lexicalState.DefaultTokenKey = "StartTagText";
lexicalState.DefaultClassificationType = xmlNameClassificationType;

// Insert the transition lexical state at the beginning of the parent language's
// default state's child states list so that it has top matching priority
parentLexer.DefaultLexicalState.ChildLexicalStates.Insert(0, lexicalState);

// Create the lexical scope for the transition lexical state
DynamicLexicalScope lexicalScope = new DynamicLexicalScope();
lexicalScope.StartLexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "StartTagStartDelimiter", xmlDelimiterClassificationType);
lexicalScope.StartLexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"<"));
lexicalScope.StartLexicalPatternGroup.LookAheadPattern = @"script";
lexicalScope.EndLexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "StartTagEndDelimiter", xmlDelimiterClassificationType);
lexicalScope.EndLexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"/? >"));

// Create a second lexical scope that will be transitioned into as soon as the first lexical scope
// is exited (after the '<script>' tag)... this second scope indicates the child language's
// lexical state to transition into along with the pattern group that will be used to exit
// back out to the parent language
DynamicLexicalScope transitionLexicalScope = new DynamicLexicalScope();
transitionLexicalScope.EndLexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "EndTagStartDelimiter", xmlDelimiterClassificationType);
transitionLexicalScope.EndLexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"</"));
transitionLexicalScope.EndLexicalPatternGroup.LookAheadPattern = @"script";
lexicalScope.Transition = new LexicalStateTransition(JavaScriptLanguage, childLexer.DefaultLexicalState, transitionLexicalScope);


// Register the schema resolver service with the XML language (needed to support IntelliPrompt)
XmlSchemaResolver resolver = new XmlSchemaResolver();


public static Stream ToStream(string str)
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
stream.Position = 0;
return stream;

Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA

Hi John,

Thanks for evaluating SyntaxEditor.  Can you write our support address directly and reference this post since we likely will need to get more detail from you and possibly trade source code.  Thanks!

Actipro Software Support

The latest build of this product (v24.1.1) was released 6 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.