Exemplo n.º 1
0
        public override bool TryParse(TokenStack tokens, out GraphNode node)
        {
            var typeDeclarationSyntax = new TypeDeclarationSyntax();

            if (typeDeclarationSyntax.TryParse(tokens, out GraphNode typeDeclaration))
            {
                if (tokens.Expect(TokenType.Identifier))
                {
                    var identifier = tokens.Pop();

                    if (tokens.Expect(TokenType.AsKeyword))
                    {
                        var asKeyword = tokens.Pop();

                        if (typeDeclarationSyntax.TryParse(tokens, out GraphNode asTypeDeclaration))
                        {
                            node = new PropertyDeclaration(new[] { identifier }, identifier.Value, (TypeDeclaration)typeDeclaration, (TypeDeclaration)asTypeDeclaration);
                            return(true);
                        }
                        else
                        {
                            // TODO: syntax error
                        }
                    }
                    else
                    {
                        node = new PropertyDeclaration(new[] { identifier }, identifier.Value, (TypeDeclaration)typeDeclaration);
                        return(true);
                    }
                }
                else
                {
                    // TODO: syntax error
                }
            }

            // TODO: syntax error
            node = null;
            return(false);
        }
Exemplo n.º 2
0
        public override bool TryParse(TokenStack tokens, out GraphNode node)
        {
            var source = new Queue <Token>();

            if (tokens.Expect(TokenType.Identifier))
            {
                var identifier = tokens.Pop();
                source.Enqueue(identifier);

                if (tokens.Expect(TokenType.ColonSymbol))
                {
                    var colon = tokens.Pop();
                    source.Enqueue(colon);

                    var valueSyntax = new ValueSyntax();
                    if (valueSyntax.TryParse(tokens, out GraphNode value))
                    {
                        node = new EnumValue(source, identifier.Value, (Value)value);
                        return(true);
                    }
                    else
                    {
                        // TODO: syntax error
                        node = null;
                        return(false);
                    }
                }
                else
                {
                    node = new EnumValue(source, identifier.Value, null);
                    return(true);
                }
            }

            // TODO: syntax error
            node = null;
            return(false);
        }
Exemplo n.º 3
0
        public override bool TryParse(TokenStack tokens, out GraphNode node)
        {
            if (tokens.Expect(TokenType.OpenKeyword))
            {
                var source = new List <Token>();
                source.Add(tokens.Pop());

                if (tokens.ExpectAny(TokenType.StringLiteral, TokenType.Identifier))
                {
                    var valueToken = tokens.Pop();
                    source.Add(valueToken);

                    var value = new Value(new [] { valueToken }, valueToken.TokenType == TokenType.Identifier ? ValueType.Identifier : ValueType.String, valueToken.Value);
                    node = new OpenStatement(source, value);
                    return(true);
                }
            }

            // TODO: syntax error
            node = null;
            return(false);
        }