Beispiel #1
0
        protected override int InnerParse(ParseArgs args)
        {
            if (args.IsRoot)
            {
                Scanner scanner = args.Scanner;
                int     pos     = scanner.Position;
                args.Push();
                int             match   = Inner.Parse(args);
                MatchCollection matches = null;
                if (match >= 0 && !AllowPartialMatch && !scanner.IsEof)
                {
                    args.PopFailed();
                    scanner.Position = pos;
                    match            = -1;
                }
                else
                {
                    matches = args.Pop();
                }

                IEnumerable <Parser> errors = null;
                if (args.Errors != null)
                {
                    var errorList = new List <Parser>(args.Errors.Count);
                    for (int i = 0; i < args.Errors.Count; i++)
                    {
                        Parser error = args.Errors[i];
                        if (!errorList.Contains(error))
                        {
                            errorList.Add(error);
                        }
                    }
                    errors = errorList;
                }

                args.Root = new GrammarMatch(this, scanner, pos, match, matches, args.ErrorIndex, args.ChildErrorIndex,
                                             errors);
                return(match);
            }
            return(base.InnerParse(args));
        }