* Re: ocaml comfort, where is stringOfCharList?
[not found] ` <199703260819.JAA14740@pauillac.inria.fr>
@ 1997-03-26 11:52 ` Fritz Heinrichmeyer
0 siblings, 0 replies; only message in thread
From: Fritz Heinrichmeyer @ 1997-03-26 11:52 UTC (permalink / raw)
To: caml-list
This is a repost without MIME structure:
The last days i tried to build a HTML-Posting parser in caml. It was
hard for a beginner used to do such things in scheme. The script below
includes also a small (now untested) tester. I wrote a simple
stringOfList function myself. In scheme i would have written only
(apply string thelist).
Did i miss something? Some examples for the use of the Stream-library
would be helpful, especially for "peek" and "junk".
The parser looks pretty short now, but it was hard work for me. I would
appreciate comments on the style. Could it be shorter?
Is it possible to create an mli file for a module build by a
functor as elegant as the implementation itself?
Now here is postParser.ml:
--------------- snip -------------------
type token =
Equal | Ampersand | Symbol of string | Value of string
;;
open StringOfList
open StringMap
let charToToken=
let sol = stringOfList
in
let rec wordr st =
parser
[<''&';rest=(wordr [])>] -> [<'(Value (sol st));'Ampersand ;rest>]
| [<''=';rest=(wordr [])>] -> [<'(Symbol (sol st));'Equal;rest>]
| [<'' '|'\n'|'\t';rest=(wordr st)>] -> rest
| [<'c;rest=(wordr (c::st))>] -> rest
| [< >] -> [<'Value(sol st)>]
in wordr []
;;
let postparser x =
let rec ppr st =
parser
[<'Symbol x;'Equal;'Value y;
rest = (ppr (StringMap.add key: x data: y st ))>] -> rest
| [<'Ampersand;'Symbol x;'Equal;'Value y;
rest = (ppr (StringMap.add key: x data: y st ))>] -> rest
| [< >] -> st
in ppr StringMap.empty (charToToken x)
;;
(* a small untested (3-26-97) tester
StringMap.iter
fun:
(fun key: a data: b ->(Printf.printf "sym=%s,val=%s\n" a b))
(postparser (Stream.of_string " ab=1&cd=2&ef=3&gh=4 "))
;;
*)
------------- snip ---------------------------
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1997-03-26 13:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <199703251426.PAA02105@jfh00.fernuni-hagen.de>
[not found] ` <199703260819.JAA14740@pauillac.inria.fr>
1997-03-26 11:52 ` ocaml comfort, where is stringOfCharList? Fritz Heinrichmeyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox