521 datatype tree = |
521 datatype tree = |
522 Node of string * tree list | |
522 Node of string * tree list | |
523 Tip of Lexicon.token; |
523 Tip of Lexicon.token; |
524 |
524 |
525 local |
525 local |
526 |
526 fun cons_nr (Node _) = 0 |
527 fun cons_nr (Node _) = 0 |
527 | cons_nr (Tip _) = 1; |
528 | cons_nr (Tip _) = 1; |
|
529 |
|
530 in |
528 in |
531 |
529 fun tree_ord trees = |
532 fun tree_ord trees = |
530 if pointer_eq trees then EQUAL |
533 if pointer_eq trees then EQUAL |
531 else |
534 else |
532 (case trees of |
535 (case trees of |
533 (Node (s, ts), Node (s', ts')) => |
536 (Node (s, ts), Node (s', ts')) => |
534 (case fast_string_ord (s, s') of |
537 (case fast_string_ord (s, s') of |
535 EQUAL => list_ord tree_ord (ts, ts') |
538 EQUAL => list_ord tree_ord (ts, ts') |
536 | ord => ord) |
539 | ord => ord) |
537 | (Tip t, Tip t') => Lexicon.token_ord (t, t') |
540 | (Tip t, Tip t') => Lexicon.token_ord (t, t') |
538 | _ => int_ord (apply2 cons_nr trees)); |
541 | _ => int_ord (apply2 cons_nr trees)); |
|
542 |
|
543 end; |
539 end; |
544 |
540 |
545 fun pretty_tree (Node (c, ts)) = |
541 fun pretty_tree (Node (c, ts)) = |
546 [Pretty.enclose "(" ")" (Pretty.breaks (Pretty.quote (Pretty.str c) :: maps pretty_tree ts))] |
542 [Pretty.enclose "(" ")" (Pretty.breaks (Pretty.quote (Pretty.str c) :: maps pretty_tree ts))] |
547 | pretty_tree (Tip tok) = |
543 | pretty_tree (Tip tok) = |