package ppx_here

  1. Overview
  2. Docs
Expands [%here] into its location

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_here-v0.14.0.tar.gz
sha256=72fe20f7cfae3744a1a726bd973f0e25d07905a065f3eb41946623e36523842c
md5=bb3bbde0964a1f866de09f3df44def4d

Description

Part of the Jane Street's PPX rewriters collection.

Published: 31 May 2020

README

ppx_here

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

Syntax

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

becomes:

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

Usage

This is normally used so exceptions can contain better positions. An example is Core_kernel.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).

Dependencies (4)

  1. ppxlib >= "0.11.0"
  2. dune >= "2.0.0"
  3. base >= "v0.14" & < "v0.15"
  4. ocaml >= "4.04.2"

Dev Dependencies

None

Used by (23)

  1. cohttp-eio >= "6.0.0~beta2"
  2. colibri2
  3. conduit-async = "2.3.0" | >= "4.0.0"
  4. dap
  5. gopcaml-mode-merlin < "0.0.6"
  6. h1_parser
  7. http
  8. nuscr >= "2.1.0"
  9. obeam >= "0.1.0"
  10. oci
  11. pa_ppx < "0.07" | >= "0.10"
  12. ppx_assert = "v0.14.0"
  13. ppx_bap
  14. ppx_bin_prot = "v0.14.0"
  15. ppx_expect >= "v0.14.0" & < "v0.15.0"
  16. ppx_fail >= "v0.14.0"
  17. ppx_jane = "v0.14.0"
  18. ppx_sexp_message >= "v0.14.0" & < "v0.15.0"
  19. ppx_sexp_value = "v0.14.0"
  20. timmy
  21. timmy-jsoo >= "1.1.5"
  22. timmy-lwt
  23. toplevel_backend = "v0.14.0"

Conflicts

None

OCaml

Innovation. Community. Security.