Allow the user of multi-line pipes#327
Conversation
Yeah, we should avoid that. The old operator should be able to support it, right after parsing it, you can force to flush the whitespaces tokens coming and attach them. |
It's actually the pipe operator in scientific. We cannot change that for regular Scriban that was following Liquid syntax for that. |
Fix up broken test case
Not sure if you had something else in mind but I solved this by simply looking ahead via the So the current syntax is: but if you write "test" | |
Possibly I have misunderstood you? DId you mean to try and handle this by looking ahead for whitespace tokens in ParserExpression when a VerticalBar is encountered? The reason to introduce a PipeOverLineBreak Token originally was to avoid breaking any code that assume a VerticalBar really was just a single-character token (as the name suggests). |
See my comment above. |
|
LGTM, thanks! |
|
Thanks for pushing the last changes! |
No problem - very much looking forward to using this feature :-) |
This change allows pipes to be chained over multiple lines, for example
This is particularly useful when trying to write text- or array- processing pipelines where otherwise you would need to write all operations on a single (very long!) line.
I've introduced a new token for this "|-" (the minus is interpreted similarly to the minus in "{{-". Though it would be possible to modify the logic for a bare "|" to skip trailing whitespace+newline (and would be more visually pleasing IMO) I'm not sure whether that might introduce breaking changes; by introducing a new token the user is forced to opt-in to the behaviour.
The new behaviour is only available in non-scientific mode but could be added to that quite easily if desired.
There is still an issue that it's possible to break existing code that looks like
-123 |- math.plus 1(space between '-' and 'math') or some variation thereof. If that is a concern, more aggressive lookahead can be introduced; if this is done then it would probably also be possible to revert to treating|\s*\ras a multi-line pipe for a nicer syntax...FWIW I quite like the visual appearance of
but I'm not sure if |> has a special meaning in Scientific mode?