From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "till.varoquaux" <till.varoquaux@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Dynamically switching lexer
Date: Thu, 10 Jan 2008 10:29:40 +0100 [thread overview]
Message-ID: <1199956968-sup-4697@ausone.local> (raw)
In-Reply-To: <9d3ec8300801091418j37e72687v892bcc2b33dc83b4@mail.gmail.com>
Excerpts from till.varoquaux's message of Wed Jan 09 23:18:57 +0100 2008:
> I'm currently doing a toy DSEL,
> Camlp4 pops to mind as a very nice way to embed it unfortunately the
> standard lexer it comes with is not all that great for my language.
> Although I do know how to use another lexer it comes with a catch:
> antiquotation need to be properly lexed to string to be passed to the
> standard ocaml parser as strings (I use
> let expr_of_string = Gram.parse_string Syntax.expr_eoi
> this seems simpler than what is shown in tutorials. Am I missing
> something?) off course the easy way to delimit such strings
> (respecting nested comments, escaped strings...) would be to use the
> former lexer, It would need to be switched between both lexers, is
> this all possibe?.
> Cheers,
> Till
>
You cannot easily change the camlp4 lexer dynamically, but when you get a quotation you get a string that you can lex with a different lexer.
Their is only two restrictions:
- ">>" is forbidden since it will end the quotation
- if you start a new quotation inside, you must close it: '<' (':' ident)? ('@' locname)? '<' ... ">>"
Here is the intersting part of the lexer
---------------------------
and quotation c = parse
| '<' (':' ident)? ('@' locname)? '<' { store c ;
with_curr_loc quotation c ;
parse quotation c }
| ">>" { store c }
| eof { err Unterminated_quotation (loc c) }
| newline { update_loc c None 1 false 0 ;
store_parse quotation c }
| _ { store_parse quotation c }
---------------------------
--
Nicolas Pouillard aka Ertai
prev parent reply other threads:[~2008-01-10 9:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-09 22:18 Till Varoquaux
2008-01-10 9:29 ` Nicolas Pouillard [this message]
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=1199956968-sup-4697@ausone.local \
--to=nicolas.pouillard@gmail.com \
--cc=caml-list@inria.fr \
--cc=till.varoquaux@gmail.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