caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Janne Hellsten" <jjhellst@gmail.com>
To: "David Allsopp" <dra-news@metastack.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Matching start of input in lexer created with ocamllex
Date: Fri, 6 Apr 2007 23:14:18 +0300	[thread overview]
Message-ID: <700d600f0704061314q2fd177bdnc918e6a1d811423b@mail.gmail.com> (raw)
In-Reply-To: <011c01c7781e$e74a80c0$6a7ba8c0@treble>

On 4/6/07, David Allsopp <dra-news@metastack.com> wrote:
> > I'd like to match the beginning of input (or beginning of line) in my
> > lexer.  Is there an easy way to do that?
> Ocamllex doesn't have a notion for beginning of line. Three possible
> solutions:
>
> 1. You can simulate it with a bool ref parameter to your lexer that gets set
> to true by each rule to indicate that you're no longer at the beginning of a
> line - the "!for" rule than raises Failure if it matches when this ref is
> true. Slightly tedious for code maintenance...
> 2. You use two lexers - one with the "!for" rule and one without and call
> one lexer from the other (not very nice, because ocamllex doesn't support
> code reuse between lexers so you'll be duplicating a lot of code).
> 3. Pre-process the input to ocamllex to include a special character that
> cannot appear in your text and place that at the beginning of the line (e.g.
> one of the control characters in 0..31).

Thanks, my program was already running its input through a
preprocessor and I thus chose to use solution #3.  I had already
considered solution #2 but came to the same conclusion: it leads to
code duplication.

Janne


  reply	other threads:[~2007-04-06 20:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070405205804.90509BC76@yquem.inria.fr>
2007-04-06  7:40 ` David Allsopp
2007-04-06 20:14   ` Janne Hellsten [this message]
2007-04-05 14:37 Janne Hellsten
2007-04-05 19:55 ` [Caml-list] " skaller
2007-04-05 20:58   ` Janne Hellsten
2007-04-06  5:52     ` skaller

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=700d600f0704061314q2fd177bdnc918e6a1d811423b@mail.gmail.com \
    --to=jjhellst@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=dra-news@metastack.com \
    /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).