first documentation results
This commit is contained in:
parent
3b71f22ece
commit
7c360a1dd8
11 changed files with 288 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
FileVersion = 1
|
||||
Dependencies = {corlib = "*", Bofa = "*", LybCL = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "bdocs"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
FileVersion = 1
|
||||
Projects = {bdocs = {Path = "."}}
|
||||
Projects = {bdocs = {Path = "."}, Bofa = {Path = "deps/Bofa"}, LybCL = {Path = "deps/LybCl"}}
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "bdocs"
|
||||
|
|
7
documentation.md
Normal file
7
documentation.md
Normal file
|
@ -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
|
4
pkkg
4
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
|
13
src/Constructs/bdocs_Class.bf
Normal file
13
src/Constructs/bdocs_Class.bf
Normal file
|
@ -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 _;
|
||||
}
|
14
src/Constructs/bdocs_Method.bf
Normal file
14
src/Constructs/bdocs_Method.bf
Normal file
|
@ -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 _;
|
||||
}
|
13
src/Constructs/bdocs_Struct.bf
Normal file
13
src/Constructs/bdocs_Struct.bf
Normal file
|
@ -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 _;
|
||||
}
|
71
src/Crawler.bf
Normal file
71
src/Crawler.bf
Normal file
|
@ -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<String> _Sections = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
public StringView InputDirectory
|
||||
{
|
||||
public get => _InputDirectory;
|
||||
}
|
||||
|
||||
public bool HasErrored
|
||||
{
|
||||
public get => _HasErrored;
|
||||
}
|
||||
|
||||
///Retrieve all sections containing bdocs data
|
||||
public Result<void> GetSections(List<String> pBuffer)
|
||||
{
|
||||
for(var i in _Sections)
|
||||
pBuffer.Add(new .(i));
|
||||
if(_HasErrored)
|
||||
return .Err;
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public this(StringView pInputDir)
|
||||
{
|
||||
_InputDirectory = new .(pInputDir);
|
||||
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
60
src/DataStore.bf
Normal file
60
src/DataStore.bf
Normal file
|
@ -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<StringView, bdocs_Class> 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<int64> errors = scope .();
|
||||
var res = BofaParser.Parse(data,.. new .(), errors);
|
||||
defer {DeleteDictionaryAndValues!(res);}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case "c":
|
||||
bdocs_Class n = new .();
|
||||
if(!Bofa.Deserialize<bdocs_Class>(ref n, res))
|
||||
{
|
||||
delete n;
|
||||
return;
|
||||
}
|
||||
Classes.Add(n.Name, n);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
47
src/Program.bf
Normal file
47
src/Program.bf
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
57
src/SectionFinder.bf
Normal file
57
src/SectionFinder.bf
Normal file
|
@ -0,0 +1,57 @@
|
|||
namespace bdocs;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
|
||||
class SectionFinder
|
||||
{
|
||||
public static void GetSections(StringView pPath, List<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue