Expands [%here] into its location
Clone or download
Latest commit 9765496 Nov 8, 2018
Failed to load latest commit information.
expander v0.11.117.00+101 Mar 29, 2018
src v0.11.117.00+101 Mar 29, 2018
test v0.11.117.00+101 Mar 29, 2018
.gitignore 114.35+03 Mar 7, 2017
CHANGES.md v0.11.116.17+187 Mar 16, 2018
CONTRIBUTING.md v0.11.120.08+153 Nov 6, 2018
LICENSE.md v0.11.117.08+54 May 23, 2018
Makefile v0.11.117.08+54 May 23, 2018
README.md v0.9.114.44+47 May 11, 2017
jbuild 114.35+03 Mar 7, 2017
ppx_here.opam v0.11.120.09+50 Nov 8, 2018



A ppx rewriter that defines an extension node whose value is its source position.


ppx_here rewrites the extension [%here] in expressions, by replacing it by a value of type Source_code_position.t (i.e. Lexing.position) corresponding to the current position. It respects line number directives.

For instance:

let _ =
  print_endline [%here].Lexing.pos_fname


let _ =
      Lexing.pos_fname = ppx/ppx_here/test/test.ml";
      pos_lnum = 2;
      pos_cnum = 26;
      pos_bol = 8;


This is normally used so exceptions can contain better positions. An example is Core_kernel.Std.Option.value_exn, which takes an optional position so that if you have a stack trace, you can get still the origin of the exception.

It can also be used in cases where stack traces are useless (for instance in monads with a complicated control flow).

Command line flag

If the flag -dirname <dir> is given, relative filenames are made relative to <dir>. <dir> can be a relative path.

<dir> can be chosen as the path from the root of the repository to the directory of the source, to make filenames unique within the repository (which avoids ambiguities as there can be many files called server.ml, common.ml or config.ml).