caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] char/line-numbers in error-messages from data-structures bulit via ocamllex?
@ 2017-04-24 20:18 Chet Murthy
  2017-04-24 20:30 ` François Pottier
  0 siblings, 1 reply; 2+ messages in thread
From: Chet Murthy @ 2017-04-24 20:18 UTC (permalink / raw)
  To: caml-list; +Cc: chetsky

Ages (decades) ago, I recall (perhaps incorrectly) that there was a
somewhat well-known way of using ocamllex and {ocamlyacc, PP streams}
together, in order to decorate a parse-tree with line-number
information -- so that later (e.g. type-checking) passes could emit
that line-number information as part of error-messages.

As I rack my brain trying to imagine what that method might be,
several approaches come to mind:

(1) with PP streams, I could define the token-type to be a tuple of
the real token-type and a lexing position, e.g.

type token = real_token * Lexing.position

(2) with camlyacc, I'd have to stuff the position into every branch of
the algebraic datatype, e.g.

type token =
| LIT of Lexing.position * literal
| ID of Lexing.position * identifier
| OP of Lexing.position * operator
...

Both of these seem workable, but I don't remember either of them as
being "the" way to do it, back in the day.

Does anybody have any memory of this "Echte" way of doing it?

Thanks,
--chet--


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-24 20:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-24 20:18 [Caml-list] char/line-numbers in error-messages from data-structures bulit via ocamllex? Chet Murthy
2017-04-24 20:30 ` François Pottier

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).