caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Frédéric Bour" <frederic.bour@lakaban.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] New release of Menhir (20141215)
Date: Fri, 26 Dec 2014 12:31:49 +0100	[thread overview]
Message-ID: <549D4725.9030202@lakaban.net> (raw)
In-Reply-To: <1100699448.864923.1419592410621.JavaMail.yahoo@jws100188.mail.ne1.yahoo.com>

Hi,

I tried various methods with Merlin, with good results.
That's quite close to what you suggest: we add an empty non-terminal and 
change the behavior when it is on stack.
Something like:

lexer_switch:
| (* empty *) { () }

inline:
| …
| LINK lexer_switch OPEN RAW END OPEN inline* END
| …

Lexing loop:

if has_lexer_switch parser then
   feed parser (Lexer.raw_token buf)
else
   feed parser (Lexer.token buf)

Of course this require introspection (Merlin's internal version exposes 
a lot more informations, but that's for debugging and experimentation 
purposes, we hope to clean that).
You can still use side-effects to emulate the trick:

lexer_switch:
| (* empty *) { in_raw_lexer := true }

lexer_leave:
| (* empty *) { in_raw_lexer := false }

… but be careful :).

Cheers,
Fred

On 26/12/2014 12:13, Dario Teixeira wrote:
> Hi,
>
>> Hmm, maybe. The new API will probably allow you to inspect the stack (which is
>> basically a list of pairs of a state and a semantic value) and to inspect a
>> state (which can be viewed as a set of LR(1) items). I don't know whether that
>> would offer you a simple way of deciding when to switch from one lexer to
>> another...
> I suspect it will *at least* be an improvement over the current situation.
> Consider the following rule:
>
> inline:
> | ...
> | LINK OPEN RAW END OPEN inline* END
> | ...
>
> Suppose that by default I'm using a 'general' lexer.  However, upon encountering
> that first OPEN token, I must switch to a 'raw' lexer and then switch back to the
> 'general' lexer upon encountering the first END token.  This lexer dance won't
> happen with the second OPEN token, though.
>
> Anyway, as long as I know which state Menhir is in, choosing the right lexer
> should be an easy task.  It may require a large lookup table on my part to map
> state to lexer, but at least that's a lot less hairy than the current approach.
>
> Best regards,
> Dario Teixeira
>

  reply	other threads:[~2014-12-26 11:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-17 20:14 Francois Pottier
2014-12-18 12:45 ` Gerd Stolpmann
2014-12-18 14:19   ` Nicolas Ojeda Bar
2014-12-18 15:20     ` Daniel Bünzli
2014-12-18 15:34       ` Simon Cruanes
2014-12-18 16:02         ` Nicolas Ojeda Bar
2014-12-18 15:25     ` Gerd Stolpmann
2014-12-18 17:25       ` Francois Pottier
2014-12-22 11:13     ` oleg
2014-12-22 18:40 ` Dario Teixeira
2014-12-24 23:30   ` Francois Pottier
2014-12-26 11:13     ` Dario Teixeira
2014-12-26 11:31       ` Frédéric Bour [this message]
2014-12-26 12:16         ` 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=549D4725.9030202@lakaban.net \
    --to=frederic.bour@lakaban.net \
    --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;
as well as URLs for NNTP newsgroup(s).