global.scrbl (4820B)
1 #lang scribble/manual 2 @require[scribble/example 3 "utils.rkt" 4 @for-label[phc-toolkit/untyped 5 extensible-parser-specifications 6 generic-syntax-expanders 7 racket/base 8 syntax/parse 9 (only-in racket/base [... …])]] 10 11 @title{Global operations} 12 13 The global patterns presented below match all of the given 14 @racket[#,ntax-pattern]s, like @racket[~and] does, and perform a global 15 aggregation over all the values corresponding to successful matches of a global 16 pattern using the same @racket[#,tribute-name]. 17 18 After the whole @racket[~seq-no-order] or @racket[~no-order] finished matching 19 its contents, but before "post" operations are executed, the attribute 20 @racket[#,tribute-name] is bound to 21 @racket[(_aggrgate-function _value₁ ... _valueₙ)], where each @racket[valueᵢ] is 22 the value which was passed to an occurrence of @racket[~global-or] with the same 23 @racket[_attribute-name], and which successfully matched. The 24 @racket[_aggregate-function] will be @racket[or] for @racket[~global-or], 25 @racket[and] for @racket[~global-and] or @racket[+] for 26 @racket[~global-counter]. 27 28 Each @racket[valueᵢ] is computed in the context in which it appears, after the 29 @racket[_syntax-pattern]s. This means that it can access: 30 @itemlist[ 31 @item{attributes already bound in the current alternative clause within the 32 current @racket[~no-order] or @racket[~seq-no-order]} 33 @item{attributes bound by the @racket[_syntax-patterns]s} 34 @item{attributes already bound outside of the @racket[~no-order] or 35 @racket[~seq-no-order]} 36 @item{but it cannot access attributes bound in other alternative clauses within 37 the current @racket[~no-order] or @racket[~seq-no-order].}] 38 39 The @racket[valueᵢ] are aggregated with @racket[or], @racket[and] or @racket[+] 40 in the order in which they appear in the @racket[~no-order] or 41 @racket[~seq-no-order]. If a @racket[valueᵢ] appears under ellipses, or as part 42 of an alternative clause which can match more than once (i.e. not @racket[~once] 43 or @racket[~optional]), then each match within that @racket[valueᵢ] group is 44 aggregated in the order it appears. 45 46 Since this notion of order is rather complex, it is possible that future 47 versions of this library will always return a boolean (@racket[#f] or 48 @racket[#t] for @racket[~global-or] and @racket[~global-and], which would make 49 the notion of order irrelevant. 50 51 @defform[#:kind "eh-mixin expander" 52 (~global-or attribute-name+value #,ntax-pattern ...) 53 #:grammar 54 [(attribute-name+value #,tribute-name 55 [#,tribute-name valueᵢ])]]{ 56 Matches all of the given @racket[#,ntax-pattern]s, like @racket[~and] does, and 57 perform a global @racket[or] over all the values corresponding to successful 58 matches of a global pattern using the same @racket[#,tribute-name]. See above 59 for a description of how global operations work. 60 61 If the @racket[valueᵢ] is omitted, @racket[#t] is used as a default. 62 63 The result is always transformed into a boolean, so @racket[_attribute-name] is 64 always bound to either @racket[#t] or @racket[#f].} 65 66 @defform[#:kind "eh-mixin expander" 67 (~global-and attribute-name+value #,ntax-pattern ...) 68 #:grammar 69 [(attribute-name+value [#,tribute-name valueᵢ])]]{ 70 Matches all of the given @racket[#,ntax-pattern]s, like @racket[~and] does, and 71 perform a global @racket[and] over all the values corresponding to successful 72 matches of a global pattern using the same @racket[#,tribute-name]. See above 73 for a description of how global operations work. 74 75 If there is at least one occurrence of @racket[~global-and] for that 76 @racket[_attribute-name] which successfully matches, the result of the 77 @racket[(and valueᵢ ...)] is always coerced to a boolean, so 78 @racket[_attribute-name] is always bound to either @racket[#t] or @racket[#f]. 79 80 If there are no matches at all, the special value @racket['none] is used 81 instead of @racket[#t] as would be produced by @racket[(and)].} 82 83 @defform[#:kind "eh-mixin expander" 84 (~global-counter attribute-name+value #,ntax-pattern ...) 85 #:grammar 86 [(attribute-name+value #,tribute-name 87 [#,tribute-name valueᵢ])]]{ 88 Matches all of the given @racket[#,ntax-pattern]s, like @racket[~and] does, and 89 perform a global @racket[+] over all the values corresponding to successful 90 matches of a global pattern using the same @racket[#,tribute-name]. See above 91 for a description of how global operations work. 92 93 If the @racket[valueᵢ] is omitted, @racket[1] is used as a default.} 94 95 @;@defform[(aggregate-global-or)] 96 @;@defform[(aggregate-global-and)] 97 @;@defform[(aggregate-global-counter)]