Beispiel #1
0
        public XmlElement Visit(BlockParseNode bpn)
        {
            var el = makeNode(bpn, "block");

            addProperty(el, "parameters", bpn.Parameters);
            addProperty(el, "body", bpn.Body);
            return(el);
        }
Beispiel #2
0
 /// <inheritdoc/>
 public virtual ParseNode Visit(BlockParseNode bpn)
 {
     foreach (var p in bpn.Parameters)
     {
         p.Visit(this);
     }
     foreach (var s in bpn.Body)
     {
         s.Visit(this);
     }
     return(bpn);
 }
Beispiel #3
0
        /// <inheritdoc />
        public Node Visit(BlockParseNode d)
        {
            var  parameters    = new List <Node>();
            Node forcedPattern = null;

            foreach (ParseNode p in d.Parameters)
            {
                var id    = p as IdentifierParseNode;
                var tppn  = p as TypedParameterParseNode;
                var vappn = p as VarArgsParameterParseNode;
                if (id != null)
                {
                    parameters.Add(new ParameterNode(id.Token, id));
                }
                else if (tppn != null)
                {
                    parameters.Add(
                        new ParameterNode(tppn.Token,
                                          tppn.Name as IdentifierParseNode,
                                          tppn.Type.Visit(this)));
                }
                else if (vappn != null)
                {
                    // Inside could be either an identifier or a
                    // TypedParameterParseNode - check for both.
                    var inIPN  = vappn.Name as IdentifierParseNode;
                    var inTPPN = vappn.Name as TypedParameterParseNode;
                    if (inIPN != null)
                    {
                        parameters.Add(new ParameterNode(inIPN.Token,
                                                         inIPN,
                                                         true // Variadic
                                                         ));
                    }
                    else if (inTPPN != null)
                    {
                        parameters.Add(new ParameterNode(inTPPN.Token,
                                                         inTPPN.Name as IdentifierParseNode,
                                                         true, // Variadic
                                                         inTPPN.Type.Visit(this)
                                                         ));
                    }
                }
                else if (p is NumberParseNode || p is StringLiteralParseNode ||
                         p is OperatorParseNode)
                {
                    parameters.Add(p.Visit(this));
                }
                else if (p is ParenthesisedParseNode)
                {
                    var tok = p.Token;
                    var it  = new IdentifierToken(tok.module, tok.line,
                                                  tok.column, "_");
                    id = new IdentifierParseNode(it);
                    parameters.Add(new ParameterNode(tok, id, p.Visit(this)));
                }
                else
                {
                    throw new Exception("unimplemented - unusual parameters");
                }
            }
            var ret = new BlockNode(d.Token, d,
                                    parameters,
                                    map(d.Body),
                                    forcedPattern);

            return(ret);
        }