Exemple #1
0
        public IParserResult <CTX, U> Parse(CTX ctx, string src)
        {
            var result = parser.Parse(ctx, src);

            if (result.Success)
            {
                return(ParserResult <CTX, U> .Ok(mapper(result.Value, result), result.Size, result.Position));
            }
            return(ParserResult <CTX, U> .FailWithExpected(result.Expected));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
 public IParserResult <CTX, None> Parse(CTX ctx, string src)
 {
     return(ParserResult <CTX, None> .Ok(None.Instance, 0, new Position(ctx)));
 }