Exemple #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)));
        }
Exemple #2
0
 public bool IsUnique(ParseContext ctx)
 {
     if (Parser == ctx.Parser && InitialOffset == ctx.InitialOffset)
     {
         return(false);
     }
     return(Parent == null || Parent.IsUnique(ctx));
 }