From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id ABE377ED45 for ; Fri, 22 Jun 2012 18:37:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApUBAIye5E/RVaG2kGdsb2JhbABFDrVOCCIBAQEBCQkNBxQEI4IYAQEBBBICExkBGx0BAwwGBQsNLiIBEQEFARwGEwgah1oBAwsLm1QJA4wjgnGFDAoZJw1XiHEBBQyLIoYCA5UsgRKNEj6DRTs X-IronPort-AV: E=Sophos;i="4.77,459,1336341600"; d="scan'208";a="164075779" Received: from mail-gg0-f182.google.com ([209.85.161.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 22 Jun 2012 18:37:42 +0200 Received: by ggnm2 with SMTP id m2so2572727ggn.27 for ; Fri, 22 Jun 2012 09:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=pe53EacxE7SsJbZFHLpCgUA/xYsXn69YlUoab0lVI3k=; b=vr47aiNTbczrre0Grbh7Hkdoi8lnx4TLGsJngW8vLMX82X8ESpymx3lWYrMhNT67Nn +Pt4fjrgDSJIk/Zl+YDP10dpmQ3opRk+u70I1ndKi+ZmTy+P9UCRGnDLwGsMnTx2nQLs vIgHFHWGTk+guGVlia8SxuzkW6fAdTJlxVzcXdpCGpszVCFfjxUcuHgE+Lz5uZ9Ieh/O j0dKSNabWZ4yfw2pCUKdxGGhC5ElQfQ3OKItzTbwqHnDC1ESAMPL6WKkbHTMRrTeJaC+ FNoewv/zV6L3cPVIa83NonEitEYRprC+fukX936Vp9ykXfKevQcl/OWftOqHJ3Uuz1Og Px/g== Received: by 10.50.217.137 with SMTP id oy9mr2277574igc.56.1340383059956; Fri, 22 Jun 2012 09:37:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.94.39 with HTTP; Fri, 22 Jun 2012 09:36:59 -0700 (PDT) In-Reply-To: References: From: Gabriel Scherer Date: Fri, 22 Jun 2012 18:36:59 +0200 Message-ID: To: Aaron Bohannon Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Compiling with camlp4 extensions All nodes in a Camlp4 AST are annotated with location information; the locations you get from the parser are correct, and it is your responsibility, as an extension writer, to ensure that any new nodes you generate also have (approximately) correct location information. If you build AST nodes "by hand", you have to provide this location explicitly. If you use the concrete syntax quotations, the location used is the value _loc present in the environment, whatever it may be. So to have correct locations, you have to make sure that, at every AST you produce through a quotation, there is a "_loc" variable in scope with the correct value. If you match AST pieces with quotation patterns (match e with <:expr< $a$ + $b$ >> -> ...), you may bind the location variable through the syntax "<:expr@foo<", for example: (match e with <:expr@_loc< $a$ + $b$ >> -> ...). Finally, if you're inside an EXTEND block defining a parsing rule, the idenfitier _loc is implicitely bound to a location corresponding to what was parsed by this rule. See for example the toy extension pa_refutable, that has example of those various things: http://bluestorm.info/camlp4/pa_refutable.ml.html In some very rare cases (or if you are perfectionist), you may want to give to a new node a location that is not quite the location of any of the parsed node you're working on. You may use various functions of the Loc submodule of your syntax definition to forge new locations; in particular, Loc.merge merges two (supposed contiguous) locations. http://bluestorm.info/camlp4/camlp4-doc/Sig.Loc.html On Fri, Jun 22, 2012 at 5:53 PM, Aaron Bohannon w= rote: > Hi, > > I have been trying to use the new camlp4 to write an OCaml syntax > extension.=A0 All the examples I have seen so far suggest that I use the > extension by passing ocamlc the "-pp" option.=A0 But it seems that all the > location info for error messages gets lost when I do this unless I catch = and > report the parse error myself within the extension.=A0 Is there some way = to > get ocamlc to report the parse error at the correct location automaticall= y? > > - Aaron