caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "François Pottier" <francois.pottier@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] char/line-numbers in error-messages from data-structures bulit via ocamllex?
Date: Mon, 24 Apr 2017 22:30:35 +0200	[thread overview]
Message-ID: <58FE606B.5000400@inria.fr> (raw)
In-Reply-To: <2183504.2kfSNf9Hln@twitter>


Dear Chet,

With ocamlyacc and menhir, just keep your type "token" unmodified -- no need
to annotate tokens with positions.

Then, if you are using ocamlyacc, the functions in the module Parsing can be
used to extract position information; if you are using menhir, the position
keywords $startpos, $endpos, etc. can be used for this purpose. (See 
Menhir's
documentation for details.) You can then arrange for your semantic 
actions to
decorate your AST with position information.

In Menhir, you can define a parameterized nonterminal symbol to alleviate
the pain of recording positions. For instance:

located(X):
   x = X
     { (x, $startpos, $endpos) }

Thus, if the nonterminal symbol X has a semantic value of type 'a, then
the nonterminal symbol located(X) recognizes the same strings as X, but
has a semantic value of type 'a * Lexing.position * Lexing.position.
If your nonterminal symbols are expression, instruction, etc.,
then you can use located(expr), located(instruction), etc.,
to automatically obtain decorated ASTs.

I hope this helps,

--
François Pottier
francois.pottier@inria.fr
http://gallium.inria.fr/~fpottier/

      reply	other threads:[~2017-04-24 20:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 20:18 Chet Murthy
2017-04-24 20:30 ` François Pottier [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=58FE606B.5000400@inria.fr \
    --to=francois.pottier@inria.fr \
    --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).