| 1 | ppx_here |
| 2 | ======== |
| 3 | |
| 4 | A ppx rewriter that defines an extension node whose value is its source position. |
| 5 | |
| 6 | Syntax |
| 7 | ------ |
| 8 | |
| 9 | `ppx_here` rewrites the extension `[%here]` in expressions, by |
| 10 | replacing it by a value of type `Source_code_position.t` |
| 11 | (i.e. `Lexing.position`) corresponding to the current position. It |
| 12 | respects line number directives. |
| 13 | |
| 14 | For instance: |
| 15 | |
| 16 | ```ocaml |
| 17 | let _ = |
| 18 | print_endline [%here].Lexing.pos_fname |
| 19 | ``` |
| 20 | |
| 21 | becomes: |
| 22 | |
| 23 | ```ocaml |
| 24 | let _ = |
| 25 | print_endline |
| 26 | { |
| 27 | Lexing.pos_fname = ppx/ppx_here/test/test.ml"; |
| 28 | pos_lnum = 2; |
| 29 | pos_cnum = 26; |
| 30 | pos_bol = 8; |
| 31 | }.Lexing.pos_fname |
| 32 | ``` |
| 33 | |
| 34 | Usage |
| 35 | ----- |
| 36 | |
| 37 | This is normally used so exceptions can contain better positions. An example is |
| 38 | `Core.Option.value_exn`, which takes an optional position so that if you have a |
| 39 | stack trace, you can get still the origin of the exception. |
| 40 | |
| 41 | It can also be used in cases where stack traces are useless (for instance in monads with a |
| 42 | complicated control flow). |
| 43 | |
| 44 | Command line flag |
| 45 | ----------------- |
| 46 | |
| 47 | If the flag `-dirname <dir>` is given, relative filenames are made |
| 48 | relative to `<dir>`. `<dir>` can be a relative path. |
| 49 | |
| 50 | `<dir>` can be chosen as the path from the root of the repository to |
| 51 | the directory of the source, to make filenames unique within the |
| 52 | repository (which avoids ambiguities as there can be many files called |
| 53 | `server.ml`, `common.ml` or `config.ml`). |
| 54 |