1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 13:30:26 +02:00

peg: helper macro docstrings

* module/ice-9/peg.scm: Convert the helper macro comments into
  docstrings.
This commit is contained in:
Andy Wingo 2011-02-18 10:33:03 +01:00
parent 09a6a7a44a
commit 87c3ef2f95

View file

@ -37,49 +37,45 @@
#:use-module (system base pmatch) #:use-module (system base pmatch)
#:use-module (ice-9 pretty-print)) #:use-module (ice-9 pretty-print))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;
;;;;; LOOPING CONSTRUCTS ;;; Helper Macros
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;
;; Perform ACTION. If it succeeded, return its return value. If it failed, run
;; IF_FAILS and try again
(define-syntax until (define-syntax until
(syntax-rules () (syntax-rules ()
"Evaluate TEST. If it is true, return its value. Otherwise,
execute the STMTs and try again."
((_ test stmt stmt* ...) ((_ test stmt stmt* ...)
(let lp () (let lp ()
(or test (or test
(begin stmt stmt* ... (lp))))))) (begin stmt stmt* ... (lp)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; GENERIC LIST-PROCESSING MACROS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Return #t if the list has only one element (calling length all the time on
;; potentially long lists was really slow).
(define-syntax single? (define-syntax single?
(syntax-rules () (syntax-rules ()
"Return #t if X is a list of one element."
((_ x) ((_ x)
(pmatch x (pmatch x
((_) #t) ((_) #t)
(else #f))))) (else #f)))))
;; Push an object onto a list.
(define-syntax push! (define-syntax push!
(syntax-rules () (syntax-rules ()
"Push an object onto a list."
((_ lst obj) ((_ lst obj)
(set! lst (cons obj lst))))) (set! lst (cons obj lst)))))
;; If SYM is a list of one element, return (car SYM), else return SYM.
(define-syntax single-filter (define-syntax single-filter
(syntax-rules () (syntax-rules ()
"If EXP is a list of one element, return the element. Otherwise
return EXP."
((_ exp) ((_ exp)
(pmatch exp (pmatch exp
((,elt) elt) ((,elt) elt)
(,elts elts))))) (,elts elts)))))
;; If OBJ is non-null, push it onto LST, otherwise do nothing.
(define-syntax push-not-null! (define-syntax push-not-null!
(syntax-rules () (syntax-rules ()
"If OBJ is non-null, push it onto LST, otherwise do nothing."
((_ lst obj) ((_ lst obj)
(if (not (null? obj)) (if (not (null? obj))
(push! lst obj))))) (push! lst obj)))))