There's efficiency to be gained when you compose your parse rules ahead of time. But what if the rule depends on other things, and you want to generate a rule to splice in that gets composed in every time it's run?
>> num: 1 >> char: #"a" >> did parse ["a" "bb" "ccc"] [ some [ into [:( rule: reduce [num char] num: num + 1 char: char + 1 rule )] ] end ] == #[true]
(Note: You shouldn't need the block outside the GET-GROUP! for the INTO, but at the moment INTO isn't aware of these get groups in its immediate argument...so they have to go in a block rule. It will be updated to recognize them directly.)
If the expression inside the GET-GROUP! evaluates to a null, it splices nothing into the rule stream. With so many null-signaling routines to choose from, that's rather cool.
>> did parse "aaabbbcccddd" [ some "a" :(case [1 > 2 [[some "x"]] 4 > 3 [[some "b"]]]) some "c" :(switch 1 + 2 [ 4 [[some "z"]] 3 + 2 [[some "q"]] ]) some "d" end ] == #[true]
Though you can return BLOCK! rules to splice, you can also just return single WORD!s. At the moment, returning a
| is disabled, though that might be relaxed based on feedback and allowed to mean "skip to next rule" (but clearly this is going to be different from a
| in the source, as being literally in the source is a prerequisite to participating in the skipping.)