A Simple Monadic Parser
Overview
Superceeded by the InStream Monad in BasicMonads.xml.
Introduction
Simple Parser
This is a non-deterministic parser monad.
functor SimpleParseMonad
It is intended that parsers built using this monad can be used on any XlStream.
xl-sml
functor SimpleParseMonad (XlStream:XlStream):StateXMonad =
struct
open XlStream

type 'a M = inStream -> 'a * inStream

fun unit x f = (x,f)

fun bind am fabm file =
let val (a,f) = am file
in fabm a f
end

type 'a M = inStream -> 'a * inStream;

exception Mexception of string * inStream

fun mraise x s = raise (Mexception (x,s))

fun mhandle am h s = am s handle Mexception x => h x
end;

Parse Arrows
Starting with the Kleisli arrow built from the simple parse monad and an XlStream.
Signature BasicParseArrow

xl-sml
signature BasicParseArrow =
sig
include FullStateXArrow
include XlStream
end;

Functor BasicParseArrow

xl-sml
functor BasicParseArrow (XlStream:XlStream):BasicParseArrow=
struct
structure Parser = FullStateXArrow(StateXArrow(SimpleParseMonad(XlStream)))
open XlStream Parser
end;

Structure BasicParseVectorArrow

xl-sml
structure BasicParseVectorArrow = BasicParseArrow(XlVectorStream);


up quick index © RBJ

$Id: ParseMonad.xml,v 1.1.1.1 2000/12/04 17:24:59 rbjones Exp $