From 7c360a1dd8c80ade343ef56bfc3ba8c62c06a353 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Mon, 30 Sep 2024 14:41:13 +0200 Subject: [PATCH] first documentation results --- BeefProj.toml | 1 + BeefSpace.toml | 2 +- documentation.md | 7 ++++ pkkg | 4 ++ src/Constructs/bdocs_Class.bf | 13 +++++++ src/Constructs/bdocs_Method.bf | 14 +++++++ src/Constructs/bdocs_Struct.bf | 13 +++++++ src/Crawler.bf | 71 ++++++++++++++++++++++++++++++++++ src/DataStore.bf | 60 ++++++++++++++++++++++++++++ src/Program.bf | 47 ++++++++++++++++++++++ src/SectionFinder.bf | 57 +++++++++++++++++++++++++++ 11 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 documentation.md create mode 100644 src/Constructs/bdocs_Class.bf create mode 100644 src/Constructs/bdocs_Method.bf create mode 100644 src/Constructs/bdocs_Struct.bf create mode 100644 src/Crawler.bf create mode 100644 src/DataStore.bf create mode 100644 src/Program.bf create mode 100644 src/SectionFinder.bf diff --git a/BeefProj.toml b/BeefProj.toml index 54c79ce..bcefd67 100644 --- a/BeefProj.toml +++ b/BeefProj.toml @@ -1,4 +1,5 @@ FileVersion = 1 +Dependencies = {corlib = "*", Bofa = "*", LybCL = "*"} [Project] Name = "bdocs" diff --git a/BeefSpace.toml b/BeefSpace.toml index 9abbc14..b7d5b8a 100644 --- a/BeefSpace.toml +++ b/BeefSpace.toml @@ -1,5 +1,5 @@ FileVersion = 1 -Projects = {bdocs = {Path = "."}} +Projects = {bdocs = {Path = "."}, Bofa = {Path = "deps/Bofa"}, LybCL = {Path = "deps/LybCl"}} [Workspace] StartupProject = "bdocs" diff --git a/documentation.md b/documentation.md new file mode 100644 index 0000000..dcfe6a2 --- /dev/null +++ b/documentation.md @@ -0,0 +1,7 @@ +# Classes +- Crawler +- DataStore +## Crawler +Crawls through the input directory in order to read all input files and get all available sections.## DataStore +Store information about the entire setup of the program, +while its running, so that it can be recovered later \ No newline at end of file diff --git a/pkkg b/pkkg index ddf8ea8..b2eb24a 100644 --- a/pkkg +++ b/pkkg @@ -14,4 +14,8 @@ a Dependencies o Bofa l Name Bofa l Url https://code.booklordofthe.dev/Booklordofthedings/Bofa.git + l Tag 1.1.0 + o LybCl + l Name LybCl + l Url https://code.booklordofthe.dev/Booklordofthedings/LybCL.git l Tag 1.0.0 \ No newline at end of file diff --git a/src/Constructs/bdocs_Class.bf b/src/Constructs/bdocs_Class.bf new file mode 100644 index 0000000..944a359 --- /dev/null +++ b/src/Constructs/bdocs_Class.bf @@ -0,0 +1,13 @@ +namespace bdocs.Constructs; + +using System; + +using Bofa; +using Bofa.Serialization; + +[BofaSerialize] +class bdocs_Class +{ + [BofaInclude("n")] public String Name = new .() ~ delete _; + [BofaInclude("d")] public String Description = new .() ~ delete _; +} \ No newline at end of file diff --git a/src/Constructs/bdocs_Method.bf b/src/Constructs/bdocs_Method.bf new file mode 100644 index 0000000..85fbe2c --- /dev/null +++ b/src/Constructs/bdocs_Method.bf @@ -0,0 +1,14 @@ +namespace bdocs.Constructs; + +using System; + +using Bofa; +using Bofa.Serialization; + +[BofaSerialize] +class bdocs_Method +{ + public String Name = null ~ delete _; + public String Description = null ~ delete _; + public String Parent = null ~ delete _; +} \ No newline at end of file diff --git a/src/Constructs/bdocs_Struct.bf b/src/Constructs/bdocs_Struct.bf new file mode 100644 index 0000000..dbbd673 --- /dev/null +++ b/src/Constructs/bdocs_Struct.bf @@ -0,0 +1,13 @@ +namespace bdocs.Constructs; + +using System; + +using Bofa; +using Bofa.Serialization; + +[BofaSerialize] +class bdocs_Struct +{ + public String Name = null ~ delete _; + public String Description = null ~ delete _; +} \ No newline at end of file diff --git a/src/Crawler.bf b/src/Crawler.bf new file mode 100644 index 0000000..e98f51e --- /dev/null +++ b/src/Crawler.bf @@ -0,0 +1,71 @@ +namespace bdocs; + +using System; +using System.IO; +using System.Collections; + +/*$$$c +l n Crawler +t d Crawls through the input directory in order to read all input files and get all available sections. +$$$*/ +class Crawler +{ + public const uint32 FOLDER_LIMIT = 999999; + + private bool _HasErrored = false; + private String _InputDirectory ~ delete _; + private List _Sections = new .() ~ DeleteContainerAndItems!(_); + + public StringView InputDirectory + { + public get => _InputDirectory; + } + + public bool HasErrored + { + public get => _HasErrored; + } + + ///Retrieve all sections containing bdocs data + public Result GetSections(List pBuffer) + { + for(var i in _Sections) + pBuffer.Add(new .(i)); + if(_HasErrored) + return .Err; + return .Ok; + } + + public this(StringView pInputDir) + { + _InputDirectory = new .(pInputDir); + + List toProcess = new .(); + defer delete toProcess; + toProcess.Add(new .(_InputDirectory)); + + uint32 counter = 0; + while(toProcess.Count > 0) + { + counter++; + if(counter >= FOLDER_LIMIT) + return; + + var target = toProcess.PopBack(); + for(var file in Directory.EnumerateFiles(target)) + { + var sections = SectionFinder.GetSections(file.GetFilePath(.. scope .()), .. new .()); + for(var i in sections) + _Sections.Add(i); + delete sections; + + } + + for(var dir in Directory.EnumerateDirectories(target)) + toProcess.Add(dir.GetFileName(.. new .())); + + delete target; + } + } + +} \ No newline at end of file diff --git a/src/DataStore.bf b/src/DataStore.bf new file mode 100644 index 0000000..cbb2f6b --- /dev/null +++ b/src/DataStore.bf @@ -0,0 +1,60 @@ +namespace bdocs; +using bdocs.Constructs; + +using System; +using System.Collections; + +using Bofa; + +/*$$$c +l n DataStore +t d Store information about the entire setup of the program, +- while its running, so that it can be recovered later +$$$*/ +class DataStore +{ + public Dictionary Classes = new .() ~ DeleteDictionaryAndValues!(_); + + /*$$$f + l n Document + t d Process all of the content of the DataStore class into a single document for future use + $$$*/ + public void Document(String pBuffer) + { + pBuffer.Append("# Classes\n"); + for(var i in Classes) + pBuffer.Append(scope $"- {i.key}\n"); + + for(var i in Classes) + { + pBuffer.Append(scope $"## {i.key}\n{i.value.Description}"); + } + } + + public void AddSection(StringView pData) + { + if(pData == "" || !pData.Contains('\n')) + return; + + var type = pData.Split('\n').GetNext().Value; + var data = pData.Split('\n')..GetNext().Remnant; + + List errors = scope .(); + var res = BofaParser.Parse(data,.. new .(), errors); + defer {DeleteDictionaryAndValues!(res);} + + switch(type) + { + case "c": + bdocs_Class n = new .(); + if(!Bofa.Deserialize(ref n, res)) + { + delete n; + return; + } + Classes.Add(n.Name, n); + default: + return; + } + } +} \ No newline at end of file diff --git a/src/Program.bf b/src/Program.bf new file mode 100644 index 0000000..13b1063 --- /dev/null +++ b/src/Program.bf @@ -0,0 +1,47 @@ +namespace bdocs; + +using LybCL; + +using System; +using System.IO; +using System.Collections; + +class Program +{ + public static void Main(String[] args) + { + + LybCl cmd = scope .(args); + String inputDir = scope .(); + String outputDir = scope .(); + +#if DEBUG + Console.WriteLine("WARNING: Debug mode. Not for distribution"); + inputDir.Append("src/"); + outputDir.Append("."); +#endif + inputDir.Append(cmd.GetParameter("input", "Input", "I", "i", "in", "In")); + outputDir.Append(cmd.GetParameter("output", "Output", "out", "Out", "o", "O")); + + if(!Directory.Exists(inputDir)) + Console.WriteLine("Target input directory does not exist"); + + Crawler c = new .(inputDir); + + DataStore d = new .(); + + for(var i in c.GetSections(.. scope .())) + { + d.AddSection(i); + delete i; + } + delete c; + + File.WriteAllText( + scope $"{outputDir}/documentation.md", + d.Document(.. scope .()) + ).IgnoreError(); + + delete d; + } +} \ No newline at end of file diff --git a/src/SectionFinder.bf b/src/SectionFinder.bf new file mode 100644 index 0000000..bfe7ac1 --- /dev/null +++ b/src/SectionFinder.bf @@ -0,0 +1,57 @@ +namespace bdocs; + +using System; +using System.IO; +using System.Collections; + +class SectionFinder +{ + public static void GetSections(StringView pPath, List pSections) + { + String fileData = scope .(); + if(File.ReadAllText(pPath, fileData) case .Err) + return; + + bool insideSection = false; + int depth = 0; + String sectionData = null; + + for(var line in fileData.Split('\n')) + { + if((scope String(line))..TrimStart().StartsWith("/*$$$")) + { + if(insideSection) + continue; + else + { + insideSection = true; + sectionData = new .(); + sectionData.Append(scope $"{line.Split("/*$$$")..GetNext().Remnant}\n"); + + while(line[depth].IsWhiteSpace) + depth++; + } + } + else if((scope String(line))..TrimStart().StartsWith("$$$*/")) + { + if(insideSection) + { + insideSection = false; + depth = 0; + sectionData.RemoveFromEnd(1); + pSections.Add(sectionData); + } + } + else if(insideSection) + { + sectionData.Append(scope $"{line.Substring(depth)}\n"); + } + } + if(insideSection) + { + insideSection = false; + sectionData.RemoveFromEnd(1); + pSections.Add(sectionData); + } + } +} \ No newline at end of file