Jelajahi Sumber

Pragmas added to interfaces for hierarchical visibility.

Brucey 1 tahun lalu
induk
melakukan
f093c80610
6 mengubah file dengan 55 tambahan dan 10 penghapusan
  1. 5 0
      ctranslator.bmx
  2. 2 0
      decl.bmx
  3. 5 0
      iparser.bmx
  4. 21 0
      parser.bmx
  5. 21 9
      toker.bmx
  6. 1 1
      version.bmx

+ 5 - 0
ctranslator.bmx

@@ -7082,6 +7082,11 @@ End If
 			Emit "ModuleInfo " + BmxEnquote(info)
 		Next
 
+		' module pragmas
+		For Local pragma:String = EachIn app.mainModule.pragmas
+			Emit "#pragma " + BmxEnquote(pragma)
+		Next
+
 		Local processed:TMap = New TMap
 
 		' module imports

+ 2 - 0
decl.bmx

@@ -3983,6 +3983,8 @@ Type TModuleDecl Extends TScopeDecl
 	
 	' cache of ModuleInfo lines
 	Field modInfo:TList = New TList
+	' cache of pragma lines
+	Field pragmas:TList = New TList
 
 	Field _getDeclTreeCache:TList
 	

+ 5 - 0
iparser.bmx

@@ -246,6 +246,11 @@ Type TIParser
 				toker.nextToke()
 				If toker.TokeType()=TOKE_SPACE toker.NextToke()
 				Continue
+			case "#"
+				toker.nextToke()
+				Parse("pragma")
+				toker.nextToke()
+				Continue
 			Case "~r", "~n"
 				Continue
 			Default

+ 21 - 0
parser.bmx

@@ -3718,6 +3718,22 @@ End Rem
 		NextToke
 	End Method
 
+	Method ParsePragmaStmt()
+		
+		Local pragma:String = _toke
+		If pragma.StartsWith("'") Then
+			pragma = pragma[1..].Trim()
+			If Not pragma.StartsWith("@bmk") Then
+				Err "Syntax error - expecting @bmk pragma"
+			End If
+
+			pragma = pragma[4..].Trim()
+
+			_module.pragmas.AddLast(pragma)
+		End If
+		NextToke
+	End Method
+
 	Method ParseModuleDecl:String( toke$,attrs:Long )
 		NextToke
 
@@ -4349,6 +4365,11 @@ End Rem
 			Default
 				Exit
 			End Select
+
+			If _tokeType = TOKE_PRAGMA Then
+				ParsePragmaStmt()
+				NextToke
+			End If
 		Wend
 
 		' app code

+ 21 - 9
toker.bmx

@@ -40,6 +40,7 @@ Const TOKE_LINECOMMENT:Int=9
 Const TOKE_LONGLIT:Int=10
 Const TOKE_NATIVE:Int=11
 Const TOKE_STRINGMULTI:Int=12
+Const TOKE_PRAGMA:Int=13
 
 '***** Tokenizer *****
 Type TToker
@@ -256,25 +257,36 @@ Type TToker
 					If _tstr="~n" Then
 						_tokePos:-1
 						Exit
+					Else If _tstr="" Then
+						Exit
 					End If
 					_tokePos:+1
 					_tstr = TSTR()
 				Wend
-		
 			Else
 				_tokeType=TOKE_LINECOMMENT
 				
 				SkipToEOL()
-	
-				' completely ignore line comments
-				If TSTR()="~n" Then
-					start = _tokePos
-					If _tokePos<_source.Length
-						_tokePos:+1
+
+				Local pos:Int = _tokePos
+				If pos >= _source.Length
+					pos = _source.Length - 1
+				End If
+				Local tk:String = _source[start + 1..pos].Trim()
+				If tk.StartsWith("@bmk") Then
+					_tokeType=TOKE_PRAGMA
+				Else
+					' completely ignore line comments
+					If TSTR()="~n" Then
+						start = _tokePos
+						If _tokePos<_source.Length
+							_tokePos:+1
+						End If
+						_line:+1
+						_tokeType=TOKE_SYMBOL
 					End If
-					_line:+1
-					_tokeType=TOKE_SYMBOL
 				End If
+
 			End If
 		Else If str="." And TSTR()="." Then
 			Local pos:Int = _tokePos

+ 1 - 1
version.bmx

@@ -23,4 +23,4 @@
 '
 SuperStrict
 
-Const BCC_VERSION:String = "0.138"
+Const BCC_VERSION:String = "0.139"