A parser combinator example...

Anoq of the Sun anoq@HardcoreProcessing.com
Tue, 26 Mar 2002 23:44:45 +0100


This is a multi-part message in MIME format.
--------------95E773A5FEC843ADB26DFD69
Content-Type: text/plain; charset=iso-8859-7
Content-Transfer-Encoding: 7bit

Hello again!


I can't seem to reproduce the problem in a small example - but
here is an excerpt of the code from the "real" program.
Unpack and:

cd HardcoreProcessing/
mlton sources.cm

What happens in the real program is that it first prints:

A, s, t, e, r, o, i, d, 5,

which is the characters it meets during parsing.
Then it prints:

A, s, t, e, r, o, i, d, 5, 5,

which is the list of characters returned from the repeat
parser combinator (which does some tricky stuff with recursion and
exception handling to avoid generating a huge exception
stack during recursion).

The output is OK when running this small example alone - but
it fails in a larger program. I hope that you might be able
to find the bug somehow. I should note that my program used
to work with MLton (the earlier versions) - and I just tested
the real program with SML/NJ and it still works fine here.

It could be some vety very sticky issues with buffering in BinIO - but
then I'm quite sure that it's not part of what I modified in BinIO :)
(but it could be that it just accidentally triggered a bug in, say, my
FuncBinIO module or something...)

Anyway - please ask if there is more I can do to help...


Cheers
-- 
http://www.HardcoreProcessing.com
--------------95E773A5FEC843ADB26DFD69
Content-Type: application/x-unknown-content-type-sml_auto_file;
 name="RepeatParserCombinatorTest.sml"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="RepeatParserCombinatorTest.sml"

KCogQ3JlYXRlIGEgYmluYXJ5IGZpbGUgd2l0aCB0aGUgc3RyaW5nICJBc3Rlcm9pZDUiIHRl
cm1pbmF0ZWQgd2l0aCA0IHplcm9zICopCnZhbCBvdXRTdHIgPSBCaW5JTy5vcGVuT3V0ICJS
ZXBlYXRQYXJzZXJDb21iaW5hdG9yLnR4dCIKdmFsIF8gPSBCaW5JTy5vdXRwdXQKICAgICAg
ICAgIChvdXRTdHIsCiAgICAgICAgICAgV29yZDhWZWN0b3IuZnJvbUxpc3QKICAgICAgICAg
ICAgICgobWFwIChmbiBjID0+IFdvcmQ4LmZyb21JbnQgKG9yZCBjKSkKICAgICAgICAgICAg
ICAgICAgIChleHBsb2RlICJBc3Rlcm9pZDUiKQogICAgICAgICAgICAgICkgQCBbMHcwLCAw
dzAsIDB3MCwgMHcwXQogICAgICAgICAgICAgKQogICAgICAgICAgKQp2YWwgXyA9IEJpbklP
LmNsb3NlT3V0IG91dFN0cgoKKCogTm93IGZvciB0aGUgY29tYmluYXRvciBwYXJzZXIgdGVz
dCB1c2luZyB0aGUgcmVwZWF0IGFuZCA+PiBjb21iaW5hdG9ycyAqKQpzdHJ1Y3R1cmUgRklP
ID0gRnVuY0JpbklPCgpsb2NhbApvcGVuIEJpbklPUGFyc2VyQ29tYmluYXRvcnMKaW4KCiAg
ICBmdW4gd29yZDhUb0NoYXIgdyA9CiAgICAgICAgICBjaHIgKFdvcmQ4LnRvSW50IHcpCgog
ICAgKCogRXh0cmFjdHMgZmlyc3QgdmVjdG9yIGVsZW1lbnQgYXMgd29yZDggKikKICAgIGZ1
biB3b3JkOHgxVG9Xb3JkOCB2ID0KICAgICAgICAgIFdvcmQ4VmVjdG9yLnN1YiAodiwgMCkK
CiAgICAgIGZ1biBnZXRCeXRlcyBmIG4gZXJyTXNnIGluU3RyID0KICAgICAgICAgICAgbGV0
CiAgICAgICAgICAgICAgdmFsICh2LCBpblN0cjIpID0gRklPLmlucHV0TiAoaW5TdHIsIG4p
CiAgICAgICAgICAgIGluCiAgICAgICAgICAgICAgaWYgV29yZDhWZWN0b3IubGVuZ3RoIHYg
Pj0gbiB0aGVuCiAgICAgICAgICAgICAgICAoZiB2LCBpblN0cjIpCiAgICAgICAgICAgICAg
ZWxzZQogICAgICAgICAgICAgICAgcmFpc2UgU3ludGF4RXJyb3IgKGVyck1zZywgaW5TdHIp
CiAgICAgICAgICAgIGVuZAoKICAgICAgKCogUmVhZHMgYSByYXcgd29yZDggKikKICAgICAg
ZnVuIGdldFdvcmQ4IGluU3RyID0KICAgICAgICAgICAgZ2V0Qnl0ZXMgd29yZDh4MVRvV29y
ZDgKICAgICAgICAgICAgICAgICAgICAgMSAiQ291bGQgbm90IHJlYWQgMSBieXRlIGFzIHJh
dyB3b3JkOCEiIGluU3RyCgpmdW4gd29yZDhUb0NoYXJOb3ROdWxsIHcgPQogICAgICAgICAg
ICAocHJpbnQgKChzdHIgKHdvcmQ4VG9DaGFyIHcpKSBeICIsICIpOwogICAgICAgICAgICBp
ZiBXb3JkOC50b0ludCB3ID0gMCB0aGVuCiAgICAgICAgICAgICAgcmFpc2UgVmFsaWRpdHlF
cnJvciAiTnVsbCBjaGFyYWN0ZXIgbWV0ISIKICAgICAgICAgICAgZWxzZQogICAgICAgICAg
ICAgIHdvcmQ4VG9DaGFyIHcKICAgICAgICAgICAgKQoKICAgICAgdmFsIGdldENoYXJOb051
bGwgPSBnZXRXb3JkOCA+PiB3b3JkOFRvQ2hhck5vdE51bGwKCiAgICAgIGZ1biBnZXRTdHJp
bmcgaW5TdHIgPQogICAgICAgICAgICBsZXQKICAgICAgICAgICAgICB2YWwgXyA9IHByaW50
ICJwYXJzaW5nIHVzaW5nIHJlcGVhdC4uLlxuIgogICAgICAgICAgICAgIHZhbCAoY2hhcnMs
IGluU3RyMikgPSByZXBlYXQgZ2V0Q2hhck5vTnVsbCBpblN0cgogICAgICAgICAgICAgIHZh
bCBfID0gcHJpbnQgIlxuIgogICAgICAgICAgICAgIHZhbCBfID0gcHJpbnQgInByaW50aW5n
IHBhcnNlZCBjaGFyYWN0ZXJzLi4uXG4iCiAgICAgICAgICAgICAgdmFsIF8gPSBMaXN0LmFw
cCAoZm4gYyA9PiBwcmludCAoKHN0ciBjKSBeICIsICIpKSBjaGFycwogICAgICAgICAgICAg
IHZhbCBfID0gcHJpbnQgIlxuIgogICAgICAgICAgICAgIHZhbCBzdHIgPSBpbXBsb2RlIGNo
YXJzCiAgICAgICAgICAgIGluCiAgICAgICAgICAgICAgc3RyCiAgICAgICAgICAgIGVuZAoK
ZnVuIGltcG9ydCBmaWxlTmFtZSA9CiAgICAgICAgICBsZXQKICAgICAgICAgICAgdmFsIGlu
U3RyID0gRklPLm9wZW5JbiBmaWxlTmFtZQogICAgICAgICAgICB2YWwgcmVzdWx0ID0gZ2V0
U3RyaW5nIGluU3RyCiAgICAgICAgICAgIHZhbCBfID0gRklPLmNsb3NlSW4gaW5TdHIKICAg
ICAgICAgIGluCiAgICAgICAgICAgIHJlc3VsdAogICAgICAgICAgZW5kCmVuZCAoKiBlbmQg
bG9jYWwgKikKCnZhbCBfID0gcHJpbnQgKCJUaGUgc3RyaW5nIHJlYWQgd2FzOiAiIF4gKGlt
cG9ydCAiUmVwZWF0UGFyc2VyQ29tYmluYXRvci50eHQiKSBeICJcbiIpCg==
--------------95E773A5FEC843ADB26DFD69--