Browse Source

Added metadata recognition and ".."-newline fix

- metadata recognition inserted (skipping content for now). Recognized: Type/Function/Method/Field/Local/Global-metadata.

- added helper function for ".."-recognition. Unified "~r~n" AND "~n"-recognition (was missing in some cases)

Conflicts:
	parser.bmx
woollybah 11 years ago
parent
commit
0c42d1ea8b
2 changed files with 91 additions and 58 deletions
  1. 76 58
      parser.bmx
  2. 15 0
      tests/framework/language/metadata_01.bmx

+ 76 - 58
parser.bmx

@@ -816,21 +816,8 @@ Type TParser
 			Local id$=ParseIdent()
 			Local id$=ParseIdent()
 			expr=New TInvokeSuperExpr.Create( id,ParseArgs( stmt ) )
 			expr=New TInvokeSuperExpr.Create( id,ParseArgs( stmt ) )
 		Case ".." ' handle end-of-line "dot dot return"
 		Case ".." ' handle end-of-line "dot dot return"
-			Local tok:TToker = New TToker.Copy(_toker)
-			Local t:String = tok.NextToke()
-			If t = "~r" Then
-				t = tok.NextToke()
-				If t = "~n" Then
-					NextToke
-					NextToke
-				Else
-					NextToke
-				End If
-			Else
-				If t = "~n" Then
-					NextToke
-				End If
-			End If
+			'concat lines connected with ".."
+			HandleDotsLineConnector()
 
 
 			expr=ParseExpr()
 			expr=ParseExpr()
 
 
@@ -969,21 +956,9 @@ Type TParser
 				Local rhs:TExpr=ParseUnaryExpr()
 				Local rhs:TExpr=ParseUnaryExpr()
 				expr=New TBinaryMathExpr.Create( op,expr,rhs )
 				expr=New TBinaryMathExpr.Create( op,expr,rhs )
 			Case ".." ' handle end-of-line "dot dot return"
 			Case ".." ' handle end-of-line "dot dot return"
-				Local tok:TToker = New TToker.Copy(_toker)
-				Local t:String = tok.NextToke()
-				If t = "~r" Then
-					t = tok.NextToke()
-					If t = "~n" Then
-						NextToke
-						NextToke
-					Else
-						NextToke
-					End If
-				Else
-					If t = "~n" Then
-						NextToke
-					End If
-				End If
+				'concat lines connected with ".."
+				HandleDotsLineConnector()
+
 				Return expr
 				Return expr
 			Default
 			Default
 				Return expr
 				Return expr
@@ -1322,8 +1297,7 @@ Type TParser
 				ParseStmt
 				ParseStmt
 			End If
 			End If
 		Wend
 		Wend
-		' TODO : handle case of no catch - perhaps throw the exception again.
-		'If Not catches.Length() Err "Try block must have at least one catch block"
+		If Not catches.Length() Err "Try block must have at least one catch block"
 		PopBlock
 		PopBlock
 		NextToke
 		NextToke
 		CParse "try"
 		CParse "try"
@@ -1635,6 +1609,12 @@ Type TParser
 			EndIf
 			EndIf
 		EndIf
 		EndIf
 
 
+		'meta data for variables
+		If CParse( "{" ) then
+			'print "meta for variable: "+id+ " -> "+ParseMetaData()
+			ParseMetaData()
+		Endif
+
 		Return decl
 		Return decl
 	End Method
 	End Method
 
 
@@ -1658,6 +1638,52 @@ Type TParser
 		Until Not CParse(",")
 		Until Not CParse(",")
 	End Method
 	End Method
 
 
+	'handle end-of-line "dot dot return"-line connector
+	'-> skips EOL tokens
+	Method HandleDotsLineConnector()
+		Local tok:TToker = New TToker.Copy(_toker)
+		Local t:String = tok.NextToke()
+		If t = "~r" Then
+			t = tok.NextToke()
+			If t = "~n" Then
+				NextToke
+				NextToke
+			Else
+				NextToke
+			End If
+		Else
+			If t = "~n" Then
+				NextToke
+			End If
+		End If
+	End Method
+
+	'should return a specific "metadata object" ?
+	Method ParseMetaData:String()
+		Local metaDataString:String = ""
+		SkipEols
+
+		Repeat
+			'concat lines connected with ".."
+			If _toke =".." then HandleDotsLineConnector()
+
+			'append current token to metaDataString
+			metaDataString :+ _toke
+			'read next token
+			NextToke()
+
+			'reached end of meta data declaration
+			If _toke="}" then Exit
+		Forever
+
+		'continue to next token
+		NextToke()
+
+		'parse this into something
+		return metaDataString
+	End Method
+
+
 	Method ParseFuncDecl:TFuncDecl( toke$,attrs:Int )
 	Method ParseFuncDecl:TFuncDecl( toke$,attrs:Int )
 		SetErr
 		SetErr
 
 
@@ -1695,19 +1721,8 @@ Type TParser
 		If _toke<>")"
 		If _toke<>")"
 			Local nargs:Int
 			Local nargs:Int
 			Repeat
 			Repeat
-				If _toke =".." ' handle end-of-line "dot dot return"
-					Local tok:TToker = New TToker.Copy(_toker)
-					Local t:String = tok.NextToke()
-					If t = "~r" Then
-						t = tok.NextToke()
-						If t = "~n" Then
-							NextToke
-							NextToke
-						Else
-							NextToke
-						End If
-					End If
-				End If
+				' handle end-of-line "dot dot return"
+				If _toke =".." then HandleDotsLineConnector()
 
 
 				Local id$=ParseIdent()
 				Local id$=ParseIdent()
 
 
@@ -1737,19 +1752,8 @@ Type TParser
 				nargs:+1
 				nargs:+1
 				If _toke=")" Exit
 				If _toke=")" Exit
 
 
-				If _toke =".." ' handle end-of-line "dot dot return"
-					Local tok:TToker = New TToker.Copy(_toker)
-					Local t:String = tok.NextToke()
-					If t = "~r" Then
-						t = tok.NextToke()
-						If t = "~n" Then
-							NextToke
-							NextToke
-						Else
-							NextToke
-						End If
-					End If
-				End If
+				' handle end-of-line "dot dot return"
+				If _toke =".." then HandleDotsLineConnector()
 
 
 				Parse ","
 				Parse ","
 			Forever
 			Forever
@@ -1770,6 +1774,11 @@ Type TParser
 				EndIf
 				EndIf
 			Else If CParse( "nodebug" )
 			Else If CParse( "nodebug" )
 				' TODO : NoDebug
 				' TODO : NoDebug
+			Else If CParse( "{" ) 'meta data
+				' TODO : do something with the metadata
+				'meta data for functions/methods
+				'print "meta for func/meth: "+id+ " -> "+ParseMetaData()
+				ParseMetaData()
 			Else
 			Else
 				Exit
 				Exit
 			EndIf
 			EndIf
@@ -1975,6 +1984,15 @@ End Rem
 			EndIf
 			EndIf
 		Forever
 		Forever
 
 
+		'check for metadata
+		If CParse( "{" )
+			' TODO : do something with the metadata
+			'metadata for "type"s
+			'print "meta for type: "+id+ " -> "+ParseMetaData()
+			ParseMetaData()
+		End If
+
+
 		Local classDecl:TClassDecl=New TClassDecl.Create( id,args,superTy,imps,attrs )
 		Local classDecl:TClassDecl=New TClassDecl.Create( id,args,superTy,imps,attrs )
 
 
 		If classDecl.IsExtern()
 		If classDecl.IsExtern()

+ 15 - 0
tests/framework/language/metadata_01.bmx

@@ -0,0 +1,15 @@
+Rem
+	This test checks:
+	- if you can define "metadata" {meta="bla"}
+End Rem
+SuperStrict
+Framework BRL.StandardIO
+
+
+Type TMyClass {typemetadata="available"}
+	Field myfield:int  {fieldmetadata="available"}
+	Global instance:TMyClass
+
+	Function myfunc:int() {funcmetadata="available"}
+	End Function
+End Type