@@ -120,10 +120,12 @@ of a subroutine:
120
120
which emphasizes the fact that a L < C < Regex > |/type/Regex> object represents code
121
121
rather than data:
122
122
123
- &S ~~ Code; # OUTPUT: True
123
+ = begin code :preamble<my sub S { /pattern/ }; my regex R { pattern };>
124
+ &S ~~ Code; # OUTPUT: True
124
125
125
- &R ~~ Code; # OUTPUT: True
126
- &R ~~ Method; # OUTPUT: True (A Regex is really a Method!)
126
+ &R ~~ Code; # OUTPUT: True
127
+ &R ~~ Method; # OUTPUT: True (A Regex is really a Method!)
128
+ = end code
127
129
128
130
Also unlike with the C < rx > form for defining an anonymous regex, the definition
129
131
of a named regex using the C < regex > keyword does not allow for adverbs to be
@@ -136,11 +138,23 @@ Alternatively, by way of shorthand, it is also possible (and recommended) to use
136
138
the C < rule > and C < token > variants of the C < regex > declarator for defining a
137
139
C < Regex > when the C < :ratchet > and C < :sigspace > adverbs are of interest:
138
140
139
- regex R { :r pattern }; # apply :r (:ratchet) to entire pattern
140
- token R { pattern }; # same thing: 'token' implies ':r'
141
+ = for code
142
+ regex R { :r pattern }; # apply :r (:ratchet) to entire pattern
143
+
144
+ and, alternatively
145
+
146
+ = for code
147
+ token R { pattern }; # same thing: 'token' implies ':r'
148
+
149
+ Or
150
+
151
+ = for code
152
+ regex R { :r :s pattern }; # apply :r (:ratchet) and :s (:sigspace) to pattern
141
153
142
- regex R { :r :s pattern }; # apply :r (:ratchet) and :s (:sigspace) to pattern
143
- rule R { pattern }; # same thing: 'rule' implies ':r:s'
154
+ with this alternative:
155
+
156
+ = for code
157
+ rule R { pattern }; # same thing: 'rule' implies ':r:s'
144
158
145
159
Named regexes may be used as building blocks for other regexes, as they are
146
160
methods that may called from within other regexes using the C « <regex-name> »
@@ -185,11 +199,11 @@ I«Smartmatch: "string" ~~ /pattern/, or "string" ~~ /<R>/»
185
199
L < Smartmatching|/language/operators#index-entry-smartmatch_operator > a string
186
200
against a C < Regex > performs a regex match of the string against the C < Regex > :
187
201
188
- say "Go ahead, make my day." ~~ / \w+ /; # OUTPUT: «「Go」»
202
+ say "Go ahead, make my day." ~~ / \w+ /; # OUTPUT: «「Go」»
189
203
190
204
my regex R { me|you };
191
- say "You talkin' to me?" ~~ / <R> /; # OUTPUT: «「me」 R => 「me」»
192
- say "May the force be with you. ~~ &R ; # OUTPUT: «「you」»
205
+ say "You talkin' to me?" ~~ / <R> /; # OUTPUT: «「me」 R => 「me」»
206
+ say "May the force be with you." ~~ &R ; # OUTPUT: «「you」»
193
207
194
208
The different outputs of the last two statements show that these two ways of
195
209
smartmatching against a named regex are not identical. The difference arises
0 commit comments