Beispiel #1
0
        internal ParseResult Parse(ParseContext parentContext)
        {
            var ctx = new ParseContext(parentContext, this);

            if (!parentContext.IsUnique(ctx))
            {
                return(ctx.Error("Infinite parsing loop detected."));
            }

            ParseResult         failed    = null;
            SymbolExpectedError tailError = null;
            var children = OnParse(ctx)
                           .TakeWhile(x => (failed = failed ?? (x.Success ? null : x)) == null &&
                                      (tailError = x.TailError ?? tailError) == tailError)
                           .SelectMany(x => x.FlattenHierarchy ? x : Single(x))
                           .ToArray();

            if (failed != null)
            {
                tailError = ctx.Expected(tailError, failed.Error as SymbolExpectedError);
            }

            return((failed != null && failed.Fatal)
                ? failed.Error
                : SubstituteResult(new ParseResult(ctx, failed != null
                    ? ctx.Expected(failed.Error as SymbolExpectedError, tailError)
                    : tailError, children)));
        }
Beispiel #2
0
 protected override IEnumerable <ParseResult> OnParse(ParseContext ctx)
 {
     yield return(ctx.Error(Reason));
 }