Ejemplo n.º 1
0
        private static CrefNode parseMember(Token[] tokens, ref int i)
        {
            CrefNode node = null;

            while (true)
            {
                if (tokens[i].Type != TokenType.Name)
                {
                    throw new InvalidOperationException("Parse Error: expected identifier.");
                }
                node = new CrefName {
                    Name = tokens[i].Item, Parent = node
                };
                i++;
                if (tokens[i].Type != TokenType.Dot)
                {
                    break;
                }
                i++;
            }
            return(node);
        }
Ejemplo n.º 2
0
        private static CrefNode parseType(Token[] tokens, ref int i)
        {
            if (tokens[i].Type == TokenType.TypeGenericParameterReference || tokens[i].Type == TokenType.MethodGenericParameterReference)
            {
                var ret = new CrefGenericParameter
                {
                    Position = Convert.ToInt32(tokens[i].Item),
                    Source   = tokens[i].Type == TokenType.TypeGenericParameterReference ? GenericParameterSource.Type : GenericParameterSource.Method
                };
                i++;
                return(ret);
            }

            CrefNode node = null;

            while (true)
            {
                if (tokens[i].Type != TokenType.Name)
                {
                    throw new InvalidOperationException("Parse Error: expected identifier.");
                }
                node = new CrefName {
                    Name = tokens[i].Item, Parent = node
                };
                i++;
                if (tokens[i].Type == TokenType.OpenCurly)
                {
                    i++;
                    var arguments = new List <CrefNode> {
                        parseType(tokens, ref i)
                    };
                    while (tokens[i].Type == TokenType.Comma)
                    {
                        i++;
                        arguments.Add(parseType(tokens, ref i));
                    }
                    if (tokens[i].Type != TokenType.CloseCurly)
                    {
                        throw new InvalidOperationException("Parse Error: '}' or ',' expected.");
                    }
                    i++;
                    node = new CrefGenericType {
                        Arguments = arguments.ToArray(), Parent = node
                    };
                }
                if (tokens[i].Type != TokenType.Dot)
                {
                    break;
                }
                i++;
            }

            while (tokens[i].Type == TokenType.Array)
            {
                node = new CrefArrayType {
                    Inner = node, Ranks = Convert.ToInt32(tokens[i].Item)
                };
                i++;
            }

            if (tokens[i].Type == TokenType.At)
            {
                node = new CrefRefType {
                    Inner = node
                };
                i++;
            }
            else if (tokens[i].Type == TokenType.Star)
            {
                node = new CrefPointerType {
                    Inner = node
                };
                i++;
            }

            return(node);
        }