equal
deleted
inserted
replaced
82 (* pretty_ast *) |
82 (* pretty_ast *) |
83 |
83 |
84 fun pretty_ast (Constant a) = Pretty.str (quote a) |
84 fun pretty_ast (Constant a) = Pretty.str (quote a) |
85 | pretty_ast (Variable x) = Pretty.str x |
85 | pretty_ast (Variable x) = Pretty.str x |
86 | pretty_ast (Appl asts) = |
86 | pretty_ast (Appl asts) = |
87 Pretty.blk (2, (Pretty.str "(") :: |
87 Pretty.parents "(" ")" (Pretty.breaks (map pretty_ast asts)); |
88 (separate (Pretty.brk 1) (map pretty_ast asts)) @ [Pretty.str ")"]); |
|
89 |
88 |
90 |
89 |
91 (* pprint_ast *) |
90 (* pprint_ast *) |
92 |
91 |
93 val pprint_ast = Pretty.pprint o pretty_ast; |
92 val pprint_ast = Pretty.pprint o pretty_ast; |
94 |
93 |
95 |
94 |
96 (* pretty_rule *) |
95 (* pretty_rule *) |
97 |
96 |
98 fun pretty_rule (lhs, rhs) = |
97 fun pretty_rule (lhs, rhs) = |
99 Pretty.blk |
98 Pretty.block [pretty_ast lhs, Pretty.str " ->", Pretty.brk 2, pretty_ast rhs]; |
100 (2, [pretty_ast lhs, Pretty.str " ->", Pretty.brk 2, pretty_ast rhs]); |
|
101 |
99 |
102 |
100 |
103 (* head_of_ast, head_of_rule *) |
101 (* head_of_ast, head_of_rule *) |
104 |
102 |
105 fun head_of_ast (Constant a) = Some a |
103 fun head_of_ast (Constant a) = Some a |
210 val passes = ref 0; |
208 val passes = ref 0; |
211 val lookups = ref 0; |
209 val lookups = ref 0; |
212 val failed_matches = ref 0; |
210 val failed_matches = ref 0; |
213 val changes = ref 0; |
211 val changes = ref 0; |
214 |
212 |
215 fun inc i = i := ! i + 1; |
|
216 |
|
217 fun subst _ (ast as Constant _) = ast |
213 fun subst _ (ast as Constant _) = ast |
218 | subst env (Variable x) = Env.get (env, x) |
214 | subst env (Variable x) = Env.get (env, x) |
219 | subst env (Appl asts) = Appl (map (subst env) asts); |
215 | subst env (Appl asts) = Appl (map (subst env) asts); |
220 |
216 |
221 fun try_rules ast ((lhs, rhs) :: pats) = |
217 fun try_rules ast ((lhs, rhs) :: pats) = |