示例#1
0
 private static ParserResult <object> MatchVerb(
     Func <IEnumerable <string>, IEnumerable <OptionSpecification>, Result <IEnumerable <Token>, Error> > tokenizer,
     IEnumerable <Tuple <Verb, Type> > verbs,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     CultureInfo parsingCulture)
 {
     return(verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
         ? InstanceBuilder.Build(
                Maybe.Just <Func <object> >(
                    () =>
                    verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2.AutoDefault()),
                tokenizer,
                arguments.Skip(1),
                nameComparer,
                parsingCulture)
         : MakeNotParsed(verbs.Select(v => v.Item2), new BadVerbSelectedError(arguments.First())));
 }
示例#2
0
 private static ParserResult <object> MatchVerb(
     Func <IEnumerable <string>, IEnumerable <OptionSpecification>, StatePair <IEnumerable <Token> > > tokenizer,
     IEnumerable <Tuple <Verb, Type> > verbs,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     CultureInfo parsingCulture)
 {
     return(verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
         ? InstanceBuilder.Build(
                Maybe.Just <Func <object> >(() => Activator.CreateInstance(verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2)),
                tokenizer,
                arguments.Skip(1),
                nameComparer,
                parsingCulture)
         : ParserResult.Create <object>(
                ParserResultType.Verbs,
                new NullInstance(),
                new[] { new BadVerbSelectedError(arguments.First()) },
                Maybe.Just(verbs.Select(v => v.Item2))));
 }
示例#3
0
 private static ParserResult <object> MatchVerb(
     Func <IEnumerable <string>, IEnumerable <OptionSpecification>, Result <IEnumerable <Token>, Error> > tokenizer,
     IEnumerable <Tuple <Verb, Type> > verbs,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     CultureInfo parsingCulture,
     IEnumerable <ErrorType> nonFatalErrors)
 {
     verbs = verbs.Memorize();
     return(verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
         ? InstanceBuilder.Build(
                verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2,
                Maybe.Nothing <Func <object> >(),
                tokenizer,
                arguments.Skip(1),
                nameComparer,
                false,
                parsingCulture,
                nonFatalErrors)
         : MakeNotParsed(verbs.Select(v => v.Item2), new BadVerbSelectedError(arguments.First())));
 }
示例#4
0
        private static ParserResult <object> MatchVerb(
            Func <IEnumerable <string>, IEnumerable <OptionSpecification>, Result <IEnumerable <Token>, Error> > tokenizer,
            IEnumerable <Tuple <Verb, Type> > verbs,
            Tuple <Verb, Type> defaultVerb,
            IEnumerable <string> arguments,
            StringComparer nameComparer,
            bool ignoreValueCase,
            CultureInfo parsingCulture,
            bool autoHelp,
            bool autoVersion,
            bool allowMultiInstance,
            IEnumerable <ErrorType> nonFatalErrors)
        {
            string firstArg = arguments.First();

            var verbUsed = verbs.FirstOrDefault(vt =>
                                                nameComparer.Equals(vt.Item1.Name, firstArg) ||
                                                vt.Item1.Aliases.Any(alias => nameComparer.Equals(alias, firstArg))
                                                );

            if (verbUsed == default)
            {
                return(MatchDefaultVerb(tokenizer, verbs, defaultVerb, arguments, nameComparer, ignoreValueCase, parsingCulture, autoHelp, autoVersion, nonFatalErrors));
            }
            return(InstanceBuilder.Build(
                       Maybe.Just <Func <object> >(
                           () => verbUsed.Item2.AutoDefault()),
                       tokenizer,
                       arguments.Skip(1),
                       nameComparer,
                       ignoreValueCase,
                       parsingCulture,
                       autoHelp,
                       autoVersion,
                       allowMultiInstance,
                       nonFatalErrors));
        }