public IParserResult <CTX, Tuple <A, B> > Parse(CTX ctx, string src) { var position = new Position(ctx); var parseResultA = parserA.Parse(ctx, src); if (!parseResultA.Success) { return(ParserResult <CTX, Tuple <A, B> > .FailWithExpected(parseResultA.Expected)); } var parseResultB = parserB.Parse(ctx, src[parseResultA.Size..]);
public IParserResult <CTX, string> Parse(CTX ctx, string src) { var match = matcher(ctx, src); if (match == null) { return(ParserResult <CTX, string> .FailWithExpected(expectedName)); } var position = new Position(ctx); foreach (var c in match) { ctx.Col++; if (c == '\n') { ctx.Line++; ctx.Col = 0; } } position.EndFromContext(ctx); return(ParserResult <CTX, string> .Ok(match, match.Length, position)); }
public IParserResult <CTX, T[]> Parse(CTX ctx, string src) { var finalSize = 0; var currentSource = src; var nodes = new List <T>(); var first = true; var position = new Position(ctx); while (true) { var r = parser.Parse(ctx, currentSource); if (!r.Success) { if (first && atLeastOne == ManyEnum.AT_LEAST_ONE) { return(ParserResult <CTX, T[]> .FailWithExpected(r.Expected)); } break; } nodes.Add(r.Value); finalSize += r.Size; currentSource = currentSource[r.Size..];