فهرست منبع

Greatly improved preprocessor error reporting.

Mark Sibly 8 سال پیش
والد
کامیت
84fbcc6cbf
4فایلهای تغییر یافته به همراه20 افزوده شده و 121 حذف شده
  1. 1 1
      src/mx2cc/errors.monkey2
  2. 1 1
      src/mx2cc/mx2cc.monkey2
  3. 17 108
      src/mx2cc/parser.monkey2
  4. 1 11
      src/mx2cc/test.monkey2

+ 1 - 1
src/mx2cc/errors.monkey2

@@ -25,7 +25,7 @@ Class ParseEx Extends ErrorEx
 		Self.srcfile=srcfile
 		Self.srcpos=srcpos
 		
-		Print ToString()
+		If srcfile Print ToString()
 	End
 	
 	Method ToString:String() Override

+ 1 - 1
src/mx2cc/mx2cc.monkey2

@@ -25,7 +25,7 @@ Const FORCE_MSVC:=False
 
 Global StartDir:String
 
-'Const TestArgs:="mx2cc makemods -clean"
+'Const TestArgs:="mx2cc makemods"
 
 'Const TestArgs:="mx2cc makemods -clean monkey"
 

+ 17 - 108
src/mx2cc/parser.monkey2

@@ -2079,13 +2079,6 @@ Class Parser
 	
 	'***** Messy Preprocessor - FIXME! *****
 	
-	Class EvalEx Extends Throwable
-		Field msg:String
-		Method new( msg:String )
-			Self.msg=msg
-		End
-	End
-	
 	Field _ppsyms:StringMap<String>
 	
 	Field _cc:=New Stack<Int>
@@ -2103,12 +2096,7 @@ Class Parser
 		If v="false" Or v="~q~q" Return "false"
 		Return "true"
 	End
-	
-	Method EvalError( msg:String )
-		Throw New EvalEx( msg )
-'		Error( "Failed to evaluate preprocessor expression: "+msg )' toke='"+Toke+"'" )
-	End
-		
+
 	Method EvalPrimary:String()
 	
 		If CParse( "(" )
@@ -2121,13 +2109,14 @@ Class Parser
 		Case TOKE_IDENT
 			Local id:=Parse()
 			Local t:=_ppsyms[id]
-			If Not t EvalError( "symbol '"+id+"' not found" )
+			If Not t Error( "symbol '"+id+"' not found" )
 			Return t
 		Case TOKE_STRINGLIT
 			Return Parse()
 		End
 
-		EvalError( "unexpected token '"+Toke+"'" )
+		Error( "unexpected token '"+Toke+"'" )
+		
 		Return Null
 	End
 	
@@ -2148,9 +2137,11 @@ Class Parser
 				lhs=ToBool( lhs )
 				rhs=ToBool( rhs )
 			Endif
+			
 			If (lhs="~q"+HostOS+"~q" And rhs="~qdesktop~q") Or (lhs="~qdesktop~q" And rhs="~q"+HostOS+"~q" ) 
-				EvalError( "__TARGET__=~qdesktop~q no longer supported! Use boolean __DESKTOP_TARGET__ instead!" )
+				Error( "__TARGET__=~qdesktop~q no longer supported! Use boolean __DESKTOP_TARGET__ instead!" )
 			Endif
+			
 			Select op
 			Case "=" If lhs=rhs lhs="true" Else lhs="false"
 			Case "<>" If lhs<>rhs lhs="true" Else lhs="false"
@@ -2230,7 +2221,7 @@ Class Parser
 				
 			Case "end","endif"
 			
-				If _cc.Length=1 EvalError( "#end without matching #if or #rem" )
+				If _cc.Length=1 p.Error( "#end without matching #if or #rem" )
 			
 				If p.CParse( "end" )
 					p.CParse( "if" )
@@ -2260,8 +2251,11 @@ Class Parser
 				If _cc.Top=1
 
 					p.Bump()
+					
 					Local path:=p.ParseString()
 					
+					p.ParseEol()
+					
 					If path.StartsWith( "<" ) And path.EndsWith( ">" )
 					
 						If Not ExtractExt( path ) path=path.Slice( 0,-1 )+".monkey2>"
@@ -2283,101 +2277,16 @@ Class Parser
 					Print p.Eval()
 				Endif
 				
-			End
-		
-			#rem
-			Select p.Toke.ToLower()
-			Case "if"
-				
-				If _ccnest=_ifnest
-				
-					p.Bump()
-					If p.EvalBool() _ccnest+=1
-					
-				Endif
-			
-				_ifnest+=1
-				
-			Case "else","elseif"
-			
-				If _ccnest=_ifnest
-				
-					_ccnest|=$10000
-					
-				Else If _ccnest=_ifnest-1
-			
-					Local t:=True
-
-					If p.CParse( "else" )
-						If p.CParse( "if" ) t=p.EvalBool()
-					Else 
-						p.Bump()
-						t=p.EvalBool()
-					Endif
-					
-					If t _ccnest+=1
-					
-				Endif
-			
-			Case "end","endif"
-			
-				If p.CParse( "end" )
-					p.CParse( "if" )
-				Else
-					p.Bump()
-				End
-				
-				_doccing=False
-				
-				_ccnest&=~$10000
-
-				If _ccnest=_ifnest _ccnest-=1
-				
-				_ifnest-=1
-			
-			Case "rem"
-			
-				If p.Bump()="monkeydoc" And _ccnest=_ifnest
-					Local qhelp:=p._toker.Text.Slice( p._toker.TokePos+9 ).Trim()
-					_ccnest|=$10000
-					_doccing=True
-					_docs.Clear()
-					_docs.Push( qhelp )
-				Endif
-				
-				_ifnest+=1
-			
-			Case "import"
-			
-				If _ccnest=_ifnest 
-					p.Bump()
-					Local path:=p.ParseString()
-					
-					If path.StartsWith( "<" ) And path.EndsWith( ">" )
-					
-						If Not ExtractExt( path ) path=path.Slice( 0,-1 )+".monkey2>"
-						
-					Else If Not path.Contains( "@/" ) And Not path.EndsWith( "/" )
-					
-						If Not ExtractExt( path ) path+=".monkey2"
-						
-					Endif
-					_imports.Push( path )
-				Endif
+			Default
 				
-			Case "print"
-			
-				If _ccnest=_ifnest
-					p.Bump()				
-					Print p.Eval()
+				If _cc.Top=1
+					p.Error( "Unrecognized preprocessor directive '"+p.Toke+"'" )
 				Endif
-				
 			End
-			#end
 			
-		Catch ex:EvalEx
-		
-			Error( "Preprocessor error - "+ex.msg )
+		Catch ex:ParseEx
+			
+			ErrorNx( ex.msg )
 		End
 		
 	End

+ 1 - 11
src/mx2cc/test.monkey2

@@ -1,15 +1,5 @@
 
-#Import "test2"
-
-Internal
-
-Function InternalTest()
-	
-	print "Internal!"
-
-End
-
-Public
+#Import "test2
 
 Function Main()