internal Reply(ReplyTag tag, O result, PString <I> state, ParserError error) { Tag = tag; Result = result; State = state; Error = error; }
internal Reply(ParserError error) { Debug.Assert(error != null); Tag = ReplyTag.Error; Error = error; State = PString <I> .Zero; }
internal Reply(O result, PString <I> state, ParserError error = null) { Debug.Assert(notnull(result)); Tag = ReplyTag.OK; State = state; Result = result; Error = error; }
public static ParserResult <I, I> newstate <I>(PString <I> inp) { var x = inp.Value[inp.Index]; return(ConsumedOK(x, new PString <I>( inp.Value, inp.Index + 1, inp.EndIndex, inp.UserState, inp.TokenPos))); }
/// <summary> /// Sets a new context for the parser p which represents a span of the input tokens /// </summary> /// <remarks> /// The parse fails if it doesn't consume all tokens in the block /// </remarks> static ParserResult <TOKEN, A> parseBlock <TOKEN, A>(Parser <TOKEN, A> p, int start, int end, PString <TOKEN> inp) { var pstr = new PString <TOKEN>(inp.Value, start, end, inp.UserState, inp.TokenPos); var pres = p.Parse(pstr); return(new ParserResult <TOKEN, A>( pres.Tag, new Reply <TOKEN, A>( pres.Reply.Tag, pres.Reply.Result, new PString <TOKEN>(inp.Value, pres.Reply.State.Index, inp.EndIndex, pres.Reply.State.UserState, pres.Reply.State.TokenPos), pres.Reply.Error))); }
public static ParserResult <I, I> newstate <I>(PString <I> inp) { var x = inp.Value[inp.Index]; var newpos = new Pos(inp.Pos.Line, inp.Pos.Column + 1); return(ConsumedOK(x, new PString <I>( inp.Value, inp.Index + 1, inp.EndIndex, newpos, inp.DefPos, onside(newpos, inp.DefPos) ? Sidedness.Onside : Sidedness.Offside, inp.UserState))); }
public static ParserResult <char> newstate(PString inp) { var x = inp.Value[inp.Index]; var newpos = x == '\n' ? new Pos(inp.Pos.Line + 1, 0) : x == '\t' ? new Pos(inp.Pos.Line, ((inp.Pos.Column / 4) + 1) * 4) : new Pos(inp.Pos.Line, inp.Pos.Column + 1); return(ConsumedOK(x, new PString( inp.Value, inp.Index + 1, inp.EndIndex, newpos, inp.DefPos, onside(newpos, inp.DefPos) ? Sidedness.Onside : Sidedness.Offside, inp.UserState))); }
/// <summary> /// Run the parser p with the input provided /// </summary> public static ParserResult <I, O> parse <I, O>(Parser <I, O> p, PString <I> input) => p.Parse(input);
/// <summary> /// Run the parser p with the input provided /// </summary> public static ParserResult <T> parse <T>(Parser <T> p, PString input) => p.Parse(input);
public static Reply <T> OK <T>(T result, PString remaining, ParserError error = null) => new Reply <T>(result, remaining, error);
public static ParserResult <I, O> ConsumedOK <I, O>(O value, PString <I> input, ParserError error) => new ParserResult <I, O>(ResultTag.Consumed, ReplyIO.OK(value, input, error));
public static ParserResult <I, O> EmptyOK <I, O>(O value, PString <I> input, ParserError error = null) => new ParserResult <I, O>(ResultTag.Empty, ReplyIO.OK(value, input, error));
public static PString <T> ToPString <T>(this Seq <T> value, Func <T, Pos> tokenPos) => PString <T> .Zero(tokenPos).SetValue(value.ToArray());
public static ParserResult <I, O> ConsumedOK <I, O>(O value, PString <I> input) => new ParserResult <I, O>(ResultTag.Consumed, Reply.OK(value, input));
public static ParserResult <T> EmptyOK <T>(T value, PString input, ParserError error = null) => new ParserResult <T>(ResultTag.Empty, Reply.OK(value, input, error));
public static Reply <I, O> OK <I, O>(O result, PString <I> remaining, ParserError error = null) => new Reply <I, O>(result, remaining, error);
public static ParserResult <T> ConsumedOK <T>(T value, PString input, ParserError error) => new ParserResult <T>(ResultTag.Consumed, Reply.OK(value, input, error));