Exemplo n.º 1
0
        private void SetNextExpectedArg(
            IItem item,
            ParserResult pr,
            ref IArgument expectedArg,
            ref IItem expectedArgItem)
        {
            List <IArgument> argList = item?.Arguments.ToList( ) ?? _spec.Arguments.ToList( );

            if (item != null &&
                expectedArg != null &&
                _spec.Arguments.Contains(expectedArg))
            {
                expectedArg = null;
            }

            if (expectedArg != null &&
                expectedArg.IsDynamicArgument)
            {
                return;
            }

            IArgument arg,
                      prevArg = null;

            while (true)
            {
                if (argList.Count == 0)
                {
                    if (expectedArgItem != null)
                    {
                        expectedArg = expectedArgItem?.Arguments.FirstOrDefault(a => !pr.IsSet(a))
                                      ?? expectedArgItem?.DynamicArgument;

                        if (expectedArg == null)
                        {
                            expectedArgItem = null;
                        }
                    }

                    if (expectedArg == null)
                    {
                        expectedArg = _spec.Arguments.FirstOrDefault(a => !pr.IsSet(a));
                    }
                    return;
                }

                arg = argList[0];
                if (expectedArg == null ||
                    prevArg == expectedArg)
                {
                    expectedArg = arg;
                    return;
                }

                argList.RemoveAt(0);
                prevArg = arg;
            }
        }