Пример #1
0
 internal Reply(ReplyTag tag, O result, PString <I> state, ParserError error)
 {
     Tag    = tag;
     Result = result;
     State  = state;
     Error  = error;
 }
Пример #2
0
        internal Reply(ParserError error)
        {
            Debug.Assert(error != null);

            Tag   = ReplyTag.Error;
            Error = error;
            State = PString <I> .Zero;
        }
Пример #3
0
        internal Reply(O result, PString <I> state, ParserError error = null)
        {
            Debug.Assert(notnull(result));

            Tag    = ReplyTag.OK;
            State  = state;
            Result = result;
            Error  = error;
        }
Пример #4
0
        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)));
        }
Пример #5
0
        /// <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)));
        }
Пример #6
0
        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)));
        }
Пример #7
0
        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)));
        }
Пример #8
0
 /// <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);
Пример #9
0
 /// <summary>
 /// Run the parser p with the input provided
 /// </summary>
 public static ParserResult <T> parse <T>(Parser <T> p, PString input) =>
 p.Parse(input);
Пример #10
0
 public static Reply <T> OK <T>(T result, PString remaining, ParserError error = null) =>
 new Reply <T>(result, remaining, error);
Пример #11
0
 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));
Пример #12
0
 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));
Пример #13
0
 public static PString <T> ToPString <T>(this Seq <T> value, Func <T, Pos> tokenPos) =>
 PString <T> .Zero(tokenPos).SetValue(value.ToArray());
Пример #14
0
 public static ParserResult <I, O> ConsumedOK <I, O>(O value, PString <I> input) =>
 new ParserResult <I, O>(ResultTag.Consumed, Reply.OK(value, input));
Пример #15
0
 public static ParserResult <T> EmptyOK <T>(T value, PString input, ParserError error = null) =>
 new ParserResult <T>(ResultTag.Empty, Reply.OK(value, input, error));
Пример #16
0
 public static Reply <I, O> OK <I, O>(O result, PString <I> remaining, ParserError error = null) =>
 new Reply <I, O>(result, remaining, error);
Пример #17
0
 public static ParserResult <T> ConsumedOK <T>(T value, PString input, ParserError error) =>
 new ParserResult <T>(ResultTag.Consumed, Reply.OK(value, input, error));