Skip to content

Commit

Permalink
Tweak docgen - support nested comments
Browse files Browse the repository at this point in the history
  • Loading branch information
slackydev committed Dec 28, 2024
1 parent 2066a17 commit cb32001
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
36 changes: 32 additions & 4 deletions DocGen/docgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@
SRC_DIR = '../Source/script/imports/'
BUILD_DIR = 'source/api/'

# between that handles nested comments, regex did not handle this!
def between(str, start, stop):
result = []
init = 0
while True:
first = str.find(start, init)
if first == -1: break

first += len(start)
last = str.find(stop, first)

if last == -1: break

nested_start = str.find(start, first)
while nested_start != -1 and nested_start < last:
last = str.find(stop, last + 1)
if last == -1: break
nested_start = str.find(start, nested_start + len(start))

result.append(str[first:last])
init = last + len(stop)
return result


# remove old build files, all but index
for file in glob.glob(f"{BUILD_DIR}*.md"):
os.remove(file)
Expand All @@ -17,20 +41,24 @@
comments = []
for source in glob.glob(f"{SRC_DIR}*.pas"):
with open(source, 'r') as f:
comments.extend(re.findall(r'\(\*(.*?)\*\)', f.read(), re.DOTALL))

comments.extend(between(f.read(), '(*', '*)'))


# write comments, changing the file when a header is found
# header being a === line rather than ---
currentfile = None
for comment in comments:
comment = comment.strip()
if (comment.splitlines()[1][0] == '='):
lines = comment.splitlines();

if (len(lines[1]) > 0) and (lines[1][0] == '='):
if currentfile:
currentfile.close()
currentfile = open(f"{BUILD_DIR}/{comment.splitlines()[0]}.md", 'a')
currentfile = open(f"{BUILD_DIR}/{lines[0]}.md", 'a')
currentfile.write(comment)
else:
currentfile.write('\n\n' + '-----' + '\n\n' + comment)

if currentfile:
currentfile.close()

Expand Down
6 changes: 5 additions & 1 deletion Source/simba.container_kdtree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,12 @@ function TKDTree.WeightedKNearestClassify(Vector: TSingleArray; K: Int32): Int32
Implements an efficient n-dimensional spatial clustering algorithm using a KD-Tree.
It supports label-based filtering to cluster points within specific categories.
Best case: O(n)
Average Time Complexity: O(n log n)
Worst Case Time Complexity: O(n log n)
Worst Case Time Complexity: O(n^2) in theory .. Maybe still just O(n log n) or thereabout.
Best case of O(n) can happen when we prune all branches in the first pass,
this requires a radii that covers all points from anywhere or luck point selection.
TODO: Add a version that returns T2DIntegerArray where each version represents
an index in KDTree.Data.
Expand Down

0 comments on commit cb32001

Please sign in to comment.