From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: Francois.Pottier@inria.fr, Jeff Shaw <shawjef3@msu.edu>,
caml-list@inria.fr
Subject: Re: [Caml-list] Re: The lexer hack
Date: Wed, 11 Nov 2009 12:03:54 +0100 [thread overview]
Message-ID: <4AFA9A1A.1040808@ens-lyon.org> (raw)
In-Reply-To: <415678.66831.qm@web111512.mail.gq1.yahoo.com>
Dario Teixeira wrote:
> Hi,
>
>> Interesting. Have you confirmed that this works? I am slightly
>> worried by the fact that an LR parser reads one token ahead,
>> i.e. one token past BEGIN_VERB might already have been read
>> before the enter_verb semantic action is executed. If that is
>> so, then this token would be read while the lexer is still in
>> the wrong mode.
>
> Yes, I was just thinking about that as well... :-)
> I think I can pile another hack on top of the dummy action:
> dummy tokens to take care of the readahead issue. Though
> this has the potential to get comically silly pretty quickly!
>
> I'll report later...
If the lexer to use can be determined by only one token (BEGIN_VERB), I think
you can change the state in the lexer like this:
rule token state = parse
"" { match !state with
`Normal -> normal_token state lexbuf
| `Verbatim -> verbatim_token state lexbuf
}
and normal_token state = parse
...
| "\\begin{verbatim}" { state := `Verbatim; BEGIN_VERB }
and verbatim_token state = parse
... { RAW (...) }
| "\\end{verbatim}" { state := `Normal; END_VERB }
An even simpler option, if possible in your case, is to use a single token for
the whole verbatim section:
rule token = parse
...
| "\\begin{verbatim}" { finish_verbatim lexbuf }
and finish_verbatim = shortest
_* as s "\\end{verbatim}" { RAW s }
Martin
--
http://mjambon.com/
next prev parent reply other threads:[~2009-11-11 11:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 15:26 Jeff Shaw
2009-11-10 16:26 ` [Caml-list] " Dario Teixeira
2009-11-10 16:33 ` Francois Pottier
2009-11-10 16:48 ` Dario Teixeira
2009-11-11 11:03 ` Martin Jambon [this message]
2009-11-14 18:19 ` Dario Teixeira
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=4AFA9A1A.1040808@ens-lyon.org \
--to=martin.jambon@ens-lyon.org \
--cc=Francois.Pottier@inria.fr \
--cc=caml-list@inria.fr \
--cc=darioteixeira@yahoo.com \
--cc=shawjef3@msu.edu \
/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