2
0
Эх сурвалжийг харах

fix searching for "if" if "endif" already closed an if-statement

Ronny Otto 11 жил өмнө
parent
commit
681a60e296
1 өөрчлөгдсөн 8 нэмэгдсэн , 1 устгасан
  1. 8 1
      parser.bmx

+ 8 - 1
parser.bmx

@@ -1087,6 +1087,8 @@ Type TParser
 		While _toke<>term
 		While _toke<>term
 			Select _toke
 			Select _toke
 			Case "endif"
 			Case "endif"
+				'if searching for "end" (not function "end"),
+				'also accept "endif"
 				If term="end" Exit
 				If term="end" Exit
 				Err "Syntax error - expecting 'End'."
 				Err "Syntax error - expecting 'End'."
 			Case "else","elseif"
 			Case "else","elseif"
@@ -1124,8 +1126,13 @@ Type TParser
 		PopBlock
 		PopBlock
 
 
 		If eatTerm
 		If eatTerm
+			'only parse for "if" if the token wasn't endif
+			if _toke = "endif" then eatTerm = False
+
 			NextToke
 			NextToke
-			If term="end" Parse "if"
+
+			'still eating term? look for If
+			If eatTerm and term="end" Parse "if"
 		EndIf
 		EndIf
 
 
 		Local stmt:TIfStmt=New TIfStmt.Create( expr,thenBlock,elseBlock )
 		Local stmt:TIfStmt=New TIfStmt.Create( expr,thenBlock,elseBlock )