예제 #1
0
        public override bool TryParse(TokenStack tokens, out GraphNode node)
        {
            if (tokens.ExpectSequence(TokenType.Identifier, TokenType.ColonSymbol))
            {
                var queue = new Queue <Token>();

                var identifier = tokens.Pop();
                var colon      = tokens.Pop();

                queue.Enqueue(identifier);
                queue.Enqueue(colon);

                var valueSyntax = new ValueSyntax();
                var valueToken  = tokens.Peek();

                if (valueSyntax.TryParse(tokens, out GraphNode value))
                {
                    queue.Enqueue(valueToken);
                    node = new VariableAssignment(queue, identifier.Value, (Value)value);
                    return(true);
                }
                else
                {
                    while (queue.Count > 0)
                    {
                        tokens.Push(queue.Dequeue());
                    }
                }
            }

            node = null;
            return(false);
        }
예제 #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);
        }