src/Pure/Syntax/ast.ML
changeset 15421 fcf747c0b6b8
parent 14981 e73f8140af78
child 15531 08c8dad8e399
equal deleted inserted replaced
15420:45653714db88 15421:fcf747c0b6b8
    21   val str_of_ast: ast -> string
    21   val str_of_ast: ast -> string
    22   val pretty_ast: ast -> Pretty.T
    22   val pretty_ast: ast -> Pretty.T
    23   val pretty_rule: ast * ast -> Pretty.T
    23   val pretty_rule: ast * ast -> Pretty.T
    24   val pprint_ast: ast -> pprint_args -> unit
    24   val pprint_ast: ast -> pprint_args -> unit
    25   val fold_ast: string -> ast list -> ast
    25   val fold_ast: string -> ast list -> ast
       
    26   val fold_ast2: string -> string -> ast list -> ast
    26   val fold_ast_p: string -> ast list * ast -> ast
    27   val fold_ast_p: string -> ast list * ast -> ast
    27   val unfold_ast: string -> ast -> ast list
    28   val unfold_ast: string -> ast -> ast list
       
    29   val unfold_ast2: string -> string -> ast -> ast list
    28   val unfold_ast_p: string -> ast -> ast list * ast
    30   val unfold_ast_p: string -> ast -> ast list * ast
    29   val trace_ast: bool ref
    31   val trace_ast: bool ref
    30   val stat_ast: bool ref
    32   val stat_ast: bool ref
    31   end;
    33   end;
    32 
    34 
   140   | fold_ast _ [y] = y
   142   | fold_ast _ [y] = y
   141   | fold_ast c (x :: xs) = Appl [Constant c, x, fold_ast c xs];
   143   | fold_ast c (x :: xs) = Appl [Constant c, x, fold_ast c xs];
   142 
   144 
   143 fun fold_ast_p c = foldr (fn (x, xs) => Appl [Constant c, x, xs]);
   145 fun fold_ast_p c = foldr (fn (x, xs) => Appl [Constant c, x, xs]);
   144 
   146 
       
   147 fun fold_ast2 _ _ [] = raise Match
       
   148   | fold_ast2 _ c1 [y] = Appl [Constant c1, y]
       
   149   | fold_ast2 c c1 (x :: xs) = Appl [Constant c, x, fold_ast2 c c1 xs];
   145 
   150 
   146 (* unfold asts *)
   151 (* unfold asts *)
   147 
   152 
   148 fun unfold_ast c (y as Appl [Constant c', x, xs]) =
   153 fun unfold_ast c (y as Appl [Constant c', x, xs]) =
   149       if c = c' then x :: (unfold_ast c xs) else [y]
   154       if c = c' then x :: (unfold_ast c xs) else [y]
   150   | unfold_ast _ y = [y];
   155   | unfold_ast _ y = [y];
       
   156 
       
   157 fun unfold_ast2 c c1 (y as Appl [Constant c', x, xs]) =
       
   158       if c = c' then x :: (unfold_ast2 c c1 xs) else [y]
       
   159   | unfold_ast2 _ c1 (y as Appl [Constant c', x]) =
       
   160       if c1 = c' then [x] else [y]
       
   161   | unfold_ast2 _ _ y = [y];
   151 
   162 
   152 fun unfold_ast_p c (y as Appl [Constant c', x, xs]) =
   163 fun unfold_ast_p c (y as Appl [Constant c', x, xs]) =
   153       if c = c' then apfst (cons x) (unfold_ast_p c xs)
   164       if c = c' then apfst (cons x) (unfold_ast_p c xs)
   154       else ([], y)
   165       else ([], y)
   155   | unfold_ast_p _ y = ([], y);
   166   | unfold_ast_p _ y = ([], y);