712 |
712 |
713 def read_theory( |
713 def read_theory( |
714 theory_context: Export.Theory_Context, |
714 theory_context: Export.Theory_Context, |
715 unicode_symbols: Boolean = false |
715 unicode_symbols: Boolean = false |
716 ): Option[Document.Snapshot] = { |
716 ): Option[Document.Snapshot] = { |
717 def decode_bytes(bytes: Bytes): String = |
717 def decode(str: String): String = Symbol.output(unicode_symbols, str) |
718 Symbol.output(unicode_symbols, bytes.text) |
|
719 |
718 |
720 def read(name: String): Export.Entry = theory_context(name, permissive = true) |
719 def read(name: String): Export.Entry = theory_context(name, permissive = true) |
721 |
720 |
722 def read_xml(name: String): XML.Body = |
721 def read_xml(name: String): XML.Body = |
723 YXML.parse_body(decode_bytes(read(name).bytes), cache = theory_context.cache) |
722 YXML.parse_body(read(name).bytes.text, recode = decode, cache = theory_context.cache) |
724 |
723 |
725 def read_source_file(name: String): Store.Source_File = |
724 def read_source_file(name: String): Store.Source_File = |
726 theory_context.session_context.source_file(name) |
725 theory_context.session_context.source_file(name) |
727 |
726 |
728 for { |
727 for { |
739 val path = Path.explode(name) |
738 val path = Path.explode(name) |
740 val src_path = File.relative_path(master_dir, path).getOrElse(path) |
739 val src_path = File.relative_path(master_dir, path).getOrElse(path) |
741 |
740 |
742 val file = read_source_file(name) |
741 val file = read_source_file(name) |
743 val bytes = file.bytes |
742 val bytes = file.bytes |
744 val text = decode_bytes(bytes) |
743 val text = decode(bytes.text) |
745 val chunk = Symbol.Text_Chunk(text) |
744 val chunk = Symbol.Text_Chunk(text) |
746 |
745 |
747 Command.Blob(Document.Node.Name(name), src_path, Some((file.digest, chunk))) -> |
746 Command.Blob(Document.Node.Name(name), src_path, Some((file.digest, chunk))) -> |
748 Document.Blobs.Item(bytes, text, chunk, changed = false) |
747 Document.Blobs.Item(bytes, text, chunk, changed = false) |
749 } |
748 } |
750 |
749 |
751 val thy_source = decode_bytes(read_source_file(thy_file).bytes) |
750 val thy_source = decode(read_source_file(thy_file).bytes.text) |
752 val thy_xml = read_xml(Export.MARKUP) |
751 val thy_xml = read_xml(Export.MARKUP) |
753 val blobs_xml = |
752 val blobs_xml = |
754 for (i <- (1 to blobs.length).toList) |
753 for (i <- (1 to blobs.length).toList) |
755 yield read_xml(Export.MARKUP + i) |
754 yield read_xml(Export.MARKUP + i) |
756 |
755 |