Skip to content

Commit 75f1674

Browse files
committed
ENH: convert syntax tree to JSON
- API: add command-line option `--json-ast`
1 parent e5baf54 commit 75f1674

File tree

14 files changed

+1229
-1
lines changed

14 files changed

+1229
-1
lines changed

src/backend/prep.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,21 @@ let expand_enabled_cdot ob
897897
print_obl_and_msg ob (
898898
"Proof obligation before `Expr.Action.expand_action_operators`:\n");
899899
let expr = expr_from_obl ob in
900+
(* Print syntax tree if requested. *)
901+
if !Params.dumps_json_ast then begin
902+
let visitor =
903+
object (self: 'self)
904+
inherit [unit] Expr.Visit.json_map
905+
end in
906+
let cx = ((), Deque.empty) in
907+
let json_str = visitor#expr cx expr in
908+
print_string (
909+
"------------\n\
910+
JSON output:\n\n" ^
911+
json_str ^
912+
"\n\n========\n\n")
913+
end;
914+
(* expand action operators *)
900915
let expr: Expr.T.expr = begin
901916
if expand_enabled || expand_cdot then begin
902917
let cx = Deque.empty in

src/expr.mli

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,42 @@ module Visit : sig
308308
method rename : ctx -> hyp -> Util.hint -> hyp * Util.hint
309309
method renames : ctx -> hyp list -> Util.hint list -> hyp list * Util.hint list
310310
end
311+
312+
val hyps_of_bounds: bounds -> hyp list
313+
314+
class virtual ['s] json_map: object
315+
method expr:
316+
's scx -> expr -> string
317+
method sel:
318+
's scx -> sel -> string
319+
method sequent:
320+
's scx -> sequent -> string
321+
method defn:
322+
's scx -> defn -> string
323+
method defns:
324+
's scx -> defn list ->
325+
's scx * string
326+
method bounds: 's scx -> bounds ->
327+
's scx * string
328+
method bound: 's scx -> bound ->
329+
's scx * string
330+
method exspec:
331+
's scx -> exspec -> string
332+
method instance:
333+
's scx -> instance -> string
334+
method hyp:
335+
's scx -> hyp -> 's scx * string
336+
method hyps:
337+
's scx -> hyp Deque.dq ->
338+
's scx * string
339+
method adj:
340+
's scx -> hyp -> 's scx
341+
method adjs:
342+
's scx -> hyp list -> 's scx
343+
end
344+
val format_parameter:
345+
Util.hint * shape -> string
346+
val json_of_ast: ctx -> expr -> string
311347
end;;
312348

313349
module Eq : sig

0 commit comments

Comments
 (0)