Ejemplo n.º 1
0
 public override Result Match(Parser parser, ICursor cursor)
 {
     if (!cursor.CanPop())
     {
         parser.RememberFail(cursor, this); return(null);
     }
     return(MatchSome(parser, cursor));
 }
Ejemplo n.º 2
0
 public override Result Match(Parser parser, ICursor cursor)
 {
     if (!cursor.CanPop())
     {
         return(new Result(cursor, null));
     }
     parser.RememberFail(cursor, this);
     return(null);
 }
Ejemplo n.º 3
0
 public override Result Match(Parser parser, ICursor cursor)
 {
     if (cursor.CanPop())
     {
         if (typeof(T).IsInstanceOfType(cursor.Peek()))
         {
             T item = (T)cursor.Peek();
             if (MatchImpl(item))
             {
                 return(new Result(cursor.Pop(), item));
             }
         }
     }
     parser.RememberFail(cursor, this);
     return(null);
 }
Ejemplo n.º 4
0
        public string GetError()
        {
            if (failCursor == null)
            {
                return(string.Empty);
            }
            object unexpected;

            if (failCursor.CanPop())
            {
                unexpected = failCursor.Peek();
            }
            else
            {
                unexpected = "{EOI}";
            }
            return(string.Format("Syntax error at {0} (unexpected '{1}')", failCursor.Position, unexpected));
        }
Ejemplo n.º 5
0
        public override Result Match(Parser parser, ICursor cursor)
        {
            ICursor cur = cursor;

            for (int i = 0; i < chars.Length; i++)
            {
                if (!cur.CanPop())
                {
                    parser.RememberFail(cursor, this); return(null);
                }
                object c = cur.Peek();
                if (!typeof(char).IsInstanceOfType(c))
                {
                    parser.RememberFail(cursor, this); return(null);
                }
                if (!Equals(chars[i], (char)c))
                {
                    parser.RememberFail(cursor, this); return(null);
                }
                cur = cur.Pop();
            }
            return(new Result(cur, chars));
        }