@@ -4,22 +4,26 @@ local defaultPath = package.path
44if fs then
55 local args = {... }
66 local docsPath = fs .getDir (args [2 ])
7- local format = " path;/path/ ?.lua;/ path/?/init.lua;"
7+ local format = " path/ ?.lua;path/?/init.lua;"
88 local main = format :gsub (" path" , docsPath )
99 package.path = main .. " rom/?;" .. defaultPath
10+ else
11+ local format = " path/?.lua;path/?/init.lua;"
12+ local main = format :gsub (" path" , " tools/BasaltDoc" )
13+ package.path = main .. " ;" .. defaultPath
1014end
1115
12- local ok1 , classParser = pcall ( require , " parsers.classParser" )
16+ local classParser = require ( " parsers.classParser" )
1317
14- local ok2 , functionParser = pcall ( require , " parsers.functionParser" )
18+ local functionParser = require ( " parsers.functionParser" )
1519
16- local ok3 , propertyParser = pcall ( require , " parsers.propertyParser" )
20+ local propertyParser = require ( " parsers.propertyParser" )
1721
18- local ok4 , eventParser = pcall ( require , " parsers.eventParser" )
22+ local eventParser = require ( " parsers.eventParser" )
1923
20- local ok6 , globalParser = pcall ( require , " parsers.globalParser" )
24+ local globalParser = require ( " parsers.globalParser" )
2125
22- local ok5 , markdownGenerator = pcall ( require , " utils.markdownGenerator" )
26+ local markdownGenerator = require ( " utils.markdownGenerator" )
2327
2428BasaltDoc .annotationHandlers = {}
2529
@@ -141,11 +145,11 @@ BasaltDoc.registerAnnotation("@globalDescription", function(target, args)
141145 end
142146end )
143147
144- if ok1 then classParser .setHandlers (BasaltDoc .annotationHandlers ) end
145- if ok2 then functionParser .setHandlers (BasaltDoc .annotationHandlers ) end
146- if ok3 then propertyParser .setHandlers (BasaltDoc .annotationHandlers ) end
147- if ok4 then eventParser .setHandlers (BasaltDoc .annotationHandlers ) end
148- if ok6 then globalParser .setHandlers (BasaltDoc .annotationHandlers ) end
148+ if classParser then classParser .setHandlers (BasaltDoc .annotationHandlers ) end
149+ if functionParser then functionParser .setHandlers (BasaltDoc .annotationHandlers ) end
150+ if propertyParser then propertyParser .setHandlers (BasaltDoc .annotationHandlers ) end
151+ if eventParser then eventParser .setHandlers (BasaltDoc .annotationHandlers ) end
152+ if globalParser then globalParser .setHandlers (BasaltDoc .annotationHandlers ) end
149153
150154---- ------------------------------------------------------------
151155-- Main Parser
@@ -174,7 +178,7 @@ function BasaltDoc.parse(content)
174178 if i <= # rawLines and rawLines [i ]:match (" %]%]" ) then
175179 i = i + 1
176180 end
177- if # globalAnnotations > 0 and ok6 then
181+ if # globalAnnotations > 0 and globalParser then
178182 local global = globalParser .parse (globalAnnotations , table.concat (globalAnnotations , " \n " ))
179183 ast .global = global
180184 end
@@ -211,25 +215,25 @@ function BasaltDoc.parse(content)
211215 elseif # annotationBuffer > 0 then
212216 local nextLine = lines [i ]
213217 local skip = false
214- if nextLine and nextLine :match (" ^function" ) and currentClass and ok2 then
218+ if nextLine and nextLine :match (" ^function" ) and currentClass and functionParser then
215219 local fn = functionParser .parse (annotationBuffer , nextLine )
216220 if fn then
217221 table.insert (currentClass .functions , fn )
218222 end
219223 skip = true
220224 elseif firstTag then
221- if firstTag == " @class" and ok1 then
225+ if firstTag == " @class" and classParser then
222226 local class = classParser .parse (annotationBuffer , table.concat (annotationBuffer , " \n " ))
223227 if class and not class .skip then
224228 table.insert (ast .classes , class )
225229 currentClass = class
226230 end
227- elseif firstTag == " @property" and currentClass and ok3 then
231+ elseif firstTag == " @property" and currentClass and propertyParser then
228232 local prop = propertyParser .parse (annotationBuffer , table.concat (annotationBuffer , " \n " ))
229233 if prop then
230234 table.insert (currentClass .properties , prop )
231235 end
232- elseif firstTag == " @event" and currentClass and ok4 then
236+ elseif firstTag == " @event" and currentClass and eventParser then
233237 local evt = eventParser .parse (annotationBuffer , table.concat (annotationBuffer , " \n " ))
234238 if evt then
235239 table.insert (currentClass .events , evt )
@@ -246,7 +250,7 @@ function BasaltDoc.parse(content)
246250 end
247251
248252 if # annotationBuffer > 0 and firstTag then
249- if firstTag == " @class" and ok1 then
253+ if firstTag == " @class" and classParser then
250254 local class = classParser .parse (annotationBuffer , table.concat (annotationBuffer , " \n " ))
251255 if class and not class .skip then
252256 table.insert (ast .classes , class )
@@ -259,7 +263,7 @@ function BasaltDoc.parse(content)
259263end
260264
261265function BasaltDoc .generateMarkdown (ast )
262- if ok5 then
266+ if markdownGenerator then
263267 local result = markdownGenerator .generate (ast )
264268 return result
265269 else
0 commit comments