let maybe f x = try Some (f x) with _ -> None
let tee f x = try ignore @@ f x; x with _ -> x
-type ('a,'b) either = Val of 'a | Error of 'b
+type ('a,'b) either = Val of 'a | Err of 'b
let string_of_list xs =
Printf.sprintf "[%s]"
meth = List.fold_left (flip MSet.remove) env.meth ms;
klass = CSet.remove {name with value=("",name.value)} env.klass}
-let unbound program =
- if List.fold_right unbound_stmt program empty = empty then
- Val true
- else
- Error false
+
+let trans (stmt : stmt) : Ast.stmt option =
+ match stmt with
+ `External _ | `ExternalClass _ ->
+ None
+ | #Ast.stmt as s ->
+ Some s
+
+
+let trans (program : stmt list)=
+ let program',env =
+ List.fold_right (fun s (stmt,env) ->
+ let env' =
+ unbound_stmt s env in
+ match trans s with
+ Some s' ->
+ ((s'::stmt),env')
+ | None ->
+ stmt,env')
+ program
+ ([],empty) in
+ if env = empty then
+ Val program'
+ else
+ Err (Node.empty "")
+
--- /dev/null
+type method_ = Ast.ident * Ast.ident list
+type stmt =
+ [ `ExternalClass of Ast.ident * Ast.name * Ast.attr list * method_ list
+ | `External of Ast.ident
+ | Ast.stmt]
+
+val trans : stmt list -> (Ast.stmt list, string Node.t) Base.either