Esempio n. 1
0
        public override Base VisitParameter_list([NotNull] GolangParser.Parameter_listContext context)
        {
            var ret = new Parameters();

            foreach (var child in context.children)
            {
                if (child is GolangParser.Parameter_declContext)
                {
                    var decl = child.Accept(this);
                    switch (decl)
                    {
                    case Parameters ps:
                        while (ps.NumChildren() > 0)
                        {
                            ret.AddChild(ps.GetChild <Parameter>(0));
                        }
                        break;

                    case Parameter p:
                        ret.AddChild(p);
                        break;
                    }
                }
            }

            return(ret);
        }
        private Parameters ParseParameters()
        {
            var t = NextToken();

            if (!t.IsDelimiter(Delimiter.ParenthesisOpen))
            {
                _stream.Previous(); // Not open parenthesis encountered

                return(null);
            }

            var node = new Parameters();

            do
            {
                var parameter = ParseParameter();

                node.AddChild(parameter);
            } while (NextToken().IsDelimiter(Delimiter.Comma));
            _stream.Previous(); // Not comma encountered

            t = NextToken();
            AssertDelimiter(Delimiter.ParenthesisClose, t);

            return(node);
        }
Esempio n. 3
0
        public override Base VisitParameter_decl([NotNull] GolangParser.Parameter_declContext context)
        {
            var type = context.type().Accept(this) as AST.Type;

            if (context.EllipsesOperator() != null)
            {
                type = new RangeType(type);
            }

            if (context.identifier_list() != null)
            {
                var ret = new Parameters();

                var nodeList = context.identifier_list().Accept(this) as RawNodeList;
                foreach (var node in nodeList.Items)
                {
                    ret.AddChild(new Parameter(node.Text, type.CloneType()));
                }

                return(ret);
            }
            else
            {
                return(new Parameter(string.Empty, type));
            }
        }