SyntaxEditor - ASP-Style Server Tags with IntelliPrompt

by Avatar Bill Henning (Actipro)
Friday, February 13, 2015 at 1:25pm

PostBannerSyntaxEditorDevNotes

We've had a lot of customers throughout the years ask us for a sample that could show how to harness our SyntaxEditor .NET Languages Add-on and its automated IntelliPrompt within an ASP-style server tag context.  This is especially useful for any sort of template generating scenario.

We had an internal sample that we would send customers upon request, but several months back, we cleaned it up, enhanced it, and added it as a new QuickStart sample.  In this post, let's have a look at the QuickStart sample that was added to the SyntaxEditor for (WPF, Silverlight, and WinRT/XAML platforms) in the 2014.2 version showing how to achieve automated IntelliPrompt within ASP-style server tags.

Usage Example

In the animated presentation below, you can see how there is a basic parent language whose lexer only knows to tokenize and color the word "date" as a keyword.  In real-world usage, the lexer could be made to fully colorize the text like normal.  The lexer has hooks that cause a transition to the C# language found in our .NET Languages Add-on when ASP-style delimiters are encountered.

SyntaxEditorServerTags

Both <% %> and <%= %> style tags are shown in this example.  What happens behind the scenes is that the parent language's parser will code generate C# code.  It will make a C# class named "__Generated" and a method named "__WriteOutput".  All the text of the parent language is output within "Response.Write" method calls.  C# code in the server tags is injected directly.  The resulting full C# code is placed in a separate in-memory document and parsed.  Finally the resulting parse data is returned, along with mapping data to know how offsets between the server tag range in the source document and those in the parsed C# document align.

Then there are several customized C# IntelliPrompt providers that know how to use that mapping data and translate offsets so that automated IntelliPrompt is fully functional within the server tag regions of the main source document, yet based on the generated C# code.

Tricky stuff, but it works great!

Summary

The full source sample described above was added in the first v2014.2 release of our WPF, Silverlight, and WinRT/XAML controls and is available for you to check out.

TaskDownload TaskLiveDemo TaskBuyNow

Actipro's WPF Controls

Over 100 UI controls for building beautiful Windows Presentation Foundation desktop apps.

Learn More

Over 100 UI controls for building beautiful Windows Presentation Foundation desktop apps.

Includes editors, docking windows, MDI, property grids, charts, tree controls, ribbons, gauges, themes, and much more.

Learn More Download Free Trial

Add Comment

Please log in to a validated account to post comments.