summaryrefslogtreecommitdiff
path: root/input.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2024-10-13 00:34:11 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2024-10-13 00:34:11 -0300
commit7a6f4586c2e83ffcdb5a8b7b2c5591f6e80e038f (patch)
tree441e462d4145c95e4aad94c7e64b89ddca667e6c /input.lisp
parentb196a5d56db31d6836c1ed028f38146cbb08436c (diff)
downloadmonparser-7a6f4586c2e83ffcdb5a8b7b2c5591f6e80e038f.tar.gz
monparser-7a6f4586c2e83ffcdb5a8b7b2c5591f6e80e038f.zip
Change project file structure and api
Diffstat (limited to 'input.lisp')
-rw-r--r--input.lisp57
1 files changed, 12 insertions, 45 deletions
diff --git a/input.lisp b/input.lisp
index 4edf6aa..e28e73a 100644
--- a/input.lisp
+++ b/input.lisp
@@ -1,53 +1,20 @@
(in-package #:monparser)
-(defclass input ()
- ((cursor :initarg :cursor :accessor cursor :initform 0)
- (file :initarg :file :reader file :initform nil)
- (data :initarg :data :reader data :initform nil)))
+(defclass parser-input ()
+ ((cursor :initarg :cursor :accessor input-cursor :initform 0)
+ (data :initarg :data :reader input-data :initform nil)))
(defun has-data? (input)
- (< (cursor input) (length (data input))))
-
-(defun prefix? (target input)
- (string= target
- (data input)
- :start2 (cursor input)
- :end2 (min (+ (cursor input) (length target))
- (length (data input)))))
+ (< (input-cursor input) (length (input-data input))))
(defun peek (input)
- (char (data input)
- (cursor input)))
-
-(defun advance (input &optional (amount 1))
- (make-instance 'input
- :data (data input)
- :file (file input)
- :cursor (+ (cursor input) amount)))
-
-(defun input-sub (input1 input2)
- (- (cursor input1) (cursor input2)))
-
-(defun from-string (str)
- (make-instance 'input :data str))
-
-(defun read-file (path)
- (with-open-file (file path)
- (let* ((size (file-length file))
- (buf (make-string size)))
- (read-sequence buf file)
- buf)))
+ (char (input-data input)
+ (input-cursor input)))
-(defun from-file (filename)
- (make-instance 'input :file filename :data (read-file filename)))
+(defun advance (input)
+ (make-instance 'parser-input
+ :data (input-data input)
+ :cursor (+ (input-cursor input) 1)))
-(defun line-and-column (input)
- (let ((line 1) (column 1))
- (dotimes (i (cursor input))
- (let ((c (char (data input) i)))
- (case c
- (#\Newline
- (incf line)
- (setf column 1))
- (t (incf column)))))
- (values line column)))
+(defun cursor-distance (input1 input2)
+ (- (input-cursor input1) (input-cursor input2)))