411 in Long_Name.implode (remainder @ [base']) end |
411 in Long_Name.implode (remainder @ [base']) end |
412 handle Graph.UNDEF _ => error ("Unknown statement name: " ^ labelled_name name); |
412 handle Graph.UNDEF _ => error ("Unknown statement name: " ^ labelled_name name); |
413 |
413 |
414 in (deresolver, sca_program) end; |
414 in (deresolver, sca_program) end; |
415 |
415 |
416 fun serialize_scala labelled_name raw_reserved includes _ module_alias |
416 fun serialize_scala { labelled_name, reserved_syms, includes, single_module, |
417 _ tyco_syntax const_syntax |
417 module_alias, class_syntax, tyco_syntax, const_syntax, program, |
418 program (stmt_names, presentation_stmt_names) = |
418 names, presentation_names } = |
419 let |
419 let |
420 |
420 |
421 (* build program *) |
421 (* build program *) |
422 val reserved = fold (insert (op =) o fst) includes raw_reserved; |
422 val reserved = fold (insert (op =) o fst) includes reserved_syms; |
423 val (deresolver, sca_program) = scala_program_of_program labelled_name |
423 val (deresolver, sca_program) = scala_program_of_program labelled_name |
424 (Name.make_context reserved) module_alias program; |
424 (Name.make_context reserved) module_alias program; |
425 |
425 |
426 (* print statements *) |
426 (* print statements *) |
427 fun lookup_constr tyco constr = case Graph.get_node program tyco |
427 fun lookup_constr tyco constr = case Graph.get_node program tyco |
453 let |
453 let |
454 val s = deresolver prefix_fragments implicit; |
454 val s = deresolver prefix_fragments implicit; |
455 in if length (Long_Name.explode s) = 1 then NONE else SOME (str s) end; |
455 in if length (Long_Name.explode s) = 1 then NONE else SOME (str s) end; |
456 fun print_node _ (_, Dummy) = NONE |
456 fun print_node _ (_, Dummy) = NONE |
457 | print_node prefix_fragments (name, Stmt stmt) = |
457 | print_node prefix_fragments (name, Stmt stmt) = |
458 if null presentation_stmt_names |
458 if null presentation_names |
459 orelse member (op =) presentation_stmt_names name |
459 orelse member (op =) presentation_names name |
460 then SOME (print_stmt (deresolver prefix_fragments, deresolver []) (name, stmt)) |
460 then SOME (print_stmt (deresolver prefix_fragments, deresolver []) (name, stmt)) |
461 else NONE |
461 else NONE |
462 | print_node prefix_fragments (name_fragment, Module (implicits, nodes)) = |
462 | print_node prefix_fragments (name_fragment, Module (implicits, nodes)) = |
463 if null presentation_stmt_names |
463 if null presentation_names |
464 then |
464 then |
465 let |
465 let |
466 val prefix_fragments' = prefix_fragments @ [name_fragment]; |
466 val prefix_fragments' = prefix_fragments @ [name_fragment]; |
467 in |
467 in |
468 Option.map (print_module name_fragment |
468 Option.map (print_module name_fragment |
475 snd (Graph.get_node nodes name))) |
475 snd (Graph.get_node nodes name))) |
476 ((rev o flat o Graph.strong_conn) nodes); |
476 ((rev o flat o Graph.strong_conn) nodes); |
477 in if null ps then NONE else SOME (Pretty.chunks2 ps) end; |
477 in if null ps then NONE else SOME (Pretty.chunks2 ps) end; |
478 |
478 |
479 (* serialization *) |
479 (* serialization *) |
480 val p_includes = if null presentation_stmt_names |
480 val p_includes = if null presentation_names |
481 then map (fn (base, p) => print_module base [] p) includes else []; |
481 then map (fn (base, p) => print_module base [] p) includes else []; |
482 val p = Pretty.chunks2 (p_includes @ the_list (print_nodes [] sca_program)); |
482 val p = Pretty.chunks2 (p_includes @ the_list (print_nodes [] sca_program)); |
483 fun write width NONE = writeln_pretty width |
483 fun write width NONE = writeln_pretty width |
484 | write width (SOME p) = File.write p o string_of_pretty width; |
484 | write width (SOME p) = File.write p o string_of_pretty width; |
485 in |
485 in |