diff options
| author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2026-05-01 14:16:07 -0300 |
|---|---|---|
| committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2026-05-01 14:16:07 -0300 |
| commit | a4411bcc3919c2099934fd49664ee689460ebf80 (patch) | |
| tree | 524492a5febcd921528da7634ff91068b8c63d02 | |
| parent | d1816df4c029447f94963355cbdce5c434063ee6 (diff) | |
| download | utils-main.tar.gz utils-main.zip | |
| -rw-r--r-- | cursor.lisp | 31 | ||||
| -rw-r--r-- | def.lisp | 17 | ||||
| -rw-r--r-- | package.lisp | 15 | ||||
| -rw-r--r-- | str.lisp | 20 | ||||
| -rw-r--r-- | utils.asd | 4 |
5 files changed, 23 insertions, 64 deletions
diff --git a/cursor.lisp b/cursor.lisp deleted file mode 100644 index d3012ab..0000000 --- a/cursor.lisp +++ /dev/null @@ -1,31 +0,0 @@ -(in-package #:cursor) - -(defclass text () - ((data :type simple-string :initarg :data :reader data :initform "") - (index :type (unsigned-byte 44) :initarg :index :accessor index :initform 0))) - -(defun has-data? (cursor) - (< (index cursor) (length (data cursor)))) - -(defun peek (cursor) - (char (data cursor) - (index cursor))) - -(defun advance (cursor) - (make-instance 'text - :data (data cursor) - :index (+ (index cursor) 1))) - -(defun distance (from to) - (- (index to) - (index from))) - -(defmethod print-object ((obj text) stream) - (print-unreadable-object (obj stream :type t) - (let ((str (if (has-data? obj) - (format nil "~{~a[4;33m~a[m~a~}" - (str:context-window (data obj) - (index obj) - :side-length 10)) - "END OF DATA"))) - (substitute #\↲ #\Newline str)))) diff --git a/def.lisp b/def.lisp new file mode 100644 index 0000000..18fcd9e --- /dev/null +++ b/def.lisp @@ -0,0 +1,17 @@ +(in-package #:def) + +(defmacro defclass (name parents &body simple-slots) + (let (slots) + (dolist (slot simple-slots) + (if (symbolp slot) + (push `(,slot :initarg ,(intern (symbol-name slot) 'keyword) :accessor ,slot) slots) + (let ((slot-name (first slot)) + (slot-type (second slot)) + (slot-form (third slot))) + (cond ((and slot-type slot-form) + (push `(,slot-name :initarg ,(intern (symbol-name slot-name) 'keyword) :accessor ,slot-name :type ,slot-type :initform ,slot-form) slots)) + (slot-type + (push `(,slot-name :initarg ,(intern (symbol-name slot-name) 'keyword) :accessor ,slot-name :type ,slot-type) slots)) + (t + (push `(,slot-name :initarg ,(intern (symbol-name slot-name) 'keyword) :accessor ,slot-name) slots)))))) + `(cl:defclass ,name ,parents ,slots))) diff --git a/package.lisp b/package.lisp index e6ed7b5..19e97a8 100644 --- a/package.lisp +++ b/package.lisp @@ -1,12 +1,7 @@ -(defpackage #:cursor +(defpackage #:def (:use #:cl) - (:export #:text - #:index - #:data - #:has-data? - #:peek - #:advance - #:distance)) + (:shadow #:defclass) + (:export #:defclass)) (defpackage #:color (:use #:cl) @@ -35,9 +30,7 @@ #:underscore->hyphen #:pascal->kebab #:upcase->pascal - #:read-file - #:line-and-column - #:context-window)) + #:read-file)) (defpackage #:small-cl (:use #:cl) @@ -52,23 +52,3 @@ (format result "~a" (char-downcase (char str i))) (format result "~a" (char str i)))) (get-output-stream-string result))) - -(defun line-and-column (str index) - (let ((line 1) (column 1)) - (dotimes (i index) - (let ((c (char str i))) - (case c - (#\Newline - (incf line) - (setf column 1)) - (t (incf column))))) - (cons line column))) - -(defun context-window (str index &key (side-length 20)) - (let ((begin (max (- index side-length) 0)) - (end (min (+ index side-length) (length str))) - (result '())) - (push (subseq str begin index) result) - (push (elt str index) result) - (push (subseq str (1+ index) end) result) - result)) @@ -2,9 +2,9 @@ :serial nil :components ((:file "package") + (:file "def") (:file "queue") (:file "char") (:file "symbol") (:file "color") - (:file "str") - (:file "cursor"))) + (:file "str"))) |
