add a new CLI command: list-declarations
This commit is contained in:
parent
a8fdb46a3a
commit
fd47f51031
@ -410,6 +410,19 @@ let dump_changelog =
|
||||
let doc = "Dump the LIGO changelog to stdout." in
|
||||
(Term.ret term , Term.info ~doc cmdname)
|
||||
|
||||
let list_declarations =
|
||||
let f source_file syntax =
|
||||
toplevel ~display_format:(`Human_readable) @@
|
||||
let%bind simplified_prg = Compile.Of_source.compile source_file (Syntax_name syntax) in
|
||||
let json_decl = List.map (fun decl -> `String decl) @@ Compile.Of_simplified.list_declarations simplified_prg in
|
||||
ok @@ J.to_string @@ `Assoc [ ("source_file", `String source_file) ; ("declarations", `List json_decl) ]
|
||||
in
|
||||
let term =
|
||||
Term.(const f $ source_file 0 $ syntax ) in
|
||||
let cmdname = "list-declarations" in
|
||||
let doc = "Subcommand: list all the top-level decalarations." in
|
||||
(Term.ret term , Term.info ~doc cmdname)
|
||||
|
||||
let run ?argv () =
|
||||
Term.eval_choice ?argv main [
|
||||
compile_file ;
|
||||
@ -425,5 +438,6 @@ let run ?argv () =
|
||||
print_cst ;
|
||||
print_ast ;
|
||||
print_typed_ast ;
|
||||
print_mini_c
|
||||
print_mini_c ;
|
||||
list_declarations ;
|
||||
]
|
||||
|
@ -44,6 +44,9 @@ let%expect_test _ =
|
||||
Subcommand: interpret the expression in the context initialized by
|
||||
the provided source file.
|
||||
|
||||
list-declarations
|
||||
Subcommand: list all the top-level decalarations.
|
||||
|
||||
measure-contract
|
||||
Subcommand: measure a contract's compiled size in bytes.
|
||||
|
||||
@ -117,6 +120,9 @@ let%expect_test _ =
|
||||
Subcommand: interpret the expression in the context initialized by
|
||||
the provided source file.
|
||||
|
||||
list-declarations
|
||||
Subcommand: list all the top-level decalarations.
|
||||
|
||||
measure-contract
|
||||
Subcommand: measure a contract's compiled size in bytes.
|
||||
|
||||
|
@ -21,3 +21,13 @@ let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simpl
|
||||
|
||||
let pretty_print formatter (program : Ast_simplified.program) =
|
||||
Ast_simplified.PP.program formatter program
|
||||
|
||||
let list_declarations (program : Ast_simplified.program) : string list =
|
||||
List.fold_left
|
||||
(fun prev el ->
|
||||
let open Location in
|
||||
let open Ast_simplified in
|
||||
match el.wrap_content with
|
||||
| Declaration_constant (var,_,_,_) -> (Var.to_name var)::prev
|
||||
| _ -> prev)
|
||||
[] program
|
||||
|
Loading…
Reference in New Issue
Block a user