From 9566e92321a1ed29a7f5903a3ba4ab16de3783b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 31 Dec 2025 16:14:31 -0300 Subject: Type check functions --- core.lisp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'core.lisp') diff --git a/core.lisp b/core.lisp index 833eb41..43dd234 100644 --- a/core.lisp +++ b/core.lisp @@ -3,6 +3,7 @@ (defparameter nothing (new nil)) +(declaim (ftype (function (symbol list) list) normalize)) (defun normalize (sym expression) (nsubst-if sym (lambda (x) @@ -24,19 +25,21 @@ (setf predicate (normalize 'it predicate)))) (t (error (format nil "Invalid predicate: ~a." predicate)))) - `(lambda (start input) - (declare (ignore start)) - (if (has-data? input) - (let ((it (peek input))) - (if ,predicate - (make-parsing :tree it - :start input - :end (advance input)) - (make-failure :place input - :message (format nil "Expected: ~a, Got: ~:c." ',predicate it)))) - (make-failure :place input - :message (format nil "Reached end of input. Expected: ~a." ',predicate))))) + `(the parser + (lambda (start input) + (declare (ignore start)) + (if (has-data? input) + (let ((it (peek input))) + (if ,predicate + (make-parsing :tree it + :start input + :end (advance input)) + (make-failure :place input + :message (format nil "Expected: ~a, Got: ~:c." ',predicate it)))) + (make-failure :place input + :message (format nil "Reached end of input. Expected: ~a." ',predicate)))))) +(declaim (ftype (function (parser parser &rest parser) parser) one-of)) (defun one-of (first-parser second-parser &rest other-parsers) (lambda (start input) (declare (ignore start)) @@ -63,9 +66,11 @@ (t (error (format nil "Invalid return value: ~a." r)))))) result))) +(declaim (ftype (function (parser) parser) optional)) (defun optional (p) (one-of p nothing)) +(declaim (ftype (function (parser &key (:all t)) parser) many)) (defun many (p &key all) (lambda (start input) (declare (ignore start)) -- cgit v1.2.3