Esempio n. 1
0
        public Parser(OptionCollection options,
                      ParsingTable parsingTable,
                      ITokenizer tokenizer,
                      IJ4JLogger?logger = null)
        {
            Collection    = options;
            _parsingTable = parsingTable;
            Tokenizer     = tokenizer;

            _logger = logger;
        }
Esempio n. 2
0
        public static IParser GetLinuxDefault(ITextConverters?converters = null,
                                              IJ4JLogger?logger          = null,
                                              params ICleanupTokens[] cleanupProcessors)
        {
            converters ??= new TextConverters(logger: logger);

            var options = new OptionCollection(StringComparison.Ordinal, converters, logger);

            var parsingTable = new ParsingTable(new OptionsGenerator(options,
                                                                     StringComparison.Ordinal,
                                                                     logger),
                                                logger);

            var tokenizer = new Tokenizer(new LinuxLexicalElements(logger),
                                          logger,
                                          cleanupProcessors);

            return(new Parser(options, parsingTable, tokenizer, logger));
        }
        private static IConfigurationBuilder AddJ4JCommandLineDefault(this IConfigurationBuilder builder,
                                                                      CommandLineOperatingSystems opSys,
                                                                      out OptionCollection?options,
                                                                      out CommandLineSource?cmdLineSource,
                                                                      ITextConverters?converters = null,
                                                                      IJ4JLogger?logger          = null,
                                                                      params ICleanupTokens[] cleanupTokens)
        {
            converters ??= new TextConverters();

            var textComparison = opSys switch
            {
                CommandLineOperatingSystems.Windows => StringComparison.OrdinalIgnoreCase,
                CommandLineOperatingSystems.Linux => StringComparison.Ordinal,
                _ => throw new
                      InvalidEnumArgumentException($"Unsupported {nameof( CommandLineOperatingSystems )} value '{opSys}'")
            };

            var lexicalElements = opSys switch
            {
                CommandLineOperatingSystems.Windows =>
                (ILexicalElements) new WindowsLexicalElements(logger),
                CommandLineOperatingSystems.Linux =>
                (ILexicalElements) new LinuxLexicalElements(logger),
                _ => throw new
                      InvalidEnumArgumentException($"Unsupported {nameof( CommandLineOperatingSystems )} value '{opSys}'")
            };

            options = new OptionCollection(textComparison, converters, logger);

            var optionsGenerator = new OptionsGenerator(options, textComparison, logger);
            var parsingTable     = new ParsingTable(optionsGenerator, logger);
            var tokenizer        = new Tokenizer(lexicalElements);

            return(builder.AddJ4JCommandLine(new Parser(options, parsingTable, tokenizer, logger),
                                             out cmdLineSource,
                                             logger,
                                             cleanupTokens));
        }
    }
}