Quellcode durchsuchen

Initial enum support.
Refactoring.

woollybah vor 6 Jahren
Ursprung
Commit
632a6f8665
4 geänderte Dateien mit 134 neuen und 104 gelöschten Zeilen
  1. 110 6
      src/makemd/docnode.bmx
  2. 5 5
      src/makemd/docstyle.bmx
  3. 14 88
      src/makemd/makemd.bmx
  4. 5 5
      src/makemd/mdstyle.bmx

+ 110 - 6
src/makemd/docnode.bmx

@@ -2,6 +2,7 @@
 Strict
 
 Import BRL.Map
+Import "parse.bmx"
 
 Type TDocNode
 
@@ -9,9 +10,10 @@ Type TDocNode
 	Field path$		'eg: Modules/Audio/Audio"
 	Field kind$		'eg: "Module", "Function", "Type" etc
 	
-	Field proto$		'eg: Function LoadImage(...)
-	Field protoId:String
-	Field protoExId:String
+'	Field proto$		'eg: Function LoadImage(...)
+'	Field protoId:String
+'	Field protoExId:String
+	Field proto:TProto
 	Field bbdoc$		'eg: Load an image (shortdesc?)
 	Field returns$	'eg: A new image
 	Field about$		'eg: blah etc blah (longdesc?)
@@ -36,7 +38,7 @@ Type TDocNode
 			Return t
 		End If
 		
-		If t And t.protoId <> protoId Then
+		If t And t.proto.protoId <> protoId Then
 			count :+ 1
 			
 			path = origPath + "_" + count
@@ -47,7 +49,7 @@ Type TDocNode
 		Return t
 	End Function
 	
-	Function Create:TDocNode( id$,path$,kind$, protoId:String )
+	Function Create:TDocNode( id$,path$,kind$, proto:String, protoId:String )
 	
 		Local t:TDocNode = GetDocNodeOrOverloadPath(kind, path, path, protoId)
 		
@@ -62,7 +64,7 @@ Type TDocNode
 		t.id=id
 		t.path=path
 		t.kind=kind
-		t.protoId = protoId
+		t.proto = New TProto(id, proto)
 		
 		Local q:TDocNode=t
 		
@@ -106,3 +108,105 @@ Type TDocNode
 	Global _pathMap:TMap=New TMap
 
 End Type
+
+Type TProto
+
+	Field id:String
+	Field ret:String
+	Field args:String
+	Field orig:String
+	Field protoId:String
+	
+	Method New(id:String, proto:String)
+		Self.id = id
+		orig = proto
+		
+		BuildProtoId()
+		BuildDets()
+	End Method
+
+	Method BuildProtoId()
+
+		' function-stripdir-path"
+		Local s:String
+		Local previousIdentChar:Int = False
+		For Local n:Int = EachIn orig.Trim()
+			' ignore brackets
+			If n = Asc("(") Then
+				Continue
+			End If
+			If IsProtoIdentChar(n) Then
+				s :+ Chr(n)
+				previousIdentChar = True
+			Else
+				If previousIdentChar Then
+					s :+ "-"
+				End If
+				previousIdentChar = False
+			End If
+		Next
+		If s.EndsWith("-") Then
+			s = s[..s.Length-1]
+		End If
+
+		protoId = s.ToLower()
+	End Method
+
+	Method BuildDets()
+
+		Local s:String = orig.ToLower()
+
+		If s.startsWith("method") Or s.StartsWith("function")
+			Local argsList:String
+			Local i:Int = s.Find("(")
+			Local argStr:String = s
+			If i >= 0 Then
+				argStr = s[i+1..]
+			End If
+
+			Local args:String[] = argStr.Split(",")
+			For Local arg:String = EachIn args
+				Local p:String[] = arg.split("=")
+				Local a:String = p[0].Trim()
+				If a = ")" Then
+					Exit
+				End If
+				p = a.Split(":")
+				Local ty:String
+				If p.length = 2 Then
+					ty = GetType(p[1].Split(" ")[0].Trim())
+				Else
+					ty = "i"
+				End If
+				argsList :+ ty
+			Next
+		
+			Self.args = argsList
+		
+		End If
+
+	End Method
+
+	Method GetType:String(s:String)
+	
+		If s.EndsWith(")") Then
+			s = s[..s.length-1]
+		End If
+	
+		Local ty:String = s
+		s = s.ToLower()
+	
+		Select s
+			Case "byte", "short", "int", "long", "uint", "float", "double"
+				ty = s[0..1]
+			Case "ulong"
+				ty = "ul"
+			Case "size_t"
+				ty = "t"
+			Case "string", "$"
+				ty = "r"
+		End Select
+		Return ty
+	End Method
+
+End Type

+ 5 - 5
src/makemd/docstyle.bmx

@@ -10,7 +10,7 @@ Import "docnode.bmx"
 
 Global BmxDocDir$=BlitzMaxPath()+"/docs/md"
 
-Global NodeKinds$[]=[ "/","Module","Type", "Interface", "Struct" ]
+Global NodeKinds$[]=[ "/","Module","Type", "Interface", "Struct", "Enum" ]
 
 Global LeafKinds$[]=[ "Const","Field","Global","Method","Function","Keyword" ]
 
@@ -59,7 +59,7 @@ Type TDocStyle Extends TBBLinkResolver
 		Else If NodeIsLeaf( node )
 			Local path:String = node.path.ToLower()
 
-			Return ExtractDir( path )+"/#"+node.protoId
+			Return ExtractDir( path )+"/#"+node.proto.protoId
 		Else If node.path<>"/"
 			If node.kind = "Module" Then
 				Return node.path.Replace(".", "_")+".md"
@@ -99,7 +99,7 @@ Type TDocStyle Extends TBBLinkResolver
 
 			If doc.kind = "Module" Then
 				url = "../.." + url
-			Else If doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Then
+			Else If doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Or doc.kind = "Enum" Then
 				url = "../../.." + url
 			End If
 		Else
@@ -124,7 +124,7 @@ Type TDocStyle Extends TBBLinkResolver
 		docURL=NodeURL( doc )
 		absDocDir=BmxDocDir+ExtractDir( docURL )
 
-		If doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Then
+		If doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Or doc.kind = "Enum" Then
 			relRootDir="../../.."
 		Else
 			relRootDir="../.."
@@ -195,7 +195,7 @@ Type TDocStyle Extends TBBLinkResolver
 		If node.kind <> "/" Then
 			generated=BBToHtml( sb.ToString(),Self )
 
-			SaveText generated,outputPath
+			SaveText generated,outputPath,ETextStreamFormat.UTF8,False
 		End If
 
 		sb.SetLength(0)

+ 14 - 88
src/makemd/makemd.bmx

@@ -21,7 +21,7 @@ Local style:TDocStyle=New TRstStyle
 
 DeleteDir BmxDocDir,True
 
-Local root:TDocNode=TDocNode.Create( "BlitzMax Help","/","/", Null )
+Local root:TDocNode=TDocNode.Create( "BlitzMax Help","/","/", Null, Null )
 
 CheckConfig()
 
@@ -87,7 +87,7 @@ Function DocBBDocs( docPath$ )
 				If id="index" Or id="intro" Continue
 				
 				Local path$=(docPath+"/"+id).Replace( "//","/" )
-				Local node:TDocNode=TDocNode.Create( id,path,"/", Null )
+				Local node:TDocNode=TDocNode.Create( id,path,"/", Null, Null )
 
 				node.about=LoadText( q )
 			End Select
@@ -114,8 +114,9 @@ Function docBmxFile( filePath$,docPath$ )
 	
 	Local Text$=LoadText( filepath )
 	
+	Local lineNumber:Int
 	For Local line$=EachIn Text.Split( "~n" )
-
+		lineNumber :+ 1
 		line=line.Trim()
 		Local tline$=line.ToLower()
 		
@@ -170,7 +171,7 @@ Function docBmxFile( filePath$,docPath$ )
 						params.AddLast String( params.RemoveLast() )+" "+line
 					Default
 						'remaining sections 1 line only...
-						If line Print "Error: Illegal bbdoc section in '"+filePath+"'"
+						If line Print "Error: Illegal bbdoc section in '"+filePath+"' on line " + lineNumber
 					End Select
 				End Select
 			
@@ -181,7 +182,7 @@ Function docBmxFile( filePath$,docPath$ )
 			bbdoc=""
 			inrem=True
 			
-		Else If id="endtype" Or id="endinterface" Or id="endstruct"
+		Else If id="endtype" Or id="endinterface" Or id="endstruct" Or id="endenum"
 
 			If typePath
 				docPath=typePath
@@ -229,7 +230,7 @@ Function docBmxFile( filePath$,docPath$ )
 				Local path$
 
 				Select kind
-				Case "Type", "Interface", "Struct"
+				Case "Type", "Interface", "Struct", "Enum"
 					If Not docPath Throw "No doc path"
 					If typePath Throw "Type path already set"
 					typePath=docPath
@@ -261,9 +262,7 @@ Function docBmxFile( filePath$,docPath$ )
 					proto=proto[..i]
 				EndIf
 				
-				Local node:TDocNode=TDocNode.Create( id,path,kind, BuildProtoId(proto) )
-				node.protoExId = BuildProtoExId(node.protoId)
-				node.proto=proto
+				Local node:TDocNode=TDocNode.Create( id,path,kind, proto, BuildProtoId(proto) )
 				node.bbdoc=bbdoc
 				node.returns=returns
 				node.about=about
@@ -277,9 +276,9 @@ Function docBmxFile( filePath$,docPath$ )
 					Local m:String = StripDir(path)
 					Local t:String = StripDir(ExtractDir(path))
 					
-					Local a:String = ExtractArgs(node.protoExId)
-					
-					If node.protoExId And apiDumpStream Then
+					Local a:String = node.proto.args
+
+					If apiDumpStream Then
 						If t.Find(".") = -1 And m.Find(".") = -1 Then
 							If a Then
 								apiDumpStream.WriteLine(t + "|" + m + "|" + (t + "_" + m + "_" + a + ".bmx").ToLower() )
@@ -314,22 +313,14 @@ Function docBmxFile( filePath$,docPath$ )
 	
 End Function
 
-Function ExtractArgs:String(proto:String)
-	Local s:String[] = proto.Split("+")
-	If s.length = 2 Then
-		Return s[1]
-	End If
-	Return ""
-End Function
-
-Function BuildProtoId:String(proto:String)
+Function BuildProtoId:String(proto:String, ignoreBrackets:Int = True)
 
 	' function-stripdir-path"
 	Local s:String
 	Local previousIdentChar:Int = False
 	For Local n:Int = EachIn proto.Trim()
 		' ignore brackets
-		If n = Asc("(") Then
+		If ignoreBrackets And n = Asc("(") Then
 			Continue
 		End If
 		If IsProtoIdentChar(n) Then
@@ -345,73 +336,8 @@ Function BuildProtoId:String(proto:String)
 	If s.EndsWith("-") Then
 		s = s[..s.Length-1]
 	End If
-	
-	Return s.ToLower()
-End Function
-
-Function BuildProtoExId:String(proto:String)
-
-	Local s:String = proto
-
-	If s.startsWith("method") Or s.StartsWith("function")
-		Local argsList:String
-		Local i:Int = proto.Find("(")
-		Local argStr:String = proto
-		If i >= 0 Then
-			argStr = proto[i+1..]
-		End If
-
-		Local args:String[] = argStr.Split(",")
-		For Local arg:String = EachIn args
-			Local p:String[] = arg.split("=")
-			Local a:String = p[0].Trim()
-			If a = ")" Then
-				Exit
-			End If
-			p = a.Split(":")
-			Local ty:String
-			If p.length = 2 Then
-				ty = GetType(p[1].Split(" ")[0].Trim())
-			Else
-				ty = "i"
-			End If
-			argsList :+ ty
-		Next
-		
-		Local count:Int
-		For i:Int = 0 Until s.length
-			If s[i] = Asc("-")
-				count :+ 1
-				If count = 2 Then
-					s = s[..i] + "+" + argsList
-				End If
-			End If
-		Next
-	End If
 
-	Return s
-End Function
-
-Function GetType:String(s:String)
-
-	If s.EndsWith(")") Then
-		s = s[..s.length-1]
-	End If
-
-	Local ty:String = s
-	s = s.ToLower()
-	
-	Select s
-		Case "byte", "short", "int", "long", "uint", "float", "double"
-			ty = s[0..1]
-		Case "ulong"
-			ty = "ul"
-		Case "size_t"
-			ty = "t"
-		Case "string", "$"
-			ty = "r"
-	End Select
-	Return ty
+	Return s.ToLower()
 End Function
 
 Function CheckConfig()

+ 5 - 5
src/makemd/mdstyle.bmx

@@ -10,7 +10,7 @@ Type TRstStyle Extends TDocStyle
 
 		If doc.kind = "/" Return
 
-		If doc.kind = "Module" Or doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Then
+		If doc.kind = "Module" Or doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Or doc.kind = "Enum" Then
 			Emit "---"
 			Emit "id: " + doc.id.ToLower() 
 			Emit "title: " + doc.id
@@ -21,11 +21,11 @@ Type TRstStyle Extends TDocStyle
 		
 		Local s:String
 		
-		If doc.kind <> "Module" And doc.kind <> "Type" And doc.kind <> "Interface" And doc.kind <> "Struct" Then
+		If doc.kind <> "Module" And doc.kind <> "Type" And doc.kind <> "Interface" And doc.kind <> "Struct"  And doc.kind <> "Enum" Then
 			Emit s + doc.id
 		End If
 
-		If (doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct") And doc.bbdoc Then
+		If (doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Or doc.kind = "Enum") And doc.bbdoc Then
 			Emit doc.bbdoc
 			Emit ""
 		EndIf
@@ -37,7 +37,7 @@ Type TRstStyle Extends TDocStyle
 			Emit ""
 		End If
 		
-		If doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Then
+		If doc.kind = "Type" Or doc.kind = "Interface" Or doc.kind = "Struct" Or doc.kind = "Enum" Then
 			EmitExample(doc)
 		End If
 		
@@ -129,7 +129,7 @@ Type TRstStyle Extends TDocStyle
 
 			Local s:String
 			
-			Emit "### `" + t.proto + "`"
+			Emit "### `" + t.proto.orig + "`"
 			Emit ""
 			
 			If t.bbdoc