Example #1
0
        public static Node CreateNodeFromAST(ASTNode aNode, NodeRegistry registry)
        {
            if (aNode is ASTControlNode)
            {
                var ac  = (ASTControlNode)aNode;
                var ret = registry.GetControl(ac.name).Construct <ControlNode> ();
                ret.lineNumber = ac.lineNumber;

                foreach (var aChild in ac.children)
                {
                    ret.children.Add(CreateNodeFromAST(aChild, registry));
                }
                return(ret);
            }
            else if (aNode is ASTDecoratorNode)
            {
                var ac  = (ASTDecoratorNode)aNode;
                var ret = registry.GetDecorator(ac.name).Construct <DecoratorNode> ();
                ret.lineNumber = ac.lineNumber;

                ret.ReadArgs(ac.args.Select(it => it.objValue).ToList());
                ret.target = CreateNodeFromAST(ac.target, registry);
                return(ret);
            }
            else if (aNode is ASTActionNode)
            {
                var ac  = (ASTActionNode)aNode;
                var ret = registry.GetAction(ac.name).Construct <ActionNode> ();
                ret.lineNumber = ac.lineNumber;

                var args = new Dictionary <string, object> ();
                foreach (var entry in ac.args)
                {
                    args.Add(entry.name, entry.arg.objValue);
                }
                ret.ReadArgs(new ActionNodeArgs(args));
                return(ret);
            }
            else if (aNode is ASTConditionNode)
            {
                var ac  = (ASTConditionNode)aNode;
                var ret = new ConditionNode(ac.condName, ac.arg.type, ac.op, ac.arg.floatValue);
                return(ret);
            }
            else if (aNode is ASTSetConditionNode)
            {
                var ac  = (ASTSetConditionNode)aNode;
                var ret = new SetConditionNode(ac.condName, ac.arg.objValue);
                return(ret);
            }
            else
            {
                throw new Exception("Unknown AST node type " + aNode);
            }
        }
Example #2
0
 NodeRegistry(NodeRegistry parent = null)
 {
     this.parent = parent;
 }