pax_global_header00006660000000000000000000000064144217506710014521gustar00rootroot0000000000000052 comment=e889a144b035ac773b6cfe5910d8c1c17686ff7f ppx_here-0.16.0/000077500000000000000000000000001442175067100134175ustar00rootroot00000000000000ppx_here-0.16.0/.gitignore000066400000000000000000000000411442175067100154020ustar00rootroot00000000000000_build *.install *.merlin _opam ppx_here-0.16.0/CHANGES.md000066400000000000000000000003101442175067100150030ustar00rootroot00000000000000## v0.11 - Depend on ppxlib instead of (now deprecated) ppx\_core and ppx\_driver. ## 113.24.00 - Make ppx\_here translate `[%here]` instead of `_here_`. - Update to follow `Ppx_core` evolution. ppx_here-0.16.0/CONTRIBUTING.md000066400000000000000000000044101442175067100156470ustar00rootroot00000000000000This repository contains open source software that is developed and maintained by [Jane Street][js]. Contributions to this project are welcome and should be submitted via GitHub pull requests. Signing contributions --------------------- We require that you sign your contributions. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org][dco]): ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` Then you just add a line to every git commit message: ``` Signed-off-by: Joe Smith ``` Use your real name (sorry, no pseudonyms or anonymous contributions.) If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with git commit -s. [dco]: http://developercertificate.org/ [js]: https://opensource.janestreet.com/ ppx_here-0.16.0/LICENSE.md000066400000000000000000000021461442175067100150260ustar00rootroot00000000000000The MIT License Copyright (c) 2015--2023 Jane Street Group, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ppx_here-0.16.0/Makefile000066400000000000000000000004031442175067100150540ustar00rootroot00000000000000INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),) default: dune build install: dune install $(INSTALL_ARGS) uninstall: dune uninstall $(INSTALL_ARGS) reinstall: uninstall install clean: dune clean .PHONY: default install uninstall reinstall clean ppx_here-0.16.0/README.md000066400000000000000000000025251442175067100147020ustar00rootroot00000000000000ppx_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: ```ocaml let _ = print_endline [%here].Lexing.pos_fname ``` becomes: ```ocaml 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.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 ` is given, relative filenames are made relative to ``. `` can be a relative path. `` 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`). ppx_here-0.16.0/dune000066400000000000000000000000001442175067100142630ustar00rootroot00000000000000ppx_here-0.16.0/dune-project000066400000000000000000000000201442175067100157310ustar00rootroot00000000000000(lang dune 1.10)ppx_here-0.16.0/expander/000077500000000000000000000000001442175067100152255ustar00rootroot00000000000000ppx_here-0.16.0/expander/dune000066400000000000000000000002471442175067100161060ustar00rootroot00000000000000(library (name ppx_here_expander) (public_name ppx_here.expander) (libraries base ppxlib) (preprocess no_preprocessing) (ppx_runtime_libraries ppx_here.runtime-lib))ppx_here-0.16.0/expander/ppx_here_expander.ml000066400000000000000000000026101442175067100212560ustar00rootroot00000000000000open Ppxlib module Filename = Stdlib.Filename let dirname = ref None let set_dirname dn = dirname := dn let () = Driver.add_arg "-dirname" (String (fun s -> dirname := Some s)) ~doc:" Name of the current directory relative to the root of the project" let chop_dot_slash_prefix ~fname = match Base.String.chop_prefix ~prefix:"./" fname with | Some fname -> fname | None -> fname let expand_filename fname = match Filename.is_relative fname, !dirname with | true, Some dirname -> (* If [dirname] is given and [fname] is relative, then prepend [dirname]. *) Filename.concat dirname (chop_dot_slash_prefix ~fname) | _ -> fname let lift_position ~loc = let loc = { loc with loc_ghost = true } in let (module Builder) = Ast_builder.make loc in let open Builder in let pos = loc.Location.loc_start in let id = Located.lident in pexp_record [ id "Ppx_here_lib.pos_fname" , estring (expand_filename pos.Lexing.pos_fname) ; id "pos_lnum" , eint pos.Lexing.pos_lnum ; id "pos_cnum" , eint pos.Lexing.pos_cnum ; id "pos_bol" , eint pos.Lexing.pos_bol ] None let lift_position_as_string ~(loc : Location.t) = let { Lexing. pos_fname; pos_lnum; pos_cnum; pos_bol } = loc.loc_start in Ast_builder.Default.estring ~loc (Printf.sprintf "%s:%d:%d" (expand_filename pos_fname) pos_lnum (pos_cnum - pos_bol)) ;; ppx_here-0.16.0/expander/ppx_here_expander.mli000066400000000000000000000007701442175067100214340ustar00rootroot00000000000000open Ppxlib (** Lift a lexing position to a expression *) val lift_position : loc:Location.t -> Parsetree.expression (** Lift a lexing position to a string expression *) val lift_position_as_string : loc:Location.t -> Parsetree.expression (** Same as setting the directory name with [-dirname], for tests *) val set_dirname : string option -> unit (** Prepend the directory name if [-dirname] was passed on the command line and the filename is relative. *) val expand_filename : string -> string ppx_here-0.16.0/ppx_here.opam000066400000000000000000000013061442175067100161070ustar00rootroot00000000000000opam-version: "2.0" version: "v0.16.0" maintainer: "Jane Street developers" authors: ["Jane Street Group, LLC"] homepage: "https://github.com/janestreet/ppx_here" bug-reports: "https://github.com/janestreet/ppx_here/issues" dev-repo: "git+https://github.com/janestreet/ppx_here.git" doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/ppx_here/index.html" license: "MIT" build: [ ["dune" "build" "-p" name "-j" jobs] ] depends: [ "ocaml" {>= "4.14.0"} "base" {>= "v0.16" & < "v0.17"} "dune" {>= "2.0.0"} "ppxlib" {>= "0.28.0"} ] available: arch != "arm32" & arch != "x86_32" synopsis: "Expands [%here] into its location" description: " Part of the Jane Street's PPX rewriters collection. " ppx_here-0.16.0/runtime-lib/000077500000000000000000000000001442175067100156465ustar00rootroot00000000000000ppx_here-0.16.0/runtime-lib/dune000066400000000000000000000001371442175067100165250ustar00rootroot00000000000000(library (name ppx_here_lib) (public_name ppx_here.runtime-lib) (preprocess no_preprocessing))ppx_here-0.16.0/runtime-lib/ppx_here_lib.ml000066400000000000000000000001611442175067100206360ustar00rootroot00000000000000type position = Lexing.position = { pos_fname : string; pos_lnum : int; pos_bol : int; pos_cnum : int; } ppx_here-0.16.0/runtime-lib/ppx_here_lib.mli000066400000000000000000000001611442175067100210070ustar00rootroot00000000000000type position = Lexing.position = { pos_fname : string; pos_lnum : int; pos_bol : int; pos_cnum : int; } ppx_here-0.16.0/src/000077500000000000000000000000001442175067100142065ustar00rootroot00000000000000ppx_here-0.16.0/src/dune000066400000000000000000000002101442175067100150550ustar00rootroot00000000000000(library (name ppx_here) (public_name ppx_here) (kind ppx_rewriter) (libraries ppxlib ppx_here_expander) (preprocess no_preprocessing))ppx_here-0.16.0/src/ppx_here.ml000066400000000000000000000003731442175067100163550ustar00rootroot00000000000000open Ppxlib let here = Extension.declare "here" Extension.Context.expression Ast_pattern.(pstr nil) (fun ~loc ~path:_ -> Ppx_here_expander.lift_position ~loc) ;; let () = Driver.register_transformation "here" ~extensions:[ here ] ;; ppx_here-0.16.0/src/ppx_here.mli000066400000000000000000000000001442175067100165110ustar00rootroot00000000000000ppx_here-0.16.0/test/000077500000000000000000000000001442175067100143765ustar00rootroot00000000000000ppx_here-0.16.0/test/dummy.mll000066400000000000000000000001151442175067100162340ustar00rootroot00000000000000{ let _ = [%here] } rule a = parse | _ { ignore ([%here]); assert false } ppx_here-0.16.0/test/dune000066400000000000000000000003501442175067100152520ustar00rootroot00000000000000(alias (name runtest) (deps dummy.ml.pp) (action (bash "grep -q '\"ppx/ppx_here/test/dummy.mll\"' dummy.ml.pp"))) (alias (name DEFAULT) (deps dummy.ml.pp)) (executables (names dummy) (preprocess (pps ppx_here))) (ocamllex dummy)ppx_here-0.16.0/test/test-location.mlt000066400000000000000000000003011442175067100176730ustar00rootroot00000000000000(* -*- tuareg -*- *) #verbose true;; [%here] [%%expect{| - : Lexing.position = {Ppx_here_lib.pos_fname = "ppx/ppx_here/test/test-location.mlt"; pos_lnum = 4; pos_bol = 38; pos_cnum = 38} |}]