File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -761,6 +761,28 @@ Becomes:
761
761
If a regex is declared with the C < rule > keyword, both the C < :sigspace > and
762
762
C < :ratchet > adverbs are implied.
763
763
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
+
764
786
= head2 Matching Adverbs
765
787
766
788
In contrast to regex adverbs, which are tied to the declaration of a regex,
You can’t perform that action at this time.
0 commit comments