Skip to content

Commit 5607c3d

Browse files
committed
Examples for overriding ws
1 parent b7c434d commit 5607c3d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/Language/regexes.pod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,28 @@ Becomes:
761761
If a regex is declared with the C<rule> keyword, both the C<:sigspace> and
762762
C<:ratchet> adverbs are implied.
763763
764+
Grammars provide an easy way to override what C«<.ws>» matches:
765+
766+
grammar Demo {
767+
token ws {
768+
<!ww> # only match when no within a word
769+
\h* # only match horizontal whitespace
770+
}
771+
rule TOP { # called by Demo.parse;
772+
a b '.'
773+
}
774+
}
775+
776+
# doesn't parse, whitspace required between a and b
777+
say so Demo.parse("ab."); # False
778+
say so Demo.parse("a b."); # True
779+
say so Demo.parse("a\tb ."); # True
780+
# \n is vertical whitespace, so no match
781+
say so Demo.parse("a\tb\n."); # False
782+
783+
When parsing file formats where some whitespace (for example vertical
784+
whitespace) is significant, it is advisable to override C<ws>.
785+
764786
=head2 Matching Adverbs
765787
766788
In contrast to regex adverbs, which are tied to the declaration of a regex,

0 commit comments

Comments
 (0)