Update to the documentation generation process

Include a doc update too.
This commit is contained in:
Grey-Echo
2017-05-03 16:35:34 +02:00
parent 9ca007ccf4
commit 7b2f0fda9c
25 changed files with 2695 additions and 174 deletions

View File

@@ -0,0 +1,10 @@
:: Generate the Markdown doc
"./bin/SlateDocGenerator2.exe" "../../../MOOSE/Moose Development/Moose" ../../../slate/source
:: Do some cleanup
del /s /q "TreeHierarchySorted.csv"
del /s /q "FuctionList.txt"
rmdir /s /q "./bin/TEMP"
:: Copy the Images that go with the documentation
robocopy ../../docs/Presentations ../../../slate/source/includes/Pictures /MIR /NJH /NJS

View File

@@ -0,0 +1,35 @@
@K=function, @M=Task_A2G, @N=onafterRouteToRendezVous, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua, @C=5129,
@K=function, @M=Task_A2G, @N=OnAfterArriveAtRendezVous, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua, @C=5789,
@K=function, @M=Task_A2G, @N=onafterEngage, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua, @C=6186,
@K=function, @M=Task_A2G, @N=onafterRouteToTarget, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua, @C=6508,
@K=function, @M=Task_A2G, @N=onafterRouteToTargets, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua, @C=7380,
@K=function, @M=Task_Cargo, @N=onenterWaitingForCommand, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=10431,
@K=function, @M=Task_Cargo, @N=OnLeaveWaitingForCommand, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=12652,
@K=function, @M=Task_Cargo, @N=onafterRouteToPickup, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=13428,
@K=function, @M=Task_Cargo, @N=onafterArriveAtPickup, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=13882,
@K=function, @M=Task_Cargo, @N=onafterRouteToDeploy, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=14310,
@K=function, @M=Task_Cargo, @N=onafterArriveAtDeploy, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=14757,
@K=function, @M=Task_Cargo, @N=onafterLand, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=15187,
@K=function, @M=Task_Cargo, @N=onafterLanded, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=16069,
@K=function, @M=Task_Cargo, @N=onafterPrepareBoarding, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=16762,
@K=function, @M=Task_Cargo, @N=onafterBoard, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=17166,
@K=function, @M=Task_Cargo, @N=onafterBoarded, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=18074,
@K=function, @M=Task_Cargo, @N=onafterPrepareUnBoarding, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=18704,
@K=function, @M=Task_Cargo, @N=onafterUnBoard, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=19134,
@K=function, @M=Task_Cargo, @N=onafterUnBoarded, @P=Fsm, @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua, @C=19788,
@K=function, @M=Designate, @N=OnBeforeLaseOn, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=12232,
@K=function, @M=Designate, @N=OnAfterLaseOn, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=12480,
@K=function, @M=Designate, @N=LaseOn, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=12701,
@K=function, @M=Designate, @N=__LaseOn, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=12824,
@K=function, @M=Designate, @N=OnBeforeLaseOff, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=13114,
@K=function, @M=Designate, @N=OnAfterLaseOff, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=13364,
@K=function, @M=Designate, @N=LaseOff, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=13587,
@K=function, @M=Designate, @N=__LaseOff, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=13712,
@K=function, @M=Designate, @N=OnBeforeSmoke, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=13944,
@K=function, @M=Designate, @N=OnAfterSmoke, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=14190,
@K=function, @M=Designate, @N=Smoke, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=14409,
@K=function, @M=Designate, @N=__Smoke, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=14530,
@K=function, @M=Designate, @N=OnBeforeStatus, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=15628,
@K=function, @M=Designate, @N=OnAfterStatus, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=15876,
@K=function, @M=Designate, @N=Status, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=16097,
@K=function, @M=Designate, @N=__Status, @P=DESIGNATE , @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua, @C=16220,
1 @K=function @M=Task_A2G @N=onafterRouteToRendezVous @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua @C=5129
2 @K=function @M=Task_A2G @N=OnAfterArriveAtRendezVous @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua @C=5789
3 @K=function @M=Task_A2G @N=onafterEngage @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua @C=6186
4 @K=function @M=Task_A2G @N=onafterRouteToTarget @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua @C=6508
5 @K=function @M=Task_A2G @N=onafterRouteToTargets @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_A2G.lua @C=7380
6 @K=function @M=Task_Cargo @N=onenterWaitingForCommand @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=10431
7 @K=function @M=Task_Cargo @N=OnLeaveWaitingForCommand @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=12652
8 @K=function @M=Task_Cargo @N=onafterRouteToPickup @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=13428
9 @K=function @M=Task_Cargo @N=onafterArriveAtPickup @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=13882
10 @K=function @M=Task_Cargo @N=onafterRouteToDeploy @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=14310
11 @K=function @M=Task_Cargo @N=onafterArriveAtDeploy @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=14757
12 @K=function @M=Task_Cargo @N=onafterLand @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=15187
13 @K=function @M=Task_Cargo @N=onafterLanded @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=16069
14 @K=function @M=Task_Cargo @N=onafterPrepareBoarding @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=16762
15 @K=function @M=Task_Cargo @N=onafterBoard @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=17166
16 @K=function @M=Task_Cargo @N=onafterBoarded @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=18074
17 @K=function @M=Task_Cargo @N=onafterPrepareUnBoarding @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=18704
18 @K=function @M=Task_Cargo @N=onafterUnBoard @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=19134
19 @K=function @M=Task_Cargo @N=onafterUnBoarded @P=Fsm @F=../../../MOOSE/Moose Development/Moose\Tasking\Task_CARGO.lua @C=19788
20 @K=function @M=Designate @N=OnBeforeLaseOn @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=12232
21 @K=function @M=Designate @N=OnAfterLaseOn @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=12480
22 @K=function @M=Designate @N=LaseOn @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=12701
23 @K=function @M=Designate @N=__LaseOn @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=12824
24 @K=function @M=Designate @N=OnBeforeLaseOff @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=13114
25 @K=function @M=Designate @N=OnAfterLaseOff @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=13364
26 @K=function @M=Designate @N=LaseOff @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=13587
27 @K=function @M=Designate @N=__LaseOff @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=13712
28 @K=function @M=Designate @N=OnBeforeSmoke @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=13944
29 @K=function @M=Designate @N=OnAfterSmoke @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=14190
30 @K=function @M=Designate @N=Smoke @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=14409
31 @K=function @M=Designate @N=__Smoke @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=14530
32 @K=function @M=Designate @N=OnBeforeStatus @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=15628
33 @K=function @M=Designate @N=OnAfterStatus @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=15876
34 @K=function @M=Designate @N=Status @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=16097
35 @K=function @M=Designate @N=__Status @P=DESIGNATE @F=../../../MOOSE/Moose Development/Moose\Functional\Designate.lua @C=16220

View File

@@ -0,0 +1,174 @@
; This file only constains function related to storing the hierarchy in a tree-like tructure
Func AddNode($Kind, $Module ,$Node, $Parent, $File, $CarretPos)
FileSetPos($DataFile, 0, $FILE_END)
If $Parent == "" And $Kind == "type" Then
$Parent = "ROOT"
ElseIf $Kind == "module" Then
$Module = " "
$Parent = " "
EndIf
FileWrite($DataFile, "@K="&$Kind&", @M="&$Module&", @N="&$Node&", @P="&$Parent&", @F="&$File&", @C="&$CarretPos&","&@CRLF)
EndFunc
; Search node by name and returns one data
Func GetData($Node, $Data)
FileSetPos($DataFile, 0, $FILE_BEGIN)
Local $CurrentLine = ""
Local $CurrentData
Local $RegexResult
Local $Regex
Switch $Data
Case "kind"
$Regex = "\@K=(.+?),"
Case "parent"
$Regex = "\@P=(.+?),"
Case "file"
$Regex = "\@F=(.+?),"
Case "carretpos"
$Regex = "\@C=(.+?),"
EndSwitch
FileSetPos($DataFile, 0, $FILE_BEGIN)
Do
$CurrentLine = FileReadLine($DataFile)
If @error == -1 Then
Return ""
ExitLoop
EndIf
$CurrentData = StringRegExp($CurrentLine, "\@N=(.+?),", $STR_REGEXPARRAYMATCH)
Until $Node == $CurrentData[0]
$CurrentData = StringRegExp($CurrentLine, $Regex, $STR_REGEXPARRAYMATCH)
Return $CurrentData[0]
EndFunc
; Returns an array of parent nodes, up to the root, starting with the root
Func GetParents($Node)
Local $CurrentParent = $Node
Local $ParentsArray[0]
Local $NbOfParents = 1
While $CurrentParent <> "ROOT"
ReDim $ParentsArray[$NbOfParents]
$ParentsArray[$NbOfParents-1] = $CurrentParent
$CurrentParent = GetData($CurrentParent, "parent")
If $CurrentParent == "" Then
FileWrite($Log, "ERROR : Couldn't find "&$ParentsArray[$NbOfParents-1]&"'s parent !")
$CurrentParent = "ERROR !"
ReDim $ParentsArray[$NbOfParents]
$ParentsArray[$NbOfParents-1] = $CurrentParent
ExitLoop
EndIf
$NbOfParents += 1
WEnd
_ArrayReverse($ParentsArray)
_ArrayDelete($ParentsArray, $NbOfParents)
Return $ParentsArray
EndFunc
Func DataSort()
Local $SortedDataFile = FileOpen(@ScriptDir & "\TreeHierarchySorted.csv", $FO_OVERWRITE)
Local $Line = ""
Local $LineNb = 1
Local $RegexResults
Local $CurrentModule
Local $CurrentType
FileSetPos($DataFile, 0, $FILE_BEGIN)
While True
$Line = FileReadLine($DataFile)
If @error then ExitLoop
$RegexResults = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == "module" Then
ConsoleWrite(".")
$RegexResults = StringRegExp($Line, "\@N=(.+?),", $STR_REGEXPARRAYMATCH)
$CurrentModule = $RegexResults[0]
FileWriteLine($SortedDataFile, $Line)
FileClose($DataFile)
_FileWriteToLine(@ScriptDir & "\TreeHierarchy.csv", $LineNb, "", True)
$DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 1)
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 1
While True
$Line = FileReadLine($DataFile)
If @error then ExitLoop
$RegexResults = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == "type" Then
$RegexResults = StringRegExp($Line, "\@M=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == $CurrentModule Then
$RegexResults = StringRegExp($Line, "\@N=(.+?),", $STR_REGEXPARRAYMATCH)
$CurrentType = $RegexResults[0]
FileWriteLine($SortedDataFile, $Line)
FileClose($DataFile)
_FileWriteToLine(@ScriptDir & "\TreeHierarchy.csv", $LineNb, "", True)
$DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 1)
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 1
While True
$Line = FileReadLine($DataFile)
If @error then ExitLoop
$RegexResults = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == "function" Then
$RegexResults = StringRegExp($Line, "\@P=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResults[0] == $CurrentType Then
FileWriteLine($SortedDataFile, $Line)
FileClose($DataFile)
_FileWriteToLine(@ScriptDir & "\TreeHierarchy.csv", $LineNb, "", True)
$DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 1)
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 0
EndIf
EndIf
$LineNb += 1
WEnd
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 0
EndIf
EndIf
$LineNb += 1
WEnd
FileSetPos($DataFile, 0, $FILE_BEGIN)
$LineNb = 0
EndIf
$LineNb += 1
Wend
If FileGetSize(@ScriptDir & "\TreeHierarchy.csv") <> 0 Then
FileWrite($Log, "ERROR : Some items couldn't be sorted. Verify them in the file TreeHierarchy.csv"&@CRLF)
ConsoleWrite(@CRLF&"INFO : Some items couldn't be sorted. Verify them in the file TreeHierarchy.csv"&@CRLF)
EndIf
FileClose($DataFile)
$DataFile = $SortedDataFile
EndFunc
Func FindInFunctionList($String)
Local $Line = ""
Local $TempStringArray
FileSetPos($FunctionList, 0, $FILE_BEGIN)
;FileWrite($Log, 'Trying to find the function prototype for : ' & $String & @CRLF)
While 1
$Line = FileReadLine($FunctionList)
If @error = -1 Then
SetError(0)
FileWrite($Log, "ERROR : Couldn't find " & $String & " in file. Does this method exitsts ?" & @CRLF)
Return $String
EndIf
If StringInStr($Line, $String) Then
$TempStringArray = StringSplit($Line, "-")
$Line = "[" & $TempStringArray[1] & ":" & $TempStringArray[2] & "()]" & '(#' & StringLower($Line) & ')'
Return $Line
EndIf
WEnd
EndFunc

View File

@@ -0,0 +1,460 @@
; This file include every function strictly related to the parsing of data in .lua files
; Get the first comment block after $CarretPos
; We will also grab function declaration if possible/applicable
; The return is a Array : CarretPosition|BlockContent|Declaration|CarretPositionStart
Func ReadNextBlock($File, $CarretPos)
local $CommentBlock = "" ; This is where we'll store the comment block
local $Declaration = "" ; This is the next line after the comment block : usually the declaration statement
local $CurrentLine = ""
local $CurrentCarretPos = 0
local $IsCommentBlock = False
local $RegExResult
local $RegexPos
; Start reading from $CarretPos
FileSetPos($File, $CarretPos, $FILE_BEGIN)
; Read till we find a comment block
Do
$CurrentLine = FileReadLine($File)
If @error Then ; We probably reached the eof
Local $ReturnArray[3] = [$CurrentCarretPos, "", ""]
Return $ReturnArray
ElseIf StringInStr($CurrentLine, "---") Then
$IsCommentBlock = True
EndIf
Until $IsCommentBlock
Local $CarretPosStart = FileGetPos($File) - StringLen($CurrentLine) - 2
; Add the first line to our comment block
$RegExResult = StringRegExp($CurrentLine, "---(.*)", $STR_REGEXPARRAYMATCH)
If Not @error Then ; The first line of the comment could be empty !
$CommentBlock &= $RegExResult[0]&@CRLF
EndIf
; Read the comment block
Do
$CurrentCarretPos = FileGetPos($File)
$CurrentLine = FileReadLine($File)
If StringInStr($CurrentLine, "--") Then ; If we can't find any "--" in the line, then it's not the comment block anymore
$RegExResult = StringRegExp($CurrentLine, "--(.*)", $STR_REGEXPARRAYMATCH)
If Not @error Then; The line of the comment could be empty !
$CommentBlock &= $RegExResult[0]&@CRLF
EndIf
Else
$IsCommentBlock = False
EndIf
Until Not $IsCommentBlock
; Ok, so now this is strange. If the comment block is class', we're going to have to check the
; next comment block. If this next comment block contains a field, that is the same name as the class, then this
; new comment block contains the whole informtion for the class. This is very shitty, but it's a workaround to
; make intellisense show classes info while programing
If ParseForOneTag($CommentBlock, "@type") Then
Local $CommentBlock2 = ""
Do
$CurrentLine = FileReadLine($File)
If @error Then
Local $ReturnArray[3] = [$CurrentCarretPos, "", ""]
Return $ReturnArray
ElseIf StringInStr($CurrentLine, "---") Then
$IsCommentBlock = True
EndIf
Until $IsCommentBlock
$RegExResult = StringRegExp($CurrentLine, "---(.*)", $STR_REGEXPARRAYMATCH)
If Not @error Then
$CommentBlock2 &= $RegExResult[0]&@CRLF
EndIf
; Yep, the next comment is the description of the class, let's read on !
If StringInStr($CurrentLine, ParseForOneTag($CommentBlock, "@type")) And StringInStr($CurrentLine, "extend") Then
Do
$CurrentLine = FileReadLine($File)
If StringInStr($CurrentLine, "--") Then
$RegExResult = StringRegExp($CurrentLine, "--(.*)", $STR_REGEXPARRAYMATCH)
If Not @error Then
$CommentBlock2 &= $RegExResult[0]&@CRLF
EndIf
Else
$IsCommentBlock = False
EndIf
Until Not $IsCommentBlock
; remove the line(s) with "@field" in the comment block. They are only needed for the intellisense hack
While 1
$RegexResult = StringRegExp($CommentBlock2, "(.*)@field(.*)", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$CommentBlock2 = StringRegExpReplace($CommentBlock2, "(.*)@field(.*)", "", 1)
WEnd
; We also don't need the first line of the first comment block anymore...
; $CommentBlock = StringRegExpReplace($CommentBlock, "(.*)", "", 1)
; append the description at the start of the comment block
$CommentBlock = $CommentBlock2&$CommentBlock
EndIf
; We also need to check if the type is a list or a map. If so, the comment block does not describe a class, but a simple list / map.
; It will have the formatting of a class, though, because it's closer closer to the actual code, even though it is highly confusing.
; But it will only have 1 field : the list or map.
If StringInStr($CommentBlock, "@list") Then
$RegExResult = StringRegExp($CommentBlock, "@list\h<(.*?)>\h(.*)", $STR_REGEXPARRAYMATCH)
if not @error Then
$CommentBlock &= "@field #table["&$RegExResult[0]&"] "&$RegExResult[1]
EndIf
EndIf
; TODO : Add support for @map the same way...
EndIf
; We'll take the next line, as it might be the declaration statement
$Declaration = $CurrentLine
; let's do some cleanup
$CommentBlock = StringRegExpReplace($CommentBlock, "(?m)^\h+", "") ;remove leading whitespaces
$CommentBlock = StringRegExpReplace($CommentBlock, "(?m)\h+$", "") ;remove trailing whitespaces
$CommentBlock = StringRegExpReplace($CommentBlock, "(?m)^[#]+", "##### ")
$CommentBlock = StringRegExpReplace($CommentBlock, "(?m)^\h+", "") ;remove leading whitespaces again now that we removed the "#"s
$CommentBlock = StringRegExpReplace($CommentBlock, "(?m)-{3,}", "") ;remove sequences of at least 3 "-" which will mess up markdown
$CommentBlock = StringRegExpReplace($CommentBlock, "(?m)={3,}", "") ; remove sequences of at least 3 "=" which will mess up markdown
Local $ReturnArray[4] = [$CurrentCarretPos, $CommentBlock, $Declaration, $CarretPosStart]
Return $ReturnArray
EndFunc
; Parses the block and returns the data for one tag
; don't use it to find the function tag !
Func ParseForOneTag($Block, $Tag)
Local $i = 1
Local $DataArray[1]
Local $RegexResult[1]
Local $RegexPos = 1
Local $Regex
; If we look for @usage, then it's a multiline data, the regex is different
If $Tag == "@usage" Then
$Regex = "(?s)@usage(.*)"
$RegexResult = StringRegExp($Block, $Regex, $STR_REGEXPARRAYMATCH, $RegexPos)
Else
$Regex = $Tag&"\h(.*)\s"
$RegexResult = StringRegExp($Block, $Regex, $STR_REGEXPARRAYMATCH, $RegexPos)
Endif
If @error Then
Return ""
Else
Return $RegexResult[0]
EndIf
EndFunc ;==>ReadOneTag
; Parses the block and returns the data for multiple tags in an array
; Don't use it for @param !
Func ParseForTags($Block, $Tag)
Local $i = 1
Local $DataArray[1]
Local $RegexResult[1]
Local $RegexPos = 1
Local $Regex = $Tag&"(?m)\h([^\s]*)(?:\h)?([^\s]*)?(?:\h)?(.*)?$"
; For each tag
While True
$RegexResult = StringRegExp($Block, $Regex, $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If $RegexPos == 0 Then ; We couldn't find any tag
If Not $DataArray[0] Then
Return ""
Else
Return $DataArray
EndIf
EndIf
; Add the tag to the array.The array looks like this : type1|param1|description1|type2...
ReDim $DataArray[$i * 3]
$DataArray[($i * 3) - 3] = $RegexResult[0]
If $RegexResult[1] == "" Then
$DataArray[($i * 3) - 2] = "self" ; if the first param doesn't have a name, then it's self
Else
$DataArray[($i * 3) - 2] = $RegexResult[1]
EndIf
$DataArray[($i * 3) - 1] = $RegexResult[2]
$i += 1
WEnd
EndFunc
; Parses both the comment block and the declaration to find the function name and it's type
; Compares both of them if possible, but will always return the one in the comment block if possible
Func ParseFunctionName($CommentBlock, $Declaration)
local $RegExResult
local $FunctionNameFromDec
local $FunctionNameFromComment
local $ReturnArray[2]
; Parse for function name in both the comment block and the desclaration
$RegExResult = StringRegExp($CommentBlock, "\@function\h(?:(\[.*\]\h))?(.*)", $STR_REGEXPARRAYMATCH)
If Not @error Then
$FunctionNameFromComment = $RegExResult[1]
EndIf
$RegExResult = StringRegExp($Declaration, "function\h(?:.*\:)?(.*)\(.*\)", $STR_REGEXPARRAYMATCH)
If Not @error Then
$FunctionNameFromDec = $RegExResult[0]
EndIf
; compare them to each other
If $FunctionNameFromComment Then
If $FunctionNameFromDec <> $FunctionNameFromComment Then
FileWrite($Log,"CAUTION : The commented function doesn't match its declaration : "&$FunctionNameFromComment& " -> "&$Declaration&@CRLF)
EndIf
$ReturnArray[0] = $FunctionNameFromComment
ElseIf $FunctionNameFromDec Then
;FileWrite($Log, "CAUTION: No data matching @function found in block, inferring the function name from its declaration : "& $FunctionNameFromDec & @CRLF)
$ReturnArray[0] = $FunctionNameFromDec
Else
$ReturnArray[0] = ""
$ReturnArray[1] = ""
return $ReturnArray
EndIf
;parses for function type in both the comment block and the desclaration
local $TypeFromComment
local $TypeFromDec
$RegExResult = StringRegExp($Declaration, "function\h(.*):", $STR_REGEXPARRAYMATCH)
If Not @error Then
$TypeFromDec = $RegExResult[0]
EndIf
$RegExResult = StringRegExp($CommentBlock, "function\h\[parent=#(.*)\]", $STR_REGEXPARRAYMATCH)
If Not @error Then
$TypeFromComment = $RegExResult[0]
EndIf
; compare them to each other
If $TypeFromComment Then
If $TypeFromDec <> $TypeFromComment Then
FileWrite($Log,"CAUTION : The commented function type doesn't match its declaration : "&$TypeFromComment& " -> "&$Declaration&@CRLF)
EndIf
$ReturnArray[1] = $TypeFromComment
ElseIf $TypeFromDec Then
;FileWrite($Log, "CAUTION: No function type found in block, inferring the function type from its declaration : "& $TypeFromDec & @CRLF)
$ReturnArray[1] = $TypeFromDec
Else
$ReturnArray[0] = ""
$ReturnArray[1] = ""
return $ReturnArray
EndIf
Return $ReturnArray
EndFunc
; Specifically designed to parse for @param tags
; will verify the comment by matching with the declaration (theoretically, I'm pretty sure it's bugged)
Func ParseParams($CommentBlock, $Declaration)
Local $ParamsFromComment = ParseForTags($CommentBlock, "@param")
Local $RegExResult
Local $RegexPos = StringInStr($Declaration, "(")
Local $ParamsFromDec[0]
Local $NbParam = 0
If StringInStr($Declaration, ":") Then
$NbParam = 1
ReDim $ParamsFromDec[1]
$ParamsFromDec[0] = "self"
EndIf
; extract params from function decaration
While True
$RegExResult = StringRegExp($Declaration, "([^,\(\)\h]+)", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NbParam += 1
Redim $ParamsFromDec[$NbParam]
$ParamsFromDec[$NbParam-1] = $RegExResult[0]
WEnd
; compare these parameters with those found in the comment block
If UBound($ParamsFromComment) <> UBound($ParamsFromDec)*3 Then
FileWrite($Log, "CAUTION: The number of parameters don't match between the comment block and declaration "& @CRLF)
Else
For $i=0 To $NbParam-1
If $ParamsFromDec[$i] <> $ParamsFromComment[($i*3)+1] Then
FileWrite($Log, "CAUTION: Parameters missmatch between the comment block and declaration "& @CRLF)
FileWrite($Log, $ParamsFromComment[($i*3)+1]& " -> " & $ParamsFromDec[$i]&@CRLF)
ExitLoop
EndIf
Next
EndIf
Return $ParamsFromComment
EndFunc
; This does 3 things :
; - Replace the hyperlinks with new ones
; - change the stuff starting with # (#nil -> <u>Nil</u>)
; - Replace pictures paths
Func ReplaceHyperlinks($TempFile)
Local $StringFile = ""
Local $RegexResult
Local $RegexPos = 1
Local $NewURL = ""
Local $i = 0
FileSetPos($TempFile, 0, $FILE_BEGIN)
$StringFile = FileRead($TempFile)
; Replace HyperLinks Using Regexs
; ---------------------------------------------------------
While 1 ; @{File.Module}
$RegexResult = StringRegExp($StringFile, "\@{([A-Z][^\.#}]+)\.([^\.#}]+)}", $STR_REGEXPARRAYMATCH, $RegexPos) ;
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = "[" & $RegexResult[1] & "](#" & StringLower($RegexResult[1]) & "-module-)"
;FileWrite($Log, "Module : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{([A-Z][^\.#}]+)\.([^\.#}]+)}", $NewURL, 1)
WEnd
While 1 ; @{Module}
$RegexResult = StringRegExp($StringFile, "\@{([A-Z][^\.#}]+)}", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = "[" & $RegexResult[0] & "](#" & StringLower($RegexResult[0]) & "-module-)"
;FileWrite($Log, "Module : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{([A-Z][^\.#}]+)}", $NewURL, 1)
WEnd
While 1 ; @{File.Module#TYPE}
$RegexResult = StringRegExp($StringFile, "\@{([A-Z][^\.#}]+)\.([A-Z][^\.#}]+)#([A-Z,_]+)}", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = "[" & $RegexResult[2] & "](#" & StringLower($RegexResult[2]) & "-class-)"
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{([A-Z][^\.#}]+)\.([A-Z][^\.#}]+)#([A-Z,_]+)}", $NewURL, 1)
WEnd
While 1 ; @{Module#TYPE}
$RegexResult = StringRegExp($StringFile, "\@{([A-Z][^\.#}]+)#([A-Z,_]+)}", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = "[" & $RegexResult[1] & "](#" & StringLower($RegexResult[1]) & "-class-)"
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{([A-Z][^\.#}]+)#([A-Z,_]+)}", $NewURL, 1)
WEnd
While 1 ; @{#TYPE}
$RegexResult = StringRegExp($StringFile, "\@{#([A-Z,_]+)}", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = "[" & $RegexResult[0] & "](#" & StringLower($RegexResult[0]) & "-class-)"
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{#([A-Z,_]+)}", $NewURL, 1)
WEnd
While 1 ; #TYPE&@CR
$RegexResult = StringRegExp($StringFile, "\h#([A-Z,_]+)\s", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = " [" & $RegexResult[0] & "](#" & StringLower($RegexResult[0]) & "-class-)"&@CRLF
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\h#([A-Z,_]+)\s", $NewURL, 1)
WEnd
While 1 ; @{File.Module#TYPE.Function}(), catches the parenthesis
$RegexResult = StringRegExp($StringFile, "\@{([A-Z][^#}\.]+)\.([A-Z][^#}\.]+)#([A-Z,_]+)\.([^#\.]+)}[\(]?[\)]?", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = FindInFunctionList($RegexResult[2] & "-" & $RegexResult[3]&"-")
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{([A-Z][^#}\.]+)\.([A-Z][^#}\.]+)#([A-Z,_]+)\.([^#\.]+)}[\(]?[\)]?", $NewURL, 1)
WEnd
While 1 ; @{Module#TYPE.Function}(), catches the parenthesis
$RegexResult = StringRegExp($StringFile, "\@{([A-Z][^#}\.]+)#([A-Z,_]+)\.([^#}\.]+)}[\(]?[\)]?", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = FindInFunctionList($RegexResult[1] & "-" & $RegexResult[2]&"-")
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{([A-Z][^#}\.]+)#([A-Z,_]+)\.([^#}\.]+)}[\(]?[\)]?", $NewURL, 1)
WEnd
While 1 ; @{#TYPE.Function}(), catches the parenthesis
$RegexResult = StringRegExp($StringFile, "\@{#([A-Z,_]+)\.([^#}\.]+)}[\(]?[\)]?", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = FindInFunctionList($RegexResult[0] & "-" & $RegexResult[1]&"-")
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\@{#([A-Z,_]+)\.([^#}\.]+)}[\(]?[\)]?", $NewURL, 1)
WEnd
While 1 ; Module#TYPE
$RegexResult = StringRegExp($StringFile, "\h(\w+[^\h\_])#(.*?)\h", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = " [" & $RegexResult[1] & "](#" & StringLower($RegexResult[1]) & "-class-) "
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\h(\w+[^\h\_])#(.*?)\h", $NewURL, 1)
WEnd
While 1 ; File.Module#TYPE
$RegexResult = StringRegExp($StringFile, "\h(\w+)\.(\w+)#(.*?)\h", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = " [" & $RegexResult[2] & "](#" & StringLower($RegexResult[2]) & "-class-) "
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\h(\w+)\.(\w+)#(.*?)\h", $NewURL, 1)
WEnd
While 1 ; #TYPE.type (nested type... really annoying and confusing lua stuff)
$RegexResult = StringRegExp($StringFile, "\h#([A-Z,_]+)\.(\w+)\h", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewURL = " [" & $RegexResult[1] & "](#" &StringLower($RegexResult[0])& "-"& StringLower($RegexResult[1]) & "-class-)"
;FileWrite($Log, "Class : " & $RegexPos & " : " & _ArrayToString($RegexResult) & " -> " & $NewURL & @CRLF)
$StringFile = StringRegExpReplace($StringFile, "\h#([A-Z,_]+)\.(\w+)\h", $NewURL, 1)
WEnd
; Clean stuff with #
; ---------------------------------------------------------
$StringFile = StringReplace($StringFile, "#nil", "<u>Nil</u>")
$StringFile = StringReplace($StringFile, "#number", "<u>Number</u>")
$StringFile = StringReplace($StringFile, "#boolean", "<u>Boolean</u>")
$StringFile = StringReplace($StringFile, "#string", "<u>String</u>")
$StringFile = StringReplace($StringFile, "#table", "<u>List[]</u>")
$StringFile = StringReplace($StringFile, "#function", "<u>Function()</u>")
; And replace the pictures Path if any
; ---------------------------------------------------------
While 1
$RegexResult = StringRegExp($StringFile, "!\[(.*)\]\(.*\\(.*)\\(.*)\)", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
$NewPic = "![" & $RegexResult[0] & "](/includes/Pictures/" & $RegexResult[1] & "/"& $RegexResult[2]&")"
$StringFile = StringRegExpReplace($StringFile, "!\[(.*)\]\(.*\\(.*)\\(.*)\)", $NewPic, 1)
WEnd
While 1
$RegexResult = StringRegExp($StringFile, "(?m)^(\d(?:(\.\d))*\)(.*))$", $STR_REGEXPARRAYMATCH, $RegexPos)
$RegexPos = @extended
If @extended == 0 Then ExitLoop
;$StringFile = StringRegExpReplace($StringFile, "(?m)^(\d(?:(\.\d))*\)(.*))$", "<h4>"&$RegExResult[0]&"</h4>", 1)
$StringFile = StringRegExpReplace($StringFile, "(?m)^(\d(?:(\.\d))*\)(.*))$", "##### "&$RegExResult[0], 1)
WEnd
Return $StringFile
EndFunc

View File

@@ -0,0 +1,310 @@
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=..\bin\SlateDocGenerator2.exe
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
This is the main script
The script goal is to read .lua file, extract the documentation in comment blocks, and write .md files to be converted to html by Slate : https://github.com/lord/slate
It works in 5 steps :
First, it reads the .lua files one bt one, indentifying the comment blocks. for each comment block, it determines the kind of content the comment block describes (module, class/type or function),
find some usefull stuff (for exemple in the declaration...) and writes all of this info in the creatively named TreeHierarchy.csv, with this format :
@K=kind, @M=ParentModule, @N=Name, @P=Parent, @F=FileWhereTheCommentBlockIsLocated, @C=CarretPositionOfTheCommentBlock
The functions used to do this step are mostly found in Parser.au3
Then the second step is the longest : we sort the TreeHiearchy.csv, and put the result into TreeHierarchySorted.csv
The idea is to have the data in this order :
Module A
Class A (belongs to Module A)
Function A (belongs to Class A)
Function B (belongs to Class A)
Class B Class A (belongs to Module A)
Function C (belongs to Class B)
Function D (belongs to Class B)
Module B ...
The functions used to do this step are found in DataStorer.au3
Then, step 3 : We read each line of TreeHierarchySorted.csv, read the appropriate comment block in the .lua source files,
and write the appropriate Markdown documentation for it in a temporary folder
This is where the markdown documentation is actually written for the first time.
The functions used to do this step are found in Writer.au3
Step 4 ! We read the newly created Markdown files, trying to find hyperlinks/picture paths... and we replace them with the new ones.
We copy each processed file into it's final destination.
The functions used to do this step are mostly found in Parser.au3
And finally Step 5 : We add the new markdown files to Slate's index and delete temporary files and folder
#ce
#include <FileConstants.au3>
#include <StringConstants.au3>
#include <Array.au3>
#include <File.au3>
; Those are the arguments that need to be passed at the start
Global $SourceFolder = $CmdLine[1] ;"./Results"
Global $OutputFolder = $CmdLine[2] ;"@ScriptDir&"/source/index.html.md"
Global $Log = FileOpen(@ScriptDir & "\SlateGenerator2.log", 2)
Global $DataFile = FileOpen(@ScriptDir & "\TreeHierarchy.csv", 2)
Global $FunctionList = FileOpen(@ScriptDir & "\FuctionList.txt", 2)
#include "Parser.au3"
#include "DataStorer.au3"
#include "Writer.au3"
Func ExitCleanly()
FileClose($DataFile)
FileClose($FunctionList)
FileWrite($Log, "SlateGenerator2 exited cleanly")
FileClose($Log)
EndFunc
; Small function to determine if a comment block is describing a module, a type or a function
Func IdentifyBlock($Block, $Declaration)
Local $Kind
Local $KindFunction
$Kind = ParseForOneTag($Block, "@module")
If $Kind Then
Return "module"
EndIf
$Kind = ParseForOneTag($Block, "@type")
If $Kind Then
Return "type"
EndIf
$KindFunction = ParseFunctionName($Block, $Declaration)
If $KindFunction[0] Then
Return "function"
EndIf
Return ""
EndFunc
; -----------------------------------------------------------------
; Main
; -----------------------------------------------------------------
; Step 1 !
; -----------------------------------------------------------------
Local $SourceList = _FileListToArrayRec($SourceFolder, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
Local $CurrentFile
Local $CarretPos = 0
Local $CommentBlock
Local $CommentKind
Local $CommentInfo[2]
Local $CurrentModule
ConsoleWrite("1. Parsing Source Files... ")
FileWrite($Log, @CRLF&@CRLF&@TAB&"INFO : Building Hierarchy" & @CRLF)
For $i=1 To $SourceList[0] ; for each .lua source file
FileWrite($Log, "DEBUG : "&$SourceList[$i])
; let's read the next .lua source file
$CurrentFile = FileOpen($SourceList[$i], $FO_READ)
FileWrite($Log, @CRLF&"INFO : Reading File "&$SourceList[$i] & @CRLF)
While True ; for each comment block in the current .lua source file
; We read the next comment block. If we could not, it's probably eof, time to open the next .lua file
$CommentBlock = ReadNextBlock($CurrentFile, $CarretPos)
If Not $CommentBlock[1] Then
ExitLoop
EndIf
$CarretPos = $CommentBlock[0]
$CommentKind = IdentifyBlock($CommentBlock[1], $CommentBlock[2])
; Depending on the kind of comment block it is, we write the appropriate line in TreeHierarchy.csv
Switch $CommentKind
Case "function"
$CommentInfo = ParseFunctionName($CommentBlock[1], $CommentBlock[2])
AddNode("function", $CurrentModule, $CommentInfo[0], $CommentInfo[1], $SourceList[$i], $CommentBlock[3])
FileWrite($Log, "INFO : Added function "&$CommentInfo[0]&" to hierarchy" & @CRLF)
Case "type"
$CommentInfo[0] = ParseForOneTag($CommentBlock[1], "@type")
$CommentInfo[1] = ParseForOneTag($CommentBlock[1], "@extends")
$CommentInfo[1] = StringRegExpReplace($CommentInfo[1], "(.*#)", "")
AddNode("type", $CurrentModule, $CommentInfo[0], $CommentInfo[1], $SourceList[$i], $CommentBlock[3])
FileWrite($Log, "INFO : Added type "&$CommentInfo[0]&" to hierarchy" & @CRLF)
Case "module"
$CurrentModule = ParseForOneTag($CommentBlock[1], "@module")
AddNode("module", "", $CurrentModule, "", $SourceList[$i], $CommentBlock[3])
FileWrite($Log, "INFO : Added module "&$CurrentModule&" to hierarchy" & @CRLF)
EndSwitch
WEnd
$CarretPos = 0
FileClose($CurrentFile)
Next
ConsoleWrite("Done"&@CRLF)
; Step 2 !
; -----------------------------------------------------------------
ConsoleWrite("2. Sorting Hierarchy")
FileWrite($Log, @CRLF&@CRLF&@TAB&"INFO : Sorting Hierarchy" & @CRLF)
; The magic happens in DataStorer.au3
DataSort()
ConsoleWrite("Done"&@CRLF)
; Step 3 !
; -----------------------------------------------------------------
ConsoleWrite("3. Writing Markdown Documentation")
FileWrite($Log, @CRLF&@CRLF&@TAB&"INFO : Writing Markdown Documentation" & @CRLF)
Local $CurrentOutput
Local $CurrentFolder
Local $RegexResult
Local $Line
Local $CarretPos = 0
Local $Results
Local $Output
Local $Declaration
FileSetPos($DataFile, 0, $FILE_BEGIN)
While True ; For each line in TreeHierarchySorted.csv
; read the next line until eof
FileSetPos($DataFile, $CarretPos, $FILE_BEGIN)
$Line = FileReadLine($DataFile)
If @error Then ; eof
ExitLoop
Endif
$CarretPos = FileGetPos($DataFile)
; find the file/position of the next comment block referenced in the line
$RegexResult = StringRegExp($Line, "\@F=(.+?),", $STR_REGEXPARRAYMATCH)
$CurrentFile = FileOpen($RegexResult[0], $FO_READ)
$RegexResult = StringRegExp($Line, "\@C=(.+?),", $STR_REGEXPARRAYMATCH)
$DataPos = $RegexResult[0]
; get the comment block itself
$Results = ReadNextBlock($CurrentFile, $DataPos)
$Block = $Results[1]
$Declaration = $Results[2]
; choose the right function to write mardown depending on the type of comment block
$RegexResult = StringRegExp($Line, "\@K=(.+?),", $STR_REGEXPARRAYMATCH)
If $RegexResult[0] == "module" Then
ConsoleWrite(".")
; We need the name of the folder containing this particular source file
$RegexResult = StringRegExp($Line, "\@F=(.+?),", $STR_REGEXPARRAYMATCH)
$RegexResult = StringRegExp($RegexResult[0], "\\(.*)\\.*\.lua", $STR_REGEXPARRAYMATCH)
If @error Then
$CurrentFolder = ""
Else
$CurrentFolder = $RegexResult[0]
Endif
; Now we can write the markdown for this module
$CurrentOutput = WriteModule($Block, $CurrentFolder)
EndIf
If $RegexResult[0] == "type" Then
; We need the name of the Module containing the type
$RegexResult = StringRegExp($Line, "\@M=(.+?),", $STR_REGEXPARRAYMATCH)
; Now we can write the markdown for this type
WriteType($Block, $RegexResult[0], $CurrentOutput)
EndIf
If $RegexResult[0] == "function" Then
; We can write the markdown for this function
WriteFunction($Block, $Declaration, $CurrentOutput)
EndIf
FileClose($CurrentFile)
Wend
ConsoleWrite("Done"&@CRLF)
; Step 4 !
; -----------------------------------------------------------------
ConsoleWrite("4. Processing Hyperlinks...")
FileWrite($Log, @CRLF&@CRLF&@TAB&"INFO : Processing Hyperlinks" & @CRLF)
Local $i=1
Local $TempFilesArray = _FileListToArray(@ScriptDir & "/TEMP")
Local $CurrentFile
Local $FinalFile
While $i <= $TempFilesArray[0] ; For each markdown file in the temporary folder
;read the file
$CurrentFile = FileOpen(@ScriptDir & "/TEMP/" & $TempFilesArray[$i], 0)
; The magic happens in Parser.au3
$FinalString = ReplaceHyperlinks($CurrentFile)
; copy the result to the final file location
$FinalFile = FileOpen($OutputFolder & "/includes/" & $TempFilesArray[$i], 2)
FileWrite($FinalFile, $FinalString)
FileClose($FinalFile)
FileClose($CurrentFile)
$i += 1
WEnd
ConsoleWrite("Done"&@CRLF)
; Step 5 !
; -----------------------------------------------------------------
ConsoleWrite("5. Adding new documentation to index...")
FileWrite($Log, @CRLF&@CRLF&@TAB&"INFO : Adding new documentation to index" & @CRLF)
; Now this is a bit annoying : there is no way to insert a line in a document.
; So we need to read the first half of it, read the second half, and the wipe the whole document
; This way, in the new doc, we can write the first half, what we wanted to insert, and then the second half !
; Let's store the index file in $IndexString
Local $IndexFile = $OutputFolder&"/index.html.md"
Local $IndexFileHandle = FileOpen($IndexFile, 0)
Local $IndexString = FileRead($IndexFileHandle)
$IndexString = StringRegExpReplace($IndexString, "-\h[A-Z][a-z]+\.[A-Z][a-z]+\s", "")
; Now we slpit it into and store the results in $BeforeString and $AfterString
Local $SearchPos = StringInStr($IndexString, "search:")
local $BeforeString = StringTrimRight($IndexString, StringLen($IndexString) - $SearchPos + 5)
local $AfterString = StringTrimLeft($IndexString, $SearchPos - 1)
; reopening the index file wiping everything
FileClose($IndexFileHandle)
$IndexFileHandle = FileOpen($IndexFile, 2)
; write the first half
FileWrite($IndexFileHandle, $BeforeString)
Local $IncludePos = StringInStr($IndexString, "includes:")
FileSetPos($IndexFileHandle, $IncludePos + 10, $FILE_BEGIN)
; add the new markdown files to the index
$i = 1
While $i <= $TempFilesArray[0]
FileWrite($Log, StringTrimRight($TempFilesArray[$i], 3)&@CRLF)
FileWrite($IndexFileHandle, " - "&StringTrimRight($TempFilesArray[$i], 3)&@CRLF)
$i+=1
WEnd
FileWrite($IndexFileHandle, @CRLF)
; append the second half of the file
FileWrite($IndexFileHandle, $AfterString)
FileClose($IndexFileHandle)
ConsoleWrite("Done"&@CRLF)
; WE ARE DONE !
ExitCleanly()

View File

@@ -0,0 +1,209 @@
; Takes an array and returns it in a markdown flavored list
; If the list is a retun, then, there is no variable name...
Func ArrayToList($Array, $Return)
$String = ""
$i = 0
do
$String &= "* "
$String &= $Array[$i] & " "
If $Return Then
If $Array[$i + 2] == "" or $Array[$i + 2] == " " Then
$String &= @CRLF
Else
$String &= " " & $Array[$i + 1] & " " & $Array[$i + 2] & @CRLF
EndIf
Else
$String &= $Array[$i + 1]
If $Array[$i + 2] == "" or $Array[$i + 2] == " " Then
$String &= @CRLF
Else
$String &= " : " & $Array[$i + 2] & @CRLF
EndIf
EndIf
$i += 3
Until $i >= UBound($Array)
Return $String
EndFunc
Func WriteModule($Block, $Group)
Local $ModuleName = ParseForOneTag($Block, "@module")
DirCreate(@ScriptDir & "\TEMP")
Local $Output = FileOpen(@ScriptDir & "\TEMP\" & $Group & "." & $ModuleName & ".md", $FO_OVERWRITE)
Local $Data = ""
Local $DataPos = 1
FileWrite($Log, @CRLF&@TAB&"Writing "&$Group & "." & $ModuleName & ".md" &@CRLF)
FileWrite($Log, "Writing Module "&$ModuleName&@CRLF)
; Add title of Module
FileWrite($Output, "# " & $Group & "." & $ModuleName & " Module" & @CRLF)
; Copy the short description
While StringRight($Data, 1) <> @CRLF And StringRight($Data, 1) <> @CR
If StringRight($Data, 7) == "@module" Then ; If there is no comment in the module block
Return $Output
EndIf
$Data &= StringMid($Block, $DataPos, 1)
$DataPos += 1
WEnd
$Data = StringTrimRight($Data, 1)
$Block = StringTrimLeft($Block, $DataPos)
FileWrite($Output, $Data & @CRLF)
; copy the long description
$DataPos = 1
$Data = ""
$Omit = False
While StringRight($Data, 7) <> "@module"
$Data &= StringMid($Block, $DataPos, 1)
$DataPos += 1
WEnd
$Data = StringTrimRight($Data, 8)
FileWrite($Output, $Data & @CRLF)
Return $Output
EndFunc
Func WriteType($Block, $ModuleName, $Output)
Local $TypeName = ParseForOneTag($Block, "@type")
Local $ParentClass = GetData($TypeName, "parent")
Local $Fields = ParseForTags($Block, "@field")
FileWrite($Log, "Writing Type "&$TypeName&@CRLF)
; Add title of Type
FileWrite($Output, "## " & $TypeName & " Class" & @CRLF)
; Add hierearchy info if necessary. Some cool ASCII drawing is going on !
If $ParentClass <> "ROOT" Then
FileWrite($Output, "<pre>" & @CRLF)
FileWrite($Output, "Inheritance : The " & $TypeName & " Class inherits from the following parents :" & @CRLF)
Local $Hierarchy = GetParents($TypeName)
Local $String = ""
Local $TabBuffer = @TAB
$String &= $Hierarchy[0]&@CRLF
For $i=1 to UBound($Hierarchy)-1
$String &= $TabBuffer&"`-- "&$Hierarchy[$i]&@CRLF
$TabBuffer &= @TAB
Next
FileWrite($Output, $String)
FileWrite($Output, "</pre>" & @CRLF)
Else
FileWrite($Output, "<pre>" & @CRLF)
FileWrite($Output, "The " & $TypeName & " class does not inherit" & @CRLF)
FileWrite($Output, "</pre>" & @CRLF)
EndIf
; Copy the long description
Local $DataPos = 1
Local $Data = ""
Local $Omit = False
While StringRight($Data, 1) <> @CR ; We discard the first line
$Data &= StringMid($Block, $DataPos, 1)
$DataPos += 1
WEnd
; If there is a tag in the first line, there is no description
if StringInStr($Data, "@type") == 0 and StringInStr($Data, "@extends") == 0 and StringInStr($Data, "@field") == 0 Then
$Data = ""
$DataPos += 1
While StringRight($Data, 5) <> "@type"
$Data &= StringMid($Block, $DataPos, 1)
$DataPos += 1
WEnd
$Data = StringTrimRight($Data, 5)
FileWrite($Output, $Data & @CRLF)
EndIf
; Add the Attributes
If IsArray($Fields) Then
FileWrite($Output, "<h4> Attributes </h4>" & @CRLF & @CRLF)
FileWrite($Output, ArrayToList($Fields, False) & @CRLF)
EndIf
FileWrite($Output, @CRLF)
Return $TypeName
EndFunc
Func WriteFunction($Block, $Declaration, $Output)
Local $RegexResult = ParseFunctionName($Block, $Declaration)
Local $FunctionName = $RegexResult[0]
Local $TypeName = $RegexResult[1]
Local $Parameters = ParseParams($Block, $Declaration)
Local $Returns = ParseForTags($Block, "@return")
Local $Usage = ParseForOneTag($Block, "@usage")
Local $RegexResult
FileWrite($Log, "Writing Function "&$FunctionName&@CRLF)
If StringLeft($FunctionName, 1) == "_" Then
_FileWriteLog($Log, @TAB&@Tab&"Function is private. Ignored." & @CRLF)
Return $FunctionName
EndIf
; Add the class before the function name
If IsArray($Parameters) Then
If $Parameters[1] == "self" Then
$FunctionName = $TypeName & ":" & $FunctionName
EndIf
Else
$FunctionName = $TypeName & "." & $FunctionName
EndIf
; add the parameters in parenthesis
$FunctionName &= "("
If IsArray($Parameters) Then
For $i = 3 To UBound($Parameters) - 3 Step 3
$FunctionName &= $Parameters[$i + 1] & ", "
Next
If UBound($Parameters) > 3 Then
$FunctionName = StringTrimRight($FunctionName, 2)
EndIf
EndIf
$FunctionName &= ")"
;write the file name
FileWrite($Output, "### " & $FunctionName & @CRLF)
;Write the exemple if any
If $Usage <> "" Then
FileWrite($Output, "``` lua")
FileWrite($Output, $Usage)
FileWrite($Output, "```" & @CRLF)
EndIf
;Write the description
FileWrite($Log, $Block)
FileWrite($Log, StringTrimRight($Block, StringLen($Block) - StringInStr($Block, "@param") + 1) & @CRLF)
FileWrite($Output, StringTrimRight($Block, StringLen($Block) - StringInStr($Block, "@param") + 1) & @CRLF)
; Write the parameters
FileWrite($Output, "<h4> Parameters </h4>" & @CRLF)
If IsArray($Parameters) Then
FileWrite($Output, ArrayToList($Parameters, False) & @CRLF)
EndIf
; Write the returns
FileWrite($Output, "<h4> Returns </h4>" & @CRLF)
If IsArray($Returns) Then
FileWrite($Output, ArrayToList($Returns, True) & @CRLF)
EndIf
FileWrite($Output, @CRLF)
; add to the list of function balises (useful for hyperlinks)
$RegexResult = ParseFunctionName($Block, $Declaration)
Local $URLBalise = $TypeName & "-" & $RegexResult[0] & "-"
If IsArray($Parameters) Then
For $i = 3 To UBound($Parameters) - 3 Step 3
$URLBalise &= StringLower($Parameters[$i + 1]) & "-"
Next
EndIf
$URLBalise = StringTrimRight($URLBalise, 1)
FileWrite($FunctionList, $URLBalise & @CRLF)
return $FunctionName
EndFunc