-
-
Save gsg/28ca0dcb42bfdf7a8b13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let map_collect_by_name tbl list = | |
let rec loop = function | |
| [] -> () | |
| D _::elts -> loop elts | |
| E (((_, name), attrs) as tag, children)::elts -> | |
try (Hashtbl.find tbl name) attrs children | |
with Not_found -> | |
failwith (Printf.sprintf "bad tag: %s" (fmt_tag tag)) in | |
loop list | |
let define_op tbl (name:string) f = | |
let cell = ref [] in | |
Hashtbl.add tbl name | |
(fun attrs children -> | |
cell := f attrs children::!cell); | |
cell | |
let parse_domain_children list = | |
let ops = Hashtbl.create 2 in | |
let rules = define_op ops "rule" parse_rule in | |
let assertions = define_op ops "assert" parse_assertion in | |
map_collect_by_name ops list; | |
!rules, !assertions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment