Example #1
0
        protected override IEnumerable <ParseResult> OnParse(ParseContext ctx)
        {
// ReSharper disable once ConvertClosureToMethodGroup
            var matches = Parsers.Select(x => ctx.Peek(x))
                          .OrderByDescending(x => x.Success ? x.Length : x.Error.Context.Offset)
                          .ToArray();

            var success = matches.FirstOrDefault(x => x.Success);

            if (success == null && matches.All(x => x.Error.Context.Offset == matches[0].Error.Context.Offset))
            {
                yield return(matches[0].Error.Context.Expected(Parsers));

                yield break;
            }

            yield return(ctx.Apply(success) ?? matches.FirstOrDefault());
        }