From b4bd3174e8a21cee13a70de7b144c47a670be82f Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Tue, 18 Dec 2018 22:35:48 -0500 Subject: [PATCH 1/2] add documentation for txexpr as a match pattern --- txexpr/scribblings/txexpr.scrbl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/txexpr/scribblings/txexpr.scrbl b/txexpr/scribblings/txexpr.scrbl index e1ae72a..80c1fd8 100644 --- a/txexpr/scribblings/txexpr.scrbl +++ b/txexpr/scribblings/txexpr.scrbl @@ -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?] -- 2.25.1 From b84257e54716e4893192b87db8920cb8ed0d3f80 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Wed, 19 Dec 2018 02:12:43 -0500 Subject: [PATCH 2/2] docs: require racket/match for examples --- txexpr/scribblings/txexpr.scrbl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/txexpr/scribblings/txexpr.scrbl b/txexpr/scribblings/txexpr.scrbl index 80c1fd8..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} -- 2.25.1