This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
6
unikernel/duniverse/ppxlib/ast/pp/dune
Normal file
6
unikernel/duniverse/ppxlib/ast/pp/dune
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(executables
|
||||
(names pp)
|
||||
(libraries supported_version)
|
||||
(flags :standard -w -3))
|
||||
|
||||
(ocamllex pp_rewrite)
|
||||
16
unikernel/duniverse/ppxlib/ast/pp/pp.ml
Normal file
16
unikernel/duniverse/ppxlib/ast/pp/pp.ml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
let () =
|
||||
match Sys.argv with
|
||||
| [| _; ocaml_version_str; fname |] ->
|
||||
let ocaml_version =
|
||||
match Supported_version.of_string ocaml_version_str with
|
||||
| Some v -> string_of_int (Supported_version.to_int v)
|
||||
| None ->
|
||||
Printf.eprintf "Unknown OCaml version %s\n" ocaml_version_str;
|
||||
exit 1
|
||||
in
|
||||
let ic = open_in_bin fname in
|
||||
Printf.printf "# 1 %S\n" fname;
|
||||
Pp_rewrite.rewrite ocaml_version (Lexing.from_channel ic)
|
||||
| _ ->
|
||||
Printf.eprintf "%s: <ocaml-version> <file-name>\n" Sys.executable_name;
|
||||
exit 2
|
||||
1
unikernel/duniverse/ppxlib/ast/pp/pp.mli
Normal file
1
unikernel/duniverse/ppxlib/ast/pp/pp.mli
Normal file
|
|
@ -0,0 +1 @@
|
|||
(* empty *)
|
||||
1
unikernel/duniverse/ppxlib/ast/pp/pp_rewrite.mli
Normal file
1
unikernel/duniverse/ppxlib/ast/pp/pp_rewrite.mli
Normal file
|
|
@ -0,0 +1 @@
|
|||
val rewrite : string -> Lexing.lexbuf -> unit
|
||||
27
unikernel/duniverse/ppxlib/ast/pp/pp_rewrite.mll
Normal file
27
unikernel/duniverse/ppxlib/ast/pp/pp_rewrite.mll
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
open Printf
|
||||
|
||||
let print_ocaml_version version =
|
||||
let patt_len = String.length "OCAML_VERSION" in
|
||||
(* Note: the spaces in the replacements are to preserve locations *)
|
||||
printf "%-*s" patt_len version
|
||||
}
|
||||
|
||||
rule rewrite ocaml_version = parse
|
||||
| "OCAML_VERSION"
|
||||
{ print_ocaml_version ocaml_version;
|
||||
rewrite ocaml_version lexbuf
|
||||
}
|
||||
| "(*IF_AT_LEAST " ([^'*' ' ']* as v) " " ([^'*']* as s) "*)"
|
||||
{ let chunk = if (v <= ocaml_version)
|
||||
then " " ^ String.make (String.length v + 1) ' ' ^ s ^ " "
|
||||
else Lexing.lexeme lexbuf
|
||||
in
|
||||
print_string chunk;
|
||||
rewrite ocaml_version lexbuf
|
||||
}
|
||||
| _ as c
|
||||
{ print_char c;
|
||||
rewrite ocaml_version lexbuf
|
||||
}
|
||||
| eof { () }
|
||||
Loading…
Add table
Add a link
Reference in a new issue