private static ExpressionNode ParseArrayInitialization(RuleContext rule)
        {
            // An array initialization is the call of a typeNode's constructor

            TypeNode             type            = ParseTreeParser.ParseType((CrawlParser.TypeContext)rule.GetChild(0));
            ArrayConstructorNode typeConstructor = CrawlSyntaxNode.ArrayConstructor(type.Interval, CrawlType.UnspecifiedType, type);
            // TypeConstructorNode is an ExpressionNode that corresponds to a TypeNode

            IEnumerable <ArgumentNode> arguments = ParseCallTail((RuleContext)rule.GetChild(1)).Select(x => CrawlSyntaxNode.Argument(x.Interval, false, x));

            return(CrawlSyntaxNode.Call(rule.SourceInterval, CrawlType.UnspecifiedType, typeConstructor, arguments));
        }
        public static ExpressionNode ParseSideEffectStatement(RuleContext rule)
        {
            ITerminalNode eos = (ITerminalNode)rule.GetChild(2);

            if (eos.Symbol.Type != CrawlLexer.END_OF_STATEMENT)
            {
                throw new CrawlImpossibleStateException($"Method call not ending {nameof(CrawlLexer.END_OF_STATEMENT)}", rule.SourceInterval);
            }

            RuleContext toCall     = (RuleContext)rule.GetChild(0);
            RuleContext invocation = (RuleContext)rule.GetChild(1);

            List <ArgumentNode> args   = ParseArgumentList(invocation).ToList();
            ExpressionNode      target = ParseExpression(toCall);

            return(CrawlSyntaxNode.Call(rule.SourceInterval, CrawlType.UnspecifiedType, target, args));
        }
        private static ExpressionNode ParsePostfix(RuleContext rule)
        {
            ExpressionNode node = ParseExpression((RuleContext)rule.GetChild(0));

            for (int i = 1; i < rule.ChildCount; i++)
            {
                RuleContext post = (RuleContext)rule.GetChild(i);
                if (post.RuleIndex == CrawlParser.RULE_call_expression)
                {
                    node = CrawlSyntaxNode.Call(post.SourceInterval, CrawlType.UnspecifiedType, node, ParseArgumentList(post));
                }
                else if (post.RuleIndex == CrawlParser.RULE_index_expression)
                {
                    node = CrawlSyntaxNode.Index(post.SourceInterval, CrawlType.UnspecifiedType, node, ParseArgumentList(post));
                }
                else if (post.RuleIndex == CrawlParser.RULE_subfield_expression)
                {
                    IdentifierNode sub = CrawlSyntaxNode.Identifier(post.GetChild(1).SourceInterval, post.GetChild(1).GetText());
                    node = CrawlSyntaxNode.MemberAccess(post.SourceInterval, CrawlType.UnspecifiedType, node, sub);
                }
                else if (post.RuleIndex == CrawlParser.RULE_generic_unpack_expression)
                {
                    List <TypeNode> generics = new List <TypeNode>();
                    for (int j = 1; j < post.ChildCount; j += 2)
                    {
                        generics.Add(ParseTreeParser.ParseType((CrawlParser.TypeContext)post.GetChild(j)));
                    }
                    node = CrawlSyntaxNode.GenericsUnpack(post.SourceInterval, CrawlType.UnspecifiedType, node, generics);
                }
                else
                {
                    throw new NotImplementedException("Strange postfix expression");
                }
            }

            return(node);
        }