From 66b6d675055eb8a5017376eb6f43d609887d1289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 15 Jun 2025 03:49:14 -0300 Subject: Update parser interface --- extra.lisp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'extra.lisp') diff --git a/extra.lisp b/extra.lisp index 9451ce8..20a13b1 100644 --- a/extra.lisp +++ b/extra.lisp @@ -11,7 +11,7 @@ (push name name-list) (push `(,name (unit ,c)) binding-list)))) `(comp ,(reverse binding-list) - (coerce ,(cons 'list (reverse name-list)) 'string)))) + ,(cons 'list (reverse name-list))))) (defparameter nothing (new nil)) @@ -19,27 +19,28 @@ (defun optional (p) (one-of p nothing)) -(defun many (p) +(defun many (p &key all) (comp ((x p) - (xs (optional (many p)))) - (if x (cons x xs) xs))) + (xs (if all + (one-of end + (many p :all all)) + (optional (many p))))) + (if x (cons x xs) xs))) (defun repeat (p min &optional (max 0)) (if (> min 0) (comp ((x p) (xs (repeat p (1- min) (1- max)))) - (cons x xs)) + (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)) + (if x (cons x xs) x)) nothing))) (defun whitespace? (x) - (some (lambda (y) (char= x y)) '(#\Space #\Newline #\Return #\Tab))) - -(defparameter whitespace - (optional (many (unit whitespace?)))) + (or (char= x #\Space) + (not (graphic-char-p x)))) (defun separated-list (p separator) (comp ((v p) @@ -47,4 +48,4 @@ (vn (if sep (separated-list p separator) nothing))) - (cons v vn))) + (cons v vn))) -- cgit v1.2.3