diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-06-23 02:22:51 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2025-06-23 02:22:51 -0300 |
commit | 1c1162747d8d7e12140329a105c0776d5555a351 (patch) | |
tree | 5feaaa2b9ac357732c9d2a9c922cfaa9356dd76c /extra.lisp | |
parent | 4d355a842737f7938d148c53338ce6f3fa055628 (diff) | |
download | monparser-1c1162747d8d7e12140329a105c0776d5555a351.tar.gz monparser-1c1162747d8d7e12140329a105c0776d5555a351.zip |
Diffstat (limited to 'extra.lisp')
-rw-r--r-- | extra.lisp | 41 |
1 files changed, 27 insertions, 14 deletions
@@ -1,11 +1,24 @@ (in-package #:monparser) -(defun whitespace? (x) - (or (char= x #\Space) - (not (graphic-char-p x)))) - (defparameter whitespace - (many (unit #'whitespace?))) + (many (unit #'char:whitespace?))) + +(defparameter end-of-input + (lambda (input) + (if (cursed:has-data? input) + (make-failure :place input :message "Didn't reach end of input.") + (make-parsing :tree nil :start input :end input)))) + +(defun repeat (p min &optional (max 0)) + (if (> min 0) + (comp ((x p) + (xs (repeat p (1- min) (1- max)))) + (cons x xs)) + (if (> max 0) + (comp ((x (optional p)) + (xs (repeat p 0 (if x (1- max) 0)))) + (if x (cons x xs) x)) + nothing))) (defmacro literal (word) (when (not (stringp word)) @@ -20,13 +33,13 @@ `(comp ,(reverse binding-list) ,(cons 'list (reverse name-list))))) -(defun separated-list (p separator) - (many - (comp ((v p) - (_ (optional separator))) - v))) +(defmacro within (left p right) + `(comp ((_ ,left) + (cell ,p) + (_ ,right)) + cell)) -(defun surround (left p &optional right) - (comp ((_ left) - (value p) - (_ (or right nothing))))) +(defmacro interlinked (p separator) + `(many (comp ((cell ,p) + (_ (optional ,separator))) + cell))) |