This project has moved and is read-only. For the latest updates, please go here.

Missing AST Nodes

Aug 27, 2011 at 1:16 AM
Edited Aug 27, 2011 at 1:18 AM

I have a Grammar defining a few custom AST nodes for our scripting language.


When I call parsetree.Root.AstNode.GetAll(), the IEnumerable<AstNode> returns a big array of nodes, but doesn't include all of them. I've put a break point in the Init for one of the Node types I've defined with nodes missing and see that the node is being created. I can trace it up to ExecuteReduce pushing it onto the ParserStack. Perhaps maybe it's a child of another of my custom AST nodes, is there much needing to be done here? 


Any ideas why it wouldn't turn up in the GetAll()?


Here is my AstNode


public class ScriptCallNode : AstNode, ICallTarget
	public IdentifierNode NameNode;
	public ScriptFileNameNode SourceNode;

	public override void Init(ParsingContext context, ParseTreeNode treeNode)
		base.Init(context, treeNode);
		if (treeNode.ChildNodes.Count > 2)
			SourceNode = AddChild("Source", treeNode.ChildNodes[0]) as ScriptFileNameNode;
			NameNode = AddChild("Name", treeNode.ChildNodes[2]) as IdentifierNode;
			NameNode = AddChild("Name", treeNode.ChildNodes[0]) as IdentifierNode;
			SourceNode = null;
		AsString = "<ScriptCall " + NameNode.AsString + ">";

The ScriptFileNameNode is another custom one to represent a partial path.
Aug 27, 2011 at 3:14 AM

I think the problem is that AST node is created (and you see it pushed into Stack), but it's not added to Parent's ChildNodes list. This happens in Init method of the parent. Init method you show does this for it's 2 child nodes - SourceNode and NameNode. Trace if this ever happens for your custom nodes (that they are added to the parent's list ChildNodes)


Aug 29, 2011 at 7:41 PM

Thanks as always Roman,


You were right. The node above it in the tree was a FunctionCallNode which wasn't correct and wasn't adding what needed to be added to it's ChildNodes. Changing it to the more generic ExpressionListNode type meant everything was added correctly.