Beginner questions for using ASTNodes

SyntaxEditor Web Languages Add-on for WPF Forum

Posted 8 years ago by matthias kossiek
Version: 11.1.0543
Avatar
We use the WPF Studio with .Net and Web Language Add-ons.
Parsing the SyntaxEditor in ASTNodes is an interesting point for us that might give us the ability to look for Elements/Attibutes in XML and to use their Textranges for copy/replace etc.. in the document.

Til now we parse the xml in Syntax Editor using something like:
XmlParseData parseData = xmlEditor.Document.ParseData as XmlParseData;
and then we add every parseData.Ast (IAstNode) and all Children to a List.

This results in a hierachical list of DefaultAstNodes. So far very nice.
But it would be very nice to have our own AstNode Type in this list. Which contains
only Elements and Attributs etc..

Now my beginner questions:
Is this the right way to access XML Elements in SyntaxEditor and to work with their
Text presentation?
Do you have tutorials describing how to define and integrate selfmade ASTNodes?
Are there any samples for working with xml and XmlParseData?
Do we have to use the Language Designer tool for that?
Simply: What would you recomment how to begin?

Comments (5)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Matthias,

Getting the parse data the way you are from document.ParseData is the correct way to access the AST.

Right now the AST uses DefaultAstNodes. Type-specific AST nodes were added after this add-on was built, and we haven't updated it yet to use those. It may be something we do in the future, but the add-on works fine with DefaultAstNodes so it's not a high priority. Changing to type-specific AST nodes is something we'd have to do, you couldn't really do it externally.

What you can do to filter down which nodes are for elements and attributes is examine the Value property of each node. For instance, each element AST node will have a value of "Element", etc.

Hope that helps!


Actipro Software Support

Posted 8 years ago by matthias kossiek
Avatar
Thank you very much for reply.
Now I know we are on the right way.
Examine the value properties is excactly what we do now.

As you wrote "Type-specific AST nodes were added after this add-on was built" isn`t it possible to get a beta version of this Add-on?
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Matthias,

What I meant was that with all the current builds of SyntaxEditor you can choose to use DefaultAstNode OR type-specific nodes when building a new grammar. Either will work fine. Type-specific AST nodes are a little more work but have a nicer end result.

The Web Languages Add-on still uses DefaultAstNode (since it was built before the type-specific AST node option was added) and we have not done any work to switch it to type-specific nodes at this time. I'll add a TODO item for that but it is a lower priority since the XML language is functioning fine as-is with DefaultAstNode.


Actipro Software Support

Posted 8 years ago by matthias kossiek
Avatar
Hi,
thanks for reply.
Do you have a small sample xml-language project with one or two type-specific ASTNodes?
Or can you give me a little howto to define xml type-specific AstNodes in LanguageDesigner using the sample xml-language project coming with the wpf-studio?
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Matthias,

The documentation for the Language Designer Tool has a topic describing how to build AST nodes with it. We don't have any samples at the moment for doing type-specific AST nodes. We eventually will add a step in the Getting Started series for it.

But regardless, if you are trying to use the Web Languages Add-on, defining your own AST nodes won't really do you any good unless you write your own XML grammar. The built-in grammar currently makes DefaultAstNode instances and it's not easy to swap in type-specific nodes without having the full source of the add-on and rebuilding it, as areas like the grammar and context building code all work off the DefaultAstNodes.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) 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.