Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: knotwell@f5.com
To: caml-list@inria.fr
Subject: a parsing question
Date: Thu, 4 May 2000 07:49:07 -0700	[thread overview]
Message-ID: <200005041449.HAA22067@klar.f5.com> (raw)

Hello all--

I've been writing a configuration file parser using ocaml's lex and
yacc.  So far, I've run into two things (actually they both grow out
of the same problem) that seem like there should be a better way
(NOTE: since I'm new the example will seem pretty contrived):

Let's say I have the following data:
      <yoyo-time>
          40
      </yoyo-time>

and I want to parse out the 40 and stuff it into a data structure
usable *outside* of parser (assume lexer.mll, parser.mly, and
config_test.ml).  What I've currently done is the following:

(* parser.mly *)
(* NOTE:  I tried creating a yoyo_time object, but ocamlyacc
          apparently doesn't like the yoyo_time#set_time syntax *)
%{
let yoyo_time = ref 10;;
let set_yoyo_time newtime = yoyo_time := (int_of_string newtime);;
%}

%token YOYO_TIME_BEGIN YOYO_TIME_END INT
%start <string> main
%type <string> INT
%%

main: YOYO_TIME_BEGIN INT YOYO_TIME_END { set_yoyo_time $2; $2 }
%%

=============================

Unfortunately, I don't know how to "export" yoyo_time to parser.mli.
My Makefile currently does the following:  

    echo "val yoyo_time: int ref" >> parser.mli

While this works fine, I'd like to avoid using Make as a post-processor.

I wondered about defining numerous entry points, but I presumed this
would force me to be extremely careful about the ordering in my config
file.

Put another way, am I incorrect in assuming the lexer discards
previously unmatched data?

Since this is so long, I'll skip the second question--macros.

Thanks.
 
--Brad




             reply	other threads:[~2000-05-04 16:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-04 14:49 knotwell [this message]
2000-05-04 16:57 ` Jean-Yves Moyen
2000-05-04 17:29 ` John Prevost

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=200005041449.HAA22067@klar.f5.com \
    --to=knotwell@f5.com \
    --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