Hi guys, I do have a question about language transition. I spent a lot of efforts to implement JScript.NET language using LLParser and it works fine, with coloring and code completion. To acomplish this we've created dozen classes:
JScriptNETParser : LLParserBase
JScriptNETLexer :MergableLexerBase
...
code completion provider, grammar, etc.
...
JScriptNETSyntaxLanguage: SyntaxLanguage
where constructor register lexer, parse, etc.
It all works perfectly.
Now I have new task to be able to to edit JScript.NET embedded within html/xml inside asp.net <% %> , <%= %>. I've taken
AspStyleTransitionSyntaxLanguage class from samples project as example. Constructor:
string xmlLangPath = "Xml.langdef";
using (Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(xmlLangPath))
{
if (stream != null)
{
SyntaxLanguageDefinitionSerializer serializer = new SyntaxLanguageDefinitionSerializer();
serializer.InitializeFromStream(this, stream);
}
}
// Get the lexer for the parent language
DynamicLexer parentLexer = this.GetLexer() as DynamicLexer;
//jScriptLanguage = new ActiproSoftware.Text.Languages.Xml.Implementation.XmlSyntaxLanguage();
// Get the lexer for the child language
var childLexer = jScriptLanguage.GetLexer() as DynamicLexer;
// Get the classification types that will be used (create and register if necessary)
IClassificationType serverSideScriptClassificationType = AmbientHighlightingStyleRegistry.Instance["ServerSideScript"];
if (serverSideScriptClassificationType == null)
{
serverSideScriptClassificationType = new ClassificationType("ServerSideScript", "Server-Side Script");
AmbientHighlightingStyleRegistry.Instance.Register(serverSideScriptClassificationType,
new HighlightingStyle(Brushes.Black, new SolidColorBrush(Color.FromArgb(0xff, 0xff, 0xee, 0x62))));
// 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
DynamicLexicalState lexicalState = new DynamicLexicalState(0, "ASPDirective");
lexicalState.DefaultTokenKey = "ASPDirectiveText";
parentLexer.LexicalStates.Add(lexicalState);
// 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();
lexicalState.LexicalScopes.Add(lexicalScope);
lexicalScope.StartLexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "ASPDirectiveStartDelimiter", serverSideScriptClassificationType);
lexicalScope.StartLexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"<%="));
lexicalScope.StartLexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"<%"));
lexicalScope.EndLexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "ASPDirectiveEndDelimiter", serverSideScriptClassificationType);
lexicalScope.EndLexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(@"%>"));
// Set up a direct transition on the lexical state so that when it is entered,
// it will transition directly to the child language's default lexical state
lexicalState.Transition = new LexicalStateTransition(jScriptLanguage, childLexer.DefaultLexicalState, null);
}
It did the job. I see that my JScriptNETLexer is triggered within <% %> block , but no parser, no classificationprovider, no completion are triggered. Text withing <% %> is left black color, intelliprompt doesn't work. Is it because I applied your example to programmatic language and not dynamic?
Thanks.
[Modified 12 years ago]