[m-users.] parsing, seeking advice on simple combinator project and also operators.

Volker Wysk post at volker-wysk.de
Sun Oct 30 04:53:42 AEDT 2022


Hi

Here's a parser combinator for you, using DCG syntax:


:- pred repeatmax0(pred(T, list(char), list(char)), 
                   list(T), 
                   list(char), list(char)).
:- mode repeatmax0(pred(out, in, out) is det,     out, in, out) is det.
:- mode repeatmax0(pred(out, in, out) is semidet, out, in, out) is det.
:- mode repeatmax0(pred(out, in, out) is multi,   out, in, out) is multi.
:- mode repeatmax0(pred(out, in, out) is nondet,  out, in, out) is nondet.

repeatmax0(Pars, Values) -->
    ( if   Pars(Val)
      then { Values = [Val|Vals] },
           repeatmax0(Pars, Vals)
      else { Values = [] }
    ).


It repeats applying a parser (Pars) as often as possible and collects the
results in a list (Values).

Bye
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20221029/f4ecc258/attachment.sig>


More information about the users mailing list