Skip to content

Commit c0e9876

Browse files
committed
Adds more examples to the definition of ws
Thanks go @jnthn for his clarification in StackOverflow. Closes #1729
1 parent e89a63b commit c0e9876

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

doc/Language/grammars.pod6

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ Please bear in mind that we're preceding C<ws> with a dot to avoid capturing,
225225
which we are not interested in. Since in general whitespace is a separator, this
226226
is how it's mostly found.
227227
228-
When C<rule> instead of C<token> is used, any whitespace after terms and closing
229-
parenthesis/brackets is turned into a non-capturing call to C<ws>,
230-
written as C«<.ws>» where C<.> means non-capturing. That is to say:
228+
When C<rule> instead of C<token> is used, C<:sigspace> is enabled by default and
229+
any whitespace after terms and closing parenthesis/brackets is turned into a
230+
non-capturing call to C<ws>, written as C«<.ws>» where C<.> means non-capturing.
231+
That is to say:
231232
232233
rule entry { <key> '=' <value> }
233234
@@ -246,6 +247,13 @@ You can also redefine the default C<ws> token:
246247
token ws { \h* }
247248
}.parse: "4 \n\n 5"; # Fails
248249
250+
And even capture it, but you need to use it explicitly:
251+
252+
=for code
253+
grammar Foo { rule TOP {\d <ws> \d} };
254+
my $parsed = Foo.parse: "3 3";
255+
say $parsed<ws>; # OUTPUT: «「」␤»
256+
249257
250258
=head3 X«C<sym>|<sym>»
251259

0 commit comments

Comments
 (0)