Exemple #1
0
        private CommandArgumentNode?ParseCommandArgument(CommandNode commandNode)
        {
            if (CurrentToken.Type != TokenType.Argument)
            {
                return(null);
            }

            IArgument?argument = default;

            for (var i = 0; i < commandNode.Command.Arguments.Count; i++)
            {
                if (commandNode.Command.Arguments[i] is {} arg&&
                    !IsFull(arg))
                {
                    argument = arg;
                    break;
                }
            }

            if (argument is null)
            {
                return(null);
            }

            var argumentNode = new CommandArgumentNode(
                CurrentToken,
                argument,
                commandNode);

            IncrementCount(argument);

            Advance();

            return(argumentNode);
        }
Exemple #2
0
        private CommandArgumentNode ParseCommandArgument(CommandNode commandNode)
        {
            if (CurrentToken.Type != TokenType.Argument)
            {
                return(null);
            }

            var argument = commandNode.Command
                           .Arguments
                           .FirstOrDefault(a => !IsFull(a));

            if (argument == null)
            {
                return(null);
            }

            var argumentNode = new CommandArgumentNode(
                CurrentToken,
                argument,
                commandNode);

            IncrementCount(argument);

            Advance();

            return(argumentNode);
        }
        protected override void VisitCommandArgumentNode(CommandArgumentNode argumentNode)
        {
            var commandResult = _innermostCommandResult;

            var argumentResult = commandResult !.Children.ResultFor(argumentNode.Argument);

            if (argumentResult is null)
            {
                argumentResult = new ArgumentResult(argumentNode.Argument, commandResult);

                commandResult.Children.Add(argumentResult);
            }

            argumentResult.AddToken(argumentNode.Token);
            commandResult.AddToken(argumentNode.Token);
        }
        protected override void VisitCommandArgumentNode(
            CommandArgumentNode argumentNode)
        {
            var commandResult = _innermostCommandResult;

            var argumentResult =
                commandResult !.Children
                .OfType <ArgumentResult>()
                .SingleOrDefault(r => r.Symbol == argumentNode.Argument);

            if (argumentResult is null)
            {
                argumentResult =
                    new ArgumentResult(
                        argumentNode.Argument,
                        commandResult);

                commandResult.Children.Add(argumentResult);
            }

            argumentResult.AddToken(argumentNode.Token);
            commandResult.AddToken(argumentNode.Token);
        }