aboutsummaryrefslogtreecommitdiff
path: root/parsing
diff options
context:
space:
mode:
Diffstat (limited to 'parsing')
-rw-r--r--parsing/coqast.ml16
-rw-r--r--parsing/coqast.mli10
2 files changed, 26 insertions, 0 deletions
diff --git a/parsing/coqast.ml b/parsing/coqast.ml
index b0a825326c..0f0dcda29c 100644
--- a/parsing/coqast.ml
+++ b/parsing/coqast.ml
@@ -15,6 +15,22 @@ type t =
type the_coq_ast = t
+let subst_meta bl ast =
+ let rec aux = function
+ | Node (_,"META", [Num(_, n)]) -> List.assoc n bl
+ | Node(loc, node_name, args) ->
+ Node(loc, node_name, List.map aux args)
+ | Slam(loc, var, arg) -> Slam(loc, var, aux arg)
+ | other -> other
+ in
+ aux ast
+
+let rec collect_metas = function
+ | Node (_,"META", [Num(_, n)]) -> [n]
+ | Node(_, _, args) -> List.concat (List.map collect_metas args)
+ | Slam(loc, var, arg) -> collect_metas arg
+ | _ -> []
+
(* Hash-consing *)
module Hloc = Hashcons.Make(
struct
diff --git a/parsing/coqast.mli b/parsing/coqast.mli
index 006b98b3e0..3a02092cd4 100644
--- a/parsing/coqast.mli
+++ b/parsing/coqast.mli
@@ -1,6 +1,8 @@
(* $Id$ *)
+(* Abstract syntax trees. *)
+
type loc = int * int
type t =
@@ -13,5 +15,13 @@ type t =
| Path of loc * string list* string
| Dynamic of loc * Dyn.t
+(* returns the list of metas occuring in the ast *)
+val collect_metas : t -> int list
+
+(* [subst_meta bl ast]: for each binding [(i,c_i)] in [bl],
+ replace the metavar [?i] by [c_i] in [ast] *)
+val subst_meta : (int * t) list -> t -> t
+
+(* hash-consing function *)
val hcons_ast: (string -> string) -> (t -> t) * (loc -> loc)