caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dario Teixeira <darioteixeira@yahoo.com>
To: caml-list@yquem.inria.fr
Subject: Parameterised lexer
Date: Sun, 14 Sep 2008 12:53:01 -0700 (PDT)	[thread overview]
Message-ID: <698632.75695.qm@web54606.mail.re2.yahoo.com> (raw)

Hi,

Is it possible to write a ocamllex/ulex scanner where a regexp is a parameter
to the lexer function?  I'm looking for something like the (invalid) ulex
code below demonstrates ("param" is the parameter):

let regexp alpha = ['a'-'z' 'A'-'Z']
let regexp whitespace = [' ' '\t' '\n']
let regexp param1 = 'x'
let regexp param2 = 'y'
let regexp param3 = 'z'

let rec token param = lexer
        | param         ->      Printf.print "*";
                                token param lexbuf
        | alpha+        ->      Printf.printf "%s" (Ulexing.utf8_lexeme lexbuf);
                                token param lexbuf
        | whitespace+   ->      Printf.printf " ";
                                token param lexbuf
        | eof           ->      Printf.printf "EOF\n"

let main () =
        let lexbuf = Ulexing.from_utf8_channel stdin
        in token param1 lexbuf

let _ = Printexc.print main ()


Thanks in advance for your help!
Kind regards,
Dario Teixeira






             reply	other threads:[~2008-09-14 19:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-14 19:53 Dario Teixeira [this message]
2008-09-16  9:38 ` [Caml-list] " David Allsopp

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=698632.75695.qm@web54606.mail.re2.yahoo.com \
    --to=darioteixeira@yahoo.com \
    --cc=caml-list@yquem.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;
as well as URLs for NNTP newsgroup(s).