Exemple #1
0
        public override Base VisitRange_clause([NotNull] GolangParser.Range_clauseContext context)
        {
            var expr = context.expression().Accept(this) as Expression;

            ExpressionList values = null;

            if (context.identifier_list() != null)
            {
                values = new ExpressionList();
                var idents = context.identifier_list().Accept(this) as RawNodeList;
                int index  = 0;
                foreach (var ident in idents.Items)
                {
                    var vd = new VarDeclaration(
                        ident.Text,
                        new IteratorType(
                            new ExpressionType(expr),
                            index++));
                    m_currentScope.AddVarDeclaration(vd);
                    values.AddChild(new IdentifierExpression(vd.Identifier));
                }
            }
            else if (context.expression_list() != null)
            {
                values = context.expression_list().Accept(this) as ExpressionList;
            }

            return(new RangeClause(
                       values,
                       expr));
        }
Exemple #2
0
        public ExpressionList ParseExpressionList(TokenType expressionDelimiter,
                                                  TokenType expressionListTerminator = TokenType.None)
        {
            try {
                trace.Enter();

                ConsumedTokens.Clear();
                Read();

                if (current.Type == expressionListTerminator)
                {
                    return(null);
                }

                var expr = new ExpressionList {
                    Delimiter = expressionDelimiter
                };
                expr.AddChild(Expr());

                while (true)
                {
                    if (current.Type == expressionDelimiter)
                    {
                        Read();
                        if (current.Type == TokenType.Eof ||
                            current.Type == expressionListTerminator)
                        {
                            break;
                        }
                        expr.AddChild(Expr());
                    }
                    else if (current.Type == TokenType.Eof ||
                             current.Type == expressionListTerminator)
                    {
                        break;
                    }
                    else
                    {
                        throw new SyntaxException(tokenizer, current, expressionDelimiter);
                    }
                }

                return(expr);
            } finally {
                trace.Leave();
            }
        }
Exemple #3
0
        public override Base VisitExpression_list([NotNull] GolangParser.Expression_listContext context)
        {
            var ret = new ExpressionList();

            foreach (var child in context.children)
            {
                if (child is GolangParser.ExpressionContext)
                {
                    ret.AddChild(child.Accept(this) as Expression);
                }
            }

            return(ret);
        }
Exemple #4
0
        public override Base VisitShort_var_decl([NotNull] GolangParser.Short_var_declContext context)
        {
            var ret = new StatementList();

            var identList = context.identifier_list().Accept(this) as RawNodeList;
            var exprList  = context.expression_list().Accept(this) as ExpressionList;

            if (identList.Items.Count > 1 && exprList.NumChildren() == 1 && exprList.GetChild(0) is InvocationExpression)
            {
                var invoke = exprList.GetChild <InvocationExpression>(0);
                var idents = new ExpressionList();

                int index = 0;
                foreach (var ident in identList.Items)
                {
                    idents.AddChild(new IdentifierExpression(ident.Text));
                    var vd = new VarDeclaration(ident.Text,
                                                new ReturnType(
                                                    invoke,
                                                    index++));
                    m_currentScope.AddVarDeclaration(vd);
                }


                ret.AddChild(
                    new ReturnAssignment(
                        idents,
                        invoke));
            }
            else
            {
                for (int i = 0; i < identList.Items.Count; i++)
                {
                    var vd = new VarDeclaration(identList.Items[i].Text, new ExpressionType(exprList.GetChild <Expression>(0)));
                    m_currentScope.AddVarDeclaration(vd);
                    ret.AddChild(
                        new Assignment(
                            new IdentifierExpression(vd.Identifier),
                            exprList.GetChild <Expression>(0),
                            AssignmentType.Normal));
                }
            }

            return(ret);
        }