Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Fritz Heinrichmeyer <fritz.heinrichmeyer@fernuni-hagen.de>
To: caml-list@inria.fr
Subject: Re: ocaml comfort, where is stringOfCharList?
Date: Wed, 26 Mar 1997 12:52:22 +0100	[thread overview]
Message-ID: <199703261152.MAA07229@jfh00.fernuni-hagen.de> (raw)
In-Reply-To: <199703260819.JAA14740@pauillac.inria.fr>

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 ---------------------------








        





           reply	other threads:[~1997-03-26 13:08 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <199703260819.JAA14740@pauillac.inria.fr>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199703261152.MAA07229@jfh00.fernuni-hagen.de \
    --to=fritz.heinrichmeyer@fernuni-hagen.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox