src/Pure/Syntax/ast.ML
changeset 235 775dd81a58e5
parent 18 c9ec452ff08f
child 258 e540b7d4ecb1
equal deleted inserted replaced
234:1b3bee8d5d7e 235:775dd81a58e5
    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) =