瀏覽代碼

.. (dot dot) handling rewrite.
Fixes #57 and #59.

woollybah 10 年之前
父節點
當前提交
5bfb3f0ef8
共有 3 個文件被更改,包括 36 次插入71 次删除
  1. 1 1
      options.bmx
  2. 2 37
      parser.bmx
  3. 33 33
      toker.bmx

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.29"
+Const version:String = "0.30"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1

+ 2 - 37
parser.bmx

@@ -687,11 +687,6 @@ Type TParser
 		Parse "["
 		Local args:TExpr[],nargs:Int
 		Repeat
-			If CParse("..") Then
-				If Not CParse("~n") Then
-					Err "Expecting expression but encountered '..'"
-				End If
-			End If
 			Local arg:TExpr=ParseExpr()
 			If args.Length=nargs args=args + New TExpr[10]
 			args[nargs]=arg
@@ -792,8 +787,6 @@ Type TParser
 						If bra<>1 Continue
 						eat=True
 						Exit
-					Case ".."
-						'toker.NextToke
 					End Select
 				Forever
 			Else
@@ -1058,18 +1051,6 @@ Type TParser
 			EndIf
 			Local id$=ParseIdent()
 			expr=New TInvokeSuperExpr.Create( id,ParseArgs( stmt ) )
-		Case ".." ' handle end-of-line "dot dot return"
-			'concat lines connected with ".."
-			HandleDotsLineConnector()
-
-			expr=ParseExpr()
-
-			'NextToke
-
-			'If Not CParse("~n") Then
-			'	Err "Expecting expression but encountered '..'"
-			'End If
-			'NextToke
 		Default
 			Select _tokeType
 			Case TOKE_IDENT
@@ -1206,11 +1187,6 @@ Type TParser
 				NextToke
 				Local rhs:TExpr=ParseUnaryExpr()
 				expr=New TBinaryMathExpr.Create( op,expr,rhs )
-			Case ".." ' handle end-of-line "dot dot return"
-				'concat lines connected with ".."
-				HandleDotsLineConnector()
-
-				Return expr
 			Default
 				Return expr
 			End Select
@@ -1408,7 +1384,7 @@ End Rem
 				
 					If singleLineIf Then
 						'check for "end"-command ("if a=1 end")
-						If currentToke = "end" and (currentToke + _toke) <> "endif" Then
+						If currentToke = "end" And (currentToke + _toke) <> "endif" Then
 							ParseEndStmt(False)
 						'found "end if"
 						Else
@@ -2288,8 +2264,6 @@ End Rem
 		SkipEols
 
 		Repeat
-			'concat lines connected with ".."
-			If _toke =".." Then HandleDotsLineConnector()
 			
 			If metaDataString Then
 				metaDataString :+ " "
@@ -2312,13 +2286,9 @@ End Rem
 			'read next token
 			NextToke()
 
-			If _toke =".." Then HandleDotsLineConnector()
-			
 			' got a value
 			If CParse("=") Then
 				
-				If _toke =".." Then HandleDotsLineConnector()
-				
 				If _tokeType = TOKE_IDENT Then
 					Err "Meta data must be literal constant"
 				End If
@@ -2389,8 +2359,6 @@ End Rem
 		If _toke<>")"
 			Local nargs:Int
 			Repeat
-				' handle end-of-line "dot dot return"
-				If _toke =".." Then HandleDotsLineConnector(True)
 
 				Local argId$=ParseIdent()
 
@@ -2426,9 +2394,6 @@ End Rem
 				nargs:+1
 				If _toke=")" Exit
 
-				' handle end-of-line "dot dot return"
-				If _toke =".." Then HandleDotsLineConnector()
-
 				Parse ","
 			Forever
 			args=args[..nargs]
@@ -3262,7 +3227,7 @@ endrem
 		While _toke
 			SetErr
 			Select _toke.ToLower()
-			Case "~n", ".."
+			Case "~n"
 				NextToke
 			Case "public"
 				NextToke

+ 33 - 33
toker.bmx

@@ -196,49 +196,49 @@ Type TToker
 				_tokePos:+1
 				_line:+1
 			EndIf
+		Else If str="." And TSTR()="." Then
+
+			Local pos:Int = _tokePos
+			Local isValidTilEOL:Int = True
+			_tokePos:+1
+			While TSTR() And TSTR()<>"~n"
+				If Not IsSpace(TCHR()) Then
+					isValidTilEOL = False
+				End If
+				_tokePos:+1
+			Wend
+			
+			If Not isValidTilEOL Then
+				_tokePos = pos + 1
+				_tokeType=TOKE_SYMBOL
+			Else
+				_tokePos:+1
+				_line:+1
+				_tokeType=TOKE_SPACE
+			End If
+			
 		Else
+
 			_tokeType=TOKE_SYMBOL
 			For Local i:Int = 0 Until _symbols.length
-'If i = 9 And _line = 42 DebugStop
+
 				Local sym$=_symbols[i]
 				If char<>sym[0] Continue
 
 				'do not try to read beyond source length
 				If TCHR(sym.length) <= 0 Then Continue
 
-'Local a:String = _source[_tokePos-1.._tokePos+sym.length-1]
 				If _source[_tokePos-1.._tokePos+sym.length-1].ToLower()=sym
-					'found the sym-string-representation in the code...
-					'but alphanumeric-symbols need a space or ".."-line-
-					'concat to work, skip other matches.
-					'else "Method My:ModObject" would tokenize ":mod"
-					Local isAlphaNum:Byte = False
-					For Local j:int = 0 Until sym.length
-						If IsAlpha(sym[j]) Or IsDigit(sym[j])
-							isAlphaNum = True
-							Exit
-						EndIf
-					Next
-					'only look advance if there is enough to read
-					If isAlphaNum And _source.Length >= _tokePos+sym.length
-						'compare following char according our rules
-						Local followUpChar:String = Chr(_source[_tokePos + sym.length - 1])
-
-						'NO concat via "double dot"?
-						If followUpChar = "."
-							'enough space left for double-dot-check
-							If _source.Length >= _tokePos + sym.length + 1
-								followUpChar = Chr(_source[_tokePos + sym.length])
-								If followUpChar = "." Then Continue
-							EndIf
-						EndIf
-
-						'NO space?
-						If Not IsSpace(Asc(followUpChar)) Then Continue
-					EndIf
-
-				
-					'_toke = _symbols_map[i]
+					
+					' if symbol has alpha, test for trailing alphanumeric char - in which case this is not a symbol
+					If IsAlpha(sym[sym.length-1]) Then
+						' not at the end of the file?
+						If _source.Length >= _tokePos+sym.length Then
+							If IsAlpha(TCHR(sym.length)) Or IsDigit(TCHR(sym.length)) Then
+								Exit
+							End If
+						End If
+					End If
 					
 					_tokePos:+sym.length-1