更新格式化代码

This commit is contained in:
codeboss 2025-04-05 11:13:51 +08:00
parent 5e58c924a8
commit 2d979ebfce
3 changed files with 19 additions and 15 deletions

View File

@ -299,6 +299,9 @@ open System.Linq
inherit AstObject(bind) inherit AstObject(bind)
new(bind: XmlElement) = Program(bind, []) new(bind: XmlElement) = Program(bind, [])
member this.dirPath() =
bind.GetAttribute "dir_src"
member this.time() = member this.time() =
bind.GetAttribute "time" bind.GetAttribute "time"
member this.children() = objs member this.children() = objs

View File

@ -1,5 +1,6 @@
namespace FmtStruct namespace FmtStruct
open System.IO
open AstAccess open AstAccess
open HtmlStruct open HtmlStruct
@ -58,7 +59,7 @@ open HtmlStruct
let text_type_childs = text_childs|> List.map(fun n-> n:?> Content.TextContent) let text_type_childs = text_childs|> List.map(fun n-> n:?> Content.TextContent)
let sections = text_fmt (prefix+" ") (objref.rows()) text_type_childs 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 // Slice:Node
@ -85,7 +86,7 @@ open HtmlStruct
let subs = match contents with let subs = match contents with
| [] -> "" | [] -> ""
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b) | _ -> 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 // Story:Node
@ -112,7 +113,7 @@ open HtmlStruct
let subs = match contents with let subs = match contents with
| [] -> "" | [] -> ""
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b) | _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
$"{{故事 {obj_story.name()}{subs}\n}}" $"\n{{故事 {obj_story.name()}{subs}\n}}"
// ArticleNode // ArticleNode
@ -139,7 +140,7 @@ open HtmlStruct
let subs = match contents with let subs = match contents with
| [] -> "" | [] -> ""
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b) | _ -> contents|> List.reduce(fun a b -> a + "\n" + b)
$"{prefix}{{章节 {obj_article.name()}{subs}\n{prefix}}}" $"\n{prefix}{{章节 {obj_article.name()}{subs}\n{prefix}}}"
// VolumeNode // VolumeNode
@ -166,10 +167,10 @@ open HtmlStruct
let subs = match contents with let subs = match contents with
| [] -> "" | [] -> ""
| _ -> contents|> List.reduce(fun a b -> a + "\n" + b) | _ -> 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 let head_str, rest_nodes=match nodes.Head with
| :? Content.RankDefine -> | :? Content.RankDefine ->
rank_fmt(nodes.Head.object()), nodes.Tail rank_fmt(nodes.Head.object()), nodes.Tail
@ -183,13 +184,16 @@ open HtmlStruct
story_def_fmt sdef story_def_fmt sdef
| _ -> failwith "error-doc-child" | _ -> 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 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 rank_o = rankn.object() :?> AstImport.RankDef
let file_path = rank_o.filePath() let file_path = rank_o.filePath()
@ -200,7 +204,7 @@ open HtmlStruct
| :? Content.VolumeDefine -> | :? Content.VolumeDefine ->
n.object().filePath() = file_path n.object().filePath() = file_path
| _ -> false) | _ -> 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 -> 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()) let path_hangout = nodes_hangout|> List.map(fun n -> n.object().filePath())
|> List.distinct |> 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) let nodes_within = nodes_hangout|> List.filter(fun n -> n.object().filePath() = path)
document_def_fmt path nodes_within document_def_fmt path nodes_within
) )
content_with_rank@content_without_rank

View File

@ -71,9 +71,7 @@ let source_format (file_in:FileInfo): unit =
// //
let nodes = visitor.contents() let nodes = visitor.contents()
let strings = program_def_fmt nodes program_def_fmt (prog.dirPath()) nodes
for it in strings do
printfn $"{it}"