summaryrefslogtreecommitdiff
path: root/input.lisp
blob: e28e73a977b0c01069315e728a3a030193d4f11e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(in-package #:monparser)

(defclass parser-input ()
  ((cursor :initarg :cursor :accessor input-cursor :initform 0)
   (data :initarg :data :reader input-data :initform nil)))

(defun has-data? (input)
  (< (input-cursor input) (length (input-data input))))

(defun peek (input)
  (char (input-data input)
        (input-cursor input)))

(defun advance (input)
  (make-instance 'parser-input
                 :data (input-data input)
                 :cursor (+ (input-cursor input) 1)))

(defun cursor-distance (input1 input2)
  (- (input-cursor input1) (input-cursor input2)))