Пример #1
0
        // This returns an IEnumerable.
        static InvokersParametersPair ParseImplementation(string s)
        {
            // Call to the native parsing lib PPparsing
            var tokens = NativeParsing.GetTokensRange(s);

            // get Commands with the right name
            var commands = commandsSniffer.GetValue(NativeParsing.GetMemory(s, tokens[0]));

            if (commands != null)
            {
                // there is a Command with such name
                {
                    var command = commands.GetIfOneLongArgument;
                    if (command != null)
                    {
                        // command has one long argument
                        return(JustOneArgument(command, NativeParsing.GetTailMemory(s, tokens[0]).TrimStart()));
                    }
                }
                tokens = tokens.Slice(1);

                var commandsWithRightArgumentCount = commands.GetValue(tokens.Length);
                if (commandsWithRightArgumentCount != null)
                {
                    // there are some Commands with the corresponing argument count
                    return(commandsWithRightArgumentCount, NativeParsing.MakeMemories(s, tokens));
                }
                else
                {
                    // there are no Commands with that argument count
                    return(JustOneArgument(commandsSniffer.BadArgumentCountCommand, tokens.Length));
                }
            }
            else
            {
                // command with that name doesn't exist
                return(JustOneArgument(commandsSniffer.NotFoundCommand, s.AsMemory().TrimStart()));
            }
        }
Пример #2
0
 // Here the IEnumerable from ParseImplementation is wrapped in an Invoker
 // that invokes the elements in order
 public (IInvoker <IApplication, object[]>, object[]) Parse(string input)
 {
     var(commands, arguments) = ParseImplementation(input);
     NativeParsing.ReleaseResources();
     return(new EnumerableInvoker <IApplication, object[]>(commands), arguments);
 }