Esempio n. 1
0
        public CommandLineSyntax Parse(string commandLine, CancellationToken cancellation = default)
        {
            if (commandLine == null)
            {
                throw new ArgumentNullException(nameof(commandLine));
            }

            var tokens          = _lexer.Lex(commandLine, cancellation).ToArray();
            var terminalElement = GetTerminalElement(tokens, commandLine);
            var cursor          = new ElementsCursor <SyntaxToken>(tokens, terminalElement);
            var errors          = new List <SyntaxError>();

            var commandNameSyntax      = ScanCommandName(cursor, errors, cancellation, out IReadOnlyList <string> commandName);
            var argumentsSectionSyntax = ScanArgumentsSection(cursor, errors, cancellation, commandName);
            var endOfInputToken        = ScanEndOfInput(cursor, errors);

            cancellation.ThrowIfCancellationRequested();
            return(new CommandLineSyntax(commandNameSyntax, argumentsSectionSyntax, endOfInputToken, errors));
        }
 /// <summary>
 /// Lexes the command line for this process. The returned command line includes the process name.
 /// </summary>
 /// <returns>The lexed command line.</returns>
 public static IEnumerable <string> Lex(this ICommandLineLexer @this) => @this.Lex(Environment.CommandLine);