Understanding Custom Tree Constructor Nodes for Lua Function Calls

SyntaxEditor for WPF Forum

Posted 2 years ago by Will Gauthier
Version: 21.1.3
Avatar

I am customizing the Lua AST I generate with type-specific nodes, but I can't figure out whether one of my productions needs a custom tree constructor node class. A simplified form of the production without all the labels, error handling, etc. is:

functionCallOrAssignmentList.Production = ((@openParenthesis + expression["expr"] + @closeParenthesis) | @identifier["ident"] | @luaFunction["luaFunc"]) + (
identifierAndArguments.OneOrMore().SetLabel("identAndArgs")
| (@comma + variable).ZeroOrMore() + @assignment + expressionList);

If the production matches for a function call by ending in identifierAndArguments.OneOrMore(), I want to create a FunctionCall AST node and set its string name property as appropriate.

There are two complicating factors: I don't know which of the three possible starting matches (expression, identifier, or luaFunction) will be hit, and the presence of multiple identifierAndArguments would indicate nested, consecutive calls (e.g. functionReturningFunction(arg1, arg2)(x)) that I'd want to append to the name as well.

I don't see how to manage all that with the built-in constructors; am I correct that it could be handled with a custom tree constructor node class that runs logic examining the presence, counts, and labels of the matches passed in?

If so, would I want to subclass TreeConstructionNodeBase or ParentTreeConstructionNodeBase? I'm unclear on the difference between them.

Comments (3)

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

Hi Will,

Yes since this is getting pretty complex you do probably want to use a custom tree construction node.  The ParentTreeConstructionNodeBase is mainly if you have child tree construction nodes (perhaps from our built-in ones) that you want to wrap the results around and tweak.  All ParentTreeConstructionNodeBase really does above and beyond TreeConstructionNodeBase is that its constructor takes the params array of child tree construction nodes and makes them available via a Children collection property.  Other than that, it does nothing special.

You may just want to stick with TreeConstructionNodeBase in your scenario.  Then in your node's CreateNode method override, you will be passed a collection of matches for the production.  Each IAstNodeMatch consists of a Label (the string label) in the production and the IAstNode that was generated for it.  You can choose manipulate all that information however you want and programmatically build up the IAstNode result for your CreateNode method.


Actipro Software Support

Posted 2 years ago by Will Gauthier
Avatar

Thanks for the explanation. I've started implementing a TreeConstructionNodeBase, but now I have a follow-up question: how are custom type-specific AST nodes displayed in the LL Parser Debugger's Matches tab?

I can't tell if I'm assigning the right values to the FunctionCall node's string name property because it only appears in the matches tab as the node type name without displaying any of the property values. I've tried overriding the ToString method and hiding the ToTreeString method, but I can't get any additional info to display in that window.

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

Hi Will,

The Matches tab should be listing the IAstNode.Value property value there.


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.