AFAIK, there's no a single way to do it with pegs module. With pegs module you
can test whether the string satisfies the definition and you should code what
to do with captured instance
for example
import pegs
var
ops = peg"\skip (\s*) '+' / '-' / '/' / '*'"
prim = peg"\skip (\s*) {\d+} '.' {\d+} / {\d+}
optionalops = sequence(capture ops, prim)
mathpeg = * sequence(prim, * optionalops)
theline = "1 + 1.5 - 2.0 / 3"
if theline =~ mathpeg:
var matches = newseq[string](10) // should allocate it first, if not we
will get error
discard theline.find(mathpeg, matches)
echo matches // ["1","+", "-", "1.5", "2.0", "/", "3", "", "", ""]
Run
so you must check which peg definition the line satisfies, get the captured
instances, and do something with it