Is there a way to require mandatory whitespace using Pest?

229 views Asked by At

I'm making an esolang based on a conlang, which rather inevitably involves whitespace-separated words. Contrary to a regular programming language using symbols, this means that I end up needing mandatory whitespace between nearly every single token. This makes the grammar much harder to read, write, evolve and maintain; is there a smart way of making whitespace mandatory? Like some overload of the ~ operator?

TL;DR I'd like a concise way of expressing something like this:

WHITESPACE = ...
a = { "a" }
b = { "b" }
rule = [modifier]{ a ~ b }

That would match a b and a b but not ab.

1

There are 1 answers

2
ivanjermakov On

You can use Pest's atomic rule to prevent implicit whitespace and handle it manually:

rule = @{ a ~ WHITESPACE+ ~ b }
a = { "a" }
b = { "b" }
WHITESPACE = _{ " " | "\t" }