This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
(melange.emit
|
||||
(target out)
|
||||
(lint
|
||||
(pps correct_static_add)))
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
let detect_static_add = object
|
||||
inherit Ppxlib.Ast_traverse.iter as super
|
||||
|
||||
method! expression e =
|
||||
match e with
|
||||
| { pexp_desc =
|
||||
Pexp_apply
|
||||
( {pexp_desc = Pexp_ident {txt = Lident "+"; _}; _}
|
||||
, [ (Nolabel, {pexp_desc = Pexp_constant (Pconst_integer (a, None)); _})
|
||||
; (Nolabel, {pexp_desc = Pexp_constant (Pconst_integer (b, None)); _})
|
||||
]
|
||||
)
|
||||
; pexp_loc = loc
|
||||
; _
|
||||
} ->
|
||||
let sum = int_of_string a + int_of_string b in
|
||||
let repl = string_of_int sum in
|
||||
Ppxlib.Driver.register_correction ~loc ~repl
|
||||
| _ -> super#expression e
|
||||
end
|
||||
|
||||
let impl s =
|
||||
detect_static_add#structure s; s
|
||||
|
||||
let () =
|
||||
Ppxlib.Driver.register_transformation
|
||||
"detect_static_add"
|
||||
~impl
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(library
|
||||
(name correct_static_add)
|
||||
(kind ppx_rewriter)
|
||||
(libraries ppxlib))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(lang dune 3.13)
|
||||
|
||||
(using melange 0.1)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
The lint alias will run preprocessing actions listed under (lint). It also
|
||||
defines corrections that may be promoted.
|
||||
|
||||
$ cat > correct/add.ml << EOF
|
||||
> let () = Printf.printf "%d\n" @@ 1 + 2
|
||||
> EOF
|
||||
$ dune build @correct/lint
|
||||
File "correct/add.ml", line 1, characters 0-0:
|
||||
Error: Files _build/default/correct/add.ml and
|
||||
_build/default/correct/add.ml.lint-corrected differ.
|
||||
[1]
|
||||
$ dune promote correct/add.ml
|
||||
Promoting _build/default/correct/add.ml.lint-corrected to correct/add.ml.
|
||||
$ cat correct/add.ml
|
||||
let () = Printf.printf "%d\n" @@ 3
|
||||
Loading…
Add table
Add a link
Reference in a new issue