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

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
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

_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmNdaKYACgkQ+K4ydFOs
HoWVUQ/8Djtzhl3PLr3WJOkcO8tXDkiq1FGjAO5a0ziOAWDjla6L5JgT+XghHphI
EMMZ5M8XT0c6yN5tGdbqSW4aHS6n+QR6BG2GOt2+LwYbVbJBrBGSZBQcXKUTGBm3
3u0Cd5ZZnzV/FeOQRlvSzihz2mW0lk2hq5qLWI030oscUuZuzTMHup4gklLRfUsM
JMhhUxcoOl7UkpRc6P0fKdXXoV2kzrMWUnHpvDioe7zt5EeVX0+lMCFXNumh73ST
umU48YbeHM8tgKmdxqpa/euku//vumEGz7xjhq9oVp7x3OWutx0HrYIzscEJvPF6
yklu3CyM0+UQ8JheFSFkdmnzzmcY0Z8kCnlAQuW5x33eAIQEMz1ctshNfYjuKKbN
6ue1+eHpyuBeggCaC99d3wu2vfGLmTz7ij/u86O1qMg4b7eIPg9hmQT08YBD1I59
CEIDxQSc+MJ09N7lLGnm+ewcnQZXUhQml2OkvSlBKqU2DtbOjHQvR37WDGG1oJdL
XsSgEu5hpgA8tVPefX9JGc2XwUY+Hj47H0lStVgN8p50p1XmlLmlP4Olnpp/pdCx
qlenfiP1I/YTMHk/32Gn97eZt9Y0opR7yKfCFLCXiH9qVHb6MQNwAyhNR2iq9PQz
+oYFevigjTkevhzD6TkMOmdl4mqxEbANORDHqjAJ0FoK2S1VP2E=
=qtmj
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.