From 151ccb002753013881f9e39826a31df3012e19c9 Mon Sep 17 00:00:00 2001 From: Ian Henry Date: Tue, 3 Dec 2024 20:20:12 -0800 Subject: [PATCH] document the (split) PEG special --- content/docs/peg.mdz | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/content/docs/peg.mdz b/content/docs/peg.mdz index 49162a1..e4fb6c0 100644 --- a/content/docs/peg.mdz +++ b/content/docs/peg.mdz @@ -218,7 +218,17 @@ compiled to bytecode). @code`patt` cannot match more than @code`window-patt`; it will see end-of-input at the end of the substring matched by @code`window-patt`. If @code`patt` also succeeds, @code`sub` will - advance to the end of what @code`window-patt` matched. }}} + advance to the end of what @code`window-patt` matched. }} + + @tr{@td{@code`(split separator-patt patt)` } + @td{ Split the remaining input by @code`separator-patt`, and execute + @code`patt` on each substring. @code`patt` will execute with its + input constrained to the next instance of @code`separator-patt`, + as if narrowed by @code`(sub (to separator-patt) ...)`. + @code`split` will continue to match separators and patterns until + it reaches the end of the input; if you don't want to match to the + end of the input you should first narrow it with + @code`(sub ... (split ...))`. }}} PEGs try to match an input text with a pattern in a greedy manner. This means that if a rule fails to match, that rule will fail and not try again. The only