From dc5e7b12d278f4abe8e357c6bdfc7e680d882cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 19 Sep 2016 22:05:02 +0200 Subject: [PATCH] Added try-order-point< and try-order-point> --- main.rkt | 5 +- private/no-order.rkt | 13 ++++- .../extensible-parser-specifications.scrbl | 48 +++++++++++++++++-- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/main.rkt b/main.rkt index f59b3a5..d64bb12 100644 --- 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 index 73b1534..7d6aa81 100644 --- 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 index b41d32b..ae537af 100644 --- 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)]{