Can the AST tree be modified?

SyntaxEditor for WPF Forum

Posted 5 years ago by Aernout van Groen
Version: 14.1.0602
Avatar

Hi

Can the AST structure be modified after it has been built by the parser?

It seems that the Children property of an AST-node (inheriting from AstNodeBase) is a copy of the underlying children.
Adding nodes to that list has no effect on the actual children.

What I wanted to do is replace one AST-node with another.  Is there a way to accomplish this?

Regards
Aernout

Comments (2)

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

Hi Aernout,

How are you building your AST nodes?  We generally either use our DefaultAstNode (which is a simple generic node with string value and supports children), or we use the Language Designer to design the AST nodes and code generate them.  It's very easy to do so and the nodes it makes will have type-specific properties and it can make modifiable collections.  The third option is to just implement IAstNode yourself but that's more work than the other two ways.

I would highly recommend letting the Language Designer build nodes for you if you are making type specific nodes.  It makes nodes that inherit AstNodeBase.  It effectively adds various collection properties and then overrides GetChildrenEnumerator to return a yield of all the collection property items.  Since Children just calls that enumerator method, that's why modifying Children does nothing.


Actipro Software Support

Posted 5 years ago by Aernout van Groen
Avatar

Ok, then I will create a custom collection that I can modify with the Language Designer.
Thank you for your reply.

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.