The Actipro Blog

All the latest UI control development news from Actipro

Progress on a SyntaxEditor Web Languages Add-on for WPF and Silverlight

As mentioned in a previous post we have been working very hard on developing a custom grammar and AST object model that will be an optional free part of SyntaxEditor for WPF/Silverlight products going forward, hopefully starting with the 2010.2 version.

We’ve been using this new grammar/AST design to prototype out a WPF version of an advanced XML syntax language implementation.  The XML language will eventually contain the same or better feature set as those found in the WinForms Web Languages Add-on.

Today I’d like to give a quick glimpse into some initial features we have working.

AST (abstract syntax tree) construction

Our new grammar has a tree construction syntax that makes it very easy to create an AST of a document.  Take this XML code for example…

Valid

The grammar parser we built for XML will construct an AST that looks like this when output to a string:

CompilationUnit[
    Element[
        "a"
        Nodes[
            Element[
                "b"
                Nodes[
                    Comment[]
                ]
                EndTag[]
            ]
        ]
        EndTag[]
    ]
]

Each node in the AST automatically gets assigned an offset range based on what generated it, which becomes important when we get into features below such as code outlining

Parse error reporting

As the XML parser (which runs based on our XML grammar) executes, it will report errors if it detects any.  You also can inject code to report your own errors when appropriate.

Take this example code that is invalid XML:

SyntaxErrors

You’ll see that errors are automatically marked with squiggles.  The specific parse errors can be listed in an Error List tool window.  If we would show the errors, we’d see:

  • Tag was not closed. (1,5)
  • Expecting end tag </b>. (1,9)

Both of those are parse errors we insert when we detect invalid XML.

Code outlining (folding)

One of the best features of having an AST that stores location data is that you can use it to drive code outlining.  Here is some example XML loaded in SyntaxEditor:

Outlining

We have a custom outliner that takes our AST data and converts it to outlining node ranges.  If we collapse the somevalue element, we see:

OutliningCollapsed

You can mouse over the collapsed block to see the collapsed text.  Also if attributes were set on the start tag, the first line of them would show up before the … in the collapsed text.

Summary

This is just the beginning for the actual add-on.  We still need to add a number of other features such as validation and automated IntelliPrompt.  But with the grammar/AST features that we’re developing, we finally have the tools available to implement those features.

It’s important to note that all of what you see here is built using the public SyntaxEditor object model along with the new grammar/AST features that will also be public.  This means that you are able to build similar syntax language implementations for your own languages too.

We’ll post some more information as development progresses.

Pingbacks and trackbacks (1)+

Comments are closed