I would like to have some more general parsers, like for example paren that would take a parser and wrap it with parentheses:
paren(Parser, Result) -->
"(", some_magic_dcg_call(Parser, Result), ")".
:- phrase(paren(number, N), "(123)").
123
:- phrase(paren(someatom, A), "(a)").
a
I tried call and dcg_call, but they don't seem to solve the problem. How can I run an arbitrary parser inside another parser?
This solution using
callworks in SWI-Prolog:Tests: