Ejemplo n.º 1
0
        private void ParseString(
            CommandTreeParserContext context,
            TokenStream stream,
            CommandTree node)
        {
            var token = stream.Expect(Token.Type.String);

            // Command?
            var command = node.Command.FindCommand(token.Value);

            if (command != null)
            {
                node.Next = ParseCommand(context, node.Command, node, stream);
                return;
            }

            // Current command has no arguments?
            if (!node.HasArguments())
            {
                throw new CommandAppException($"Unknown child command '{token.Value}' of '{node.Command.Name}'.");
            }

            // Argument?
            var parameter = node.FindArgument(context.CurrentArgumentPosition);

            if (parameter == null)
            {
                throw new CommandAppException($"Could not match '{token.Value}' with an argument.");
            }

            node.Mapped.Add((parameter, stream.Consume(Token.Type.String).Value));

            context.IncreaseArgumentPosition();
        }