From 2d979ebfce80b25217d8d2ffbc725c4fe9aefc60 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Sat, 5 Apr 2025 11:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AstConv/AstImport.fs | 3 +++ AstConv/FmtStruct.fs | 27 +++++++++++++++------------ AstConv/Program.fs | 4 +--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/AstConv/AstImport.fs b/AstConv/AstImport.fs index 6891cdd..0267142 100644 --- a/AstConv/AstImport.fs +++ b/AstConv/AstImport.fs @@ -299,6 +299,9 @@ open System.Linq inherit AstObject(bind) new(bind: XmlElement) = Program(bind, []) + member this.dirPath() = + bind.GetAttribute "dir_src" + member this.time() = bind.GetAttribute "time" member this.children() = objs diff --git a/AstConv/FmtStruct.fs b/AstConv/FmtStruct.fs index 75abfe2..922f05c 100644 --- a/AstConv/FmtStruct.fs +++ b/AstConv/FmtStruct.fs @@ -1,5 +1,6 @@ namespace FmtStruct +open System.IO open AstAccess open HtmlStruct @@ -58,7 +59,7 @@ open HtmlStruct let text_type_childs = text_childs|> List.map(fun n-> n:?> Content.TextContent) let sections = text_fmt (prefix+" ") (objref.rows()) text_type_childs - $"{prefix}{{@情节 {objref.storyRef()}&{objref.sliceRef()}{sections}}}" + $"\n{prefix}{{@情节 {objref.storyRef()}&{objref.sliceRef()}{sections}}}" // 格式化Slice:Node @@ -85,7 +86,7 @@ open HtmlStruct let subs = match contents with | [] -> "" | _ -> contents|> List.reduce(fun a b -> a + "\n" + b) - $"{prefix}{{情节 {obj_def.name()}{subs}\n{prefix}}}" + $"\n{prefix}{{情节 {obj_def.name()}{subs}\n{prefix}}}" // 格式化Story:Node @@ -112,7 +113,7 @@ open HtmlStruct let subs = match contents with | [] -> "" | _ -> contents|> List.reduce(fun a b -> a + "\n" + b) - $"{{故事 {obj_story.name()}{subs}\n}}" + $"\n{{故事 {obj_story.name()}{subs}\n}}" // 格式化Article:Node @@ -139,7 +140,7 @@ open HtmlStruct let subs = match contents with | [] -> "" | _ -> contents|> List.reduce(fun a b -> a + "\n" + b) - $"{prefix}{{章节 {obj_article.name()}{subs}\n{prefix}}}" + $"\n{prefix}{{章节 {obj_article.name()}{subs}\n{prefix}}}" // 格式化Volume:Node @@ -166,10 +167,10 @@ open HtmlStruct let subs = match contents with | [] -> "" | _ -> contents|> List.reduce(fun a b -> a + "\n" + b) - $"{{分卷 {obj_volume.name()}{subs}\n}}" + $"\n{{分卷 {obj_volume.name()}{subs}\n}}" - let document_def_fmt(path:string)(nodes: Present.IDomUnit list):string = + let document_def_fmt(path:string)(nodes: Present.IDomUnit list): unit = let head_str, rest_nodes=match nodes.Head with | :? Content.RankDefine -> rank_fmt(nodes.Head.object()), nodes.Tail @@ -183,13 +184,16 @@ open HtmlStruct story_def_fmt sdef | _ -> failwith "error-doc-child" ) - head_str + (nodes_str|> List.reduce(fun a b -> a + "\n" + b)) + let xcontent = head_str + (nodes_str|> List.reduce(fun a b -> a + "\n" + b)) + use wr = new StreamWriter(path,false) + wr.Write(xcontent) + - let program_def_fmt(nodes: Present.IDomUnit list):string list = + let program_def_fmt(dir:string)(nodes: Present.IDomUnit list): unit = let ranks = nodes|> List.filter(fun n -> n:?Content.RankDefine) - let content_with_rank = ranks|> List.map(fun rankn -> + ranks|> List.iter(fun rankn -> let rank_o = rankn.object() :?> AstImport.RankDef let file_path = rank_o.filePath() @@ -200,7 +204,7 @@ open HtmlStruct | :? Content.VolumeDefine -> n.object().filePath() = file_path | _ -> false) - document_def_fmt file_path (rankn::nodes_within) + document_def_fmt (Path.Combine(dir, file_path)) (rankn::nodes_within) ) let nodes_hangout = nodes|> List.filter(fun n -> @@ -214,9 +218,8 @@ open HtmlStruct let path_hangout = nodes_hangout|> List.map(fun n -> n.object().filePath()) |> List.distinct - let content_without_rank = path_hangout |> List.map(fun path -> + path_hangout |> List.iter(fun path -> let nodes_within = nodes_hangout|> List.filter(fun n -> n.object().filePath() = path) document_def_fmt path nodes_within ) - content_with_rank@content_without_rank diff --git a/AstConv/Program.fs b/AstConv/Program.fs index a88b7ec..da9d15b 100644 --- a/AstConv/Program.fs +++ b/AstConv/Program.fs @@ -71,9 +71,7 @@ let source_format (file_in:FileInfo): unit = // 获取内容节点 let nodes = visitor.contents() - let strings = program_def_fmt nodes - for it in strings do - printfn $"{it}" + program_def_fmt (prog.dirPath()) nodes