Add primitive action handlers
[hcoop/domtool2.git] / src / env.sml
index d18a5a9..47003cb 100644 (file)
@@ -25,10 +25,24 @@ open Ast
 structure SS = StringSet
 structure SM = StringMap
 
 structure SS = StringSet
 structure SM = StringMap
 
-val typeRules : (exp -> bool) SM.map ref = ref SM.empty
+type typeRule = exp -> bool
+val typeRules : typeRule SM.map ref = ref SM.empty
 fun registerType (name, rule) = typeRules := SM.insert (!typeRules, name, rule)
 fun typeRule name = SM.find (!typeRules, name)
 
 fun registerType (name, rule) = typeRules := SM.insert (!typeRules, name, rule)
 fun typeRule name = SM.find (!typeRules, name)
 
+type env_vars = exp SM.map
+type action = env_vars * Ast.exp list -> env_vars
+val actions : action SM.map ref = ref SM.empty
+fun registerAction (name, action) = actions := SM.insert (!actions, name, action)
+fun action name = SM.find (!actions, name)
+
+val containers : (action * (unit -> unit)) SM.map ref = ref SM.empty
+fun registerContainer (name, befor, after) =
+    containers := SM.insert (!containers, name, (befor, after))
+fun container name = SM.find (!containers, name)
+
+fun badArgs name = raise Fail ("Invalid arguments to " ^ name)
+
 type env = SS.set * (typ * exp option) SM.map
 val empty : env = (SS.add (SS.singleton "int", "string"),
                   SM.empty)
 type env = SS.set * (typ * exp option) SM.map
 val empty : env = (SS.add (SS.singleton "int", "string"),
                   SM.empty)