commit dc5e7b12d278f4abe8e357c6bdfc7e680d882cc2
parent 16290d0fcc36f1f0d084c4d4987524c80886506b
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Mon, 19 Sep 2016 22:05:02 +0200
Added try-order-point< and try-order-point>
Diffstat:
3 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/main.rkt b/main.rkt
@@ -24,6 +24,8 @@
~order-point
order-point<
order-point>
+ try-order-point<
+ try-order-point>
~mixin
~post-check
~post-fail
@@ -38,4 +40,5 @@
aggregate-global-counter
(for-template define-syntax/parse+simple)
define/syntax-parse+simple
- try-attribute)
+ try-attribute
+ if-attribute)
diff --git a/private/no-order.rkt b/private/no-order.rkt
@@ -28,7 +28,8 @@
phc-toolkit/untyped
racket/list
racket/pretty)
- "parameters.rkt")
+ "parameters.rkt"
+ "try-attribute.rkt")
(provide define-eh-alternative-mixin
~seq-no-order
@@ -36,6 +37,8 @@
~order-point
order-point<
order-point>
+ try-order-point<
+ try-order-point>
(expander-out eh-mixin))
(define-expander-type eh-mixin)
@@ -159,4 +162,10 @@
(define-syntax-rule (order-point> a b)
(and (attribute a) (attribute b)
- (> (attribute a) (attribute b))))
-\ No newline at end of file
+ (> (attribute a) (attribute b))))
+
+(define-syntax-rule (try-order-point< a b)
+ (if-attribute a (if-attribute b (order-point< a b) #f) #f))
+
+(define-syntax-rule (try-order-point> a b)
+ (if-attribute a (if-attribute b (order-point> a b) #f) #f))
+\ No newline at end of file
diff --git a/scribblings/extensible-parser-specifications.scrbl b/scribblings/extensible-parser-specifications.scrbl
@@ -136,21 +136,61 @@
#:grammar
[(a #,tribute-name)
(b #,tribute-name)]]{
-
Returns @racket[#t] when the first element matched by
@racket[(~order-point a #,ntax-pattern ...)] occurs before the first element
matched by @racket[(~order-point b #,ntax-pattern ...)]. Otherwise, returns
- @racket[#f].}
+ @racket[#f].
+
+ This operation does not fail if @racket[a] or @racket[b] are bound to
+ @racket[#f] (i.e. their corresponding @racket[_syntax-pattern ...] did not
+ match). Instead, in both cases, it returns @racket[#f].}
@defform[(order-point> a b)
#:grammar
[(a #,tribute-name)
(b #,tribute-name)]]{
-
Returns @racket[#t] when the first element matched by
@racket[(~order-point a #,ntax-pattern ...)] occurs after the first element
matched by @racket[(~order-point b #,ntax-pattern ...)]. Otherwise, returns
- @racket[#f].}
+ @racket[#f].
+
+ This operation does not fail if @racket[a] or @racket[b] are bound to
+ @racket[#f] (i.e. their corresponding @racket[_syntax-pattern ...] did not
+ match). Instead, in both cases, it returns @racket[#f].}
+
+@defform[(try-order-point< a b)
+ #:grammar
+ [(a #,tribute-name)
+ (b #,tribute-name)]]{
+
+ Like @racket[order-point<], except that it does not fail if @racket[a] or
+ @racket[b] are not attributes, or if they are bound to @racket[#f]. Instead, in
+ all those cases, it returns @racket[#f].
+
+ It can be used as follows:
+
+ @racketblock[
+ (~post-fail "a must appear after b"
+ #:when (try-order-point< a b))]
+
+ The same caveats as for @racket[try-attribute] apply.}
+
+@defform[(try-order-point> a b)
+ #:grammar
+ [(a #,tribute-name)
+ (b #,tribute-name)]]{
+
+ Like @racket[order-point>], except that it does not fail if @racket[a] or
+ @racket[b] are not attributes, or if they are bound to @racket[#f]. Instead, in
+ all those cases, it returns @racket[#f].
+
+ It can be used as follows:
+
+ @racketblock[
+ (~post-fail "a must appear before b"
+ #:when (try-order-point> a b))]
+
+ The same caveats as for @racket[try-attribute] apply.}
@defform[(~mixin #,-alternative-mixin)]{