Skip to content

Commit c206090

Browse files
authored
Correct erroneous info on default <ws> token
1 parent 5b1788c commit c206090

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

doc/Language/grammars.pod6

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,21 @@ Is the same as:
192192
193193
token entry { <key> <.ws> ’=’ <.ws> <value> <.ws> } # . = non-capturing
194194
195-
The default C<ws> matches "whitespace", such a sequence of spaces (of whatever
196-
type), newlines, unspaces, or heredocs.
197-
198-
It's perfectly fine to provide your own C<ws> token:
195+
The default C<ws> matches one or more whitespace characters (C<\s>) or a
196+
word boundary (C«<|w>»):
197+
198+
# First <.ws> matches word boundary at the start of the line
199+
# and second <.ws> matches the whitespace between 'b' and 'c'
200+
say 'ab c' ~~ /<.ws> ab <.ws> c / # OUTPUT: «「ab c」␤»
201+
202+
# Failed match: there neither any whitespace nor a word
203+
# boundary between 'a' and 'b'
204+
say 'ab' ~~ /. <.ws> b/ # OUTPUT: «Nil␤»
205+
206+
# Successful match: there is a word boundary between ')' and 'b'
207+
say ')b' ~~ /. <.ws> b/ # OUTPUT: «「)b」␤»
208+
209+
You can also redefine the default C<ws> token:
199210
200211
grammar Foo {
201212
rule TOP { \d \d }

0 commit comments

Comments
 (0)