Regex operators for sequences
From clojure.spec, but we need to rename some as ?, + and * are not valid in javascript identifiers.
catalt?=> qm? atMostOne?+=> plus? atLeastOne?*=> star? any?
So that we could
import {define, spec} from 'js.spec'
define("ingredient", spec.cat(
"quantity", spec.number,
"unit", spec.string))
define("odds-then-maybe-even", spec.cat(
"odds", spec.plus(spec.odd),
"even", spec.star(spec.even)))
Check to what extent we can leverage pamatcher.
I like the idea of naming them after what they do rather than describing the symbol, even though the symbol names are shorter.
One interesting thought is that all three of those quantifier (which is what the Perl docs call them) operators are really shorthand for {n,m}: ? === {0,1} * === {0,} + === {1,}. I wonder if we just use a single quantify or repeat method that takes three parameters (low, high, spec)? This is similar to the linked pamatcher's repeat.
I wonder if we just use a single quantify or repeat method that takes three parameters (low, high, spec)? This is similar to the linked pamatcher's repeat.
I think that's a good idea. We can still expose this function bound to predefined values for +, ?, *.