Minor fixes of minor tools

Signed-off-by: Kakadu <Kakadu@pm.me>
This commit is contained in:
Kakadu 2024-09-05 17:32:45 +03:00
parent f6277da16e
commit d3d2535f97
12 changed files with 67 additions and 27 deletions

9
tools/dune Normal file
View file

@ -0,0 +1,9 @@
(executable
(name tool)
(modules tool)
(flags
(:standard -rectypes))
(libraries liba))
(cram
(deps ../runtime/runtime.a ../runtime/Std.i ./tool.exe demo1.lama))

4
tools/run.t Normal file
View file

@ -0,0 +1,4 @@
$ LAMA=../runtime ./tool.exe demo1.lama -pos 5,22 -use
found definition for `f` at (1,19)
Total 2 usages found
(5,24) (5,22)

View file

@ -14,9 +14,10 @@ type config =
; mutable line : int
; mutable col: int
; mutable mode: mode
; mutable includes : string list
}
let config = { filename= "file.ml"; pos="0,0"; line=0; col=0; mode = GoToDef }
let config = { filename= "file.ml"; pos="0,0"; line=0; col=0; mode = GoToDef; includes = ["."; "./runtime"] }
let _ = if false then config.pos <- "" else ignore config.pos
let parse_loc loc =
Scanf.sscanf loc "%d,%d" (fun l c -> config.line <- l; config.col <- c)
@ -26,6 +27,7 @@ let () =
[ "-pos", String parse_loc, "L,C when L is line and C is column"
; "-def", Unit (fun () -> config.mode <- GoToDef), "go to definition"
; "-use", Unit (fun () -> config.mode <- Usages), "find usages"
; "-I", String (fun s -> config.includes <- s :: config.includes), " Add include path"
]
(fun name -> config.filename <- name)
"Help"
@ -118,7 +120,10 @@ let find_usages root (def_name,(_,_)) =
let () =
let cfg = object
method get_include_paths = ["."; "./runtime"] method get_infile = config.filename method is_workaround=false end
method get_include_paths = ["."; "./runtime"; "../runtime"]
method get_infile = config.filename
method is_workaround = false
end
in
match Language.run_parser cfg with
| `Fail s -> failwith s