From b80218b1b6b19f253d5057c2b811ce724395686c Mon Sep 17 00:00:00 2001 From: Alex Knauth Date: Wed, 19 Dec 2018 20:07:14 -0500 Subject: [PATCH] add documentation for txexpr as a match pattern (#10) * add documentation for txexpr as a match pattern * docs: require racket/match for examples --- txexpr/scribblings/txexpr.scrbl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/txexpr/scribblings/txexpr.scrbl b/txexpr/scribblings/txexpr.scrbl index e1ae72a..17e0f74 100644 --- a/txexpr/scribblings/txexpr.scrbl +++ b/txexpr/scribblings/txexpr.scrbl @@ -7,7 +7,7 @@ (for-label racket txexpr txexpr/stx xml rackunit)) @(define my-eval (make-base-eval)) -@(my-eval `(require txexpr xml rackunit)) +@(my-eval `(require racket/match txexpr xml rackunit)) @title{txexpr: Tagged X-expressions} @@ -229,6 +229,23 @@ Assemble a @racket[_txexpr] from its parts. If you don't have attributes, but yo (get-attrs tx) (get-elements tx)) ] +The @racket[txexpr] form can also be used as a match pattern: + +@examples[#:eval my-eval +(match '(div) + [(txexpr tag attrs elems) + (values tag attrs elems)]) +(match '(div "Hello" (p "World")) + [(txexpr tag attrs elems) + (values tag attrs elems)]) +(match '(div "Hello" (p "World")) + [(txexpr 'div attrs1 (list elems1 ... (txexpr 'p attrs2 elems2))) + (values attrs1 elems1 attrs2 elems2)]) +(match '(div ((id "top")) "Hello" (p "World")) + [(txexpr 'div attrs1 (list elems1 ... (txexpr 'p attrs2 elems2))) + (values attrs1 elems1 attrs2 elems2)]) +] + @defproc[ (txexpr* [tag txexpr-tag?]