Ticket #66: ticket66.patch
File ticket66.patch, 3.3 KB (added by eric.sellon, 15 years ago) |
---|
-
Source/CobraParser.cobra
79 79 var _typeProvider as ITypeProvider? 80 80 81 81 var _parseCommandLineArgs as ParseCommandLineArgsSig? 82 83 var _startOfLoopFlag as bool 84 var _curLoopBlockDepth as int 82 85 83 86 cue init 84 87 base.init … … 87 90 _codeParts = Stack<of AbstractMethod>() 88 91 _expectAnonymousMethodExprStack = Stack<of AnonymousMethodExpr>() 89 92 _references = List<of String>() 93 _startOfLoopFlag = false 94 _curLoopBlockDepth = 0 90 95 91 96 pro typeProvider from var 92 97 … … 1876 1881 s = .branchStmt 1877 1882 expectEOL = false 1878 1883 on 'BREAK' 1884 if _curLoopBlockDepth == 0 1885 .recordError(token, 'Cannot use "break" outside of a loop.') 1879 1886 s = .breakStmt 1880 1887 on 'CONTINUE' 1888 if _curLoopBlockDepth == 0 1889 .recordError(token, 'Cannot use "continue" outside of a loop.') 1881 1890 s = .continueStmt 1882 1891 on 'EXPECT' 1883 1892 s = .expectStmt 1884 1893 expectEOL = false 1885 1894 on 'FOR' 1895 _startOfLoopFlag = true 1886 1896 s = .forStmtBeginning 1887 1897 expectEOL = false 1888 1898 # on 'DEF' … … 1907 1917 on 'PASS' 1908 1918 s = .passStmt 1909 1919 on 'POST' 1920 _startOfLoopFlag = true 1910 1921 s = .postWhileStmt 1911 1922 expectEOL = false 1912 1923 on 'PRINT' … … 1928 1939 s = .usingStmt 1929 1940 expectEOL = false 1930 1941 on 'WHILE' 1942 _startOfLoopFlag = true 1931 1943 s = .whileStmt 1932 1944 expectEOL = false 1933 1945 on 'YIELD' … … 2398 2410 """ 2399 2411 stmts = List<of Stmt>() 2400 2412 done = false 2413 if _startOfLoopFlag 2414 _startOfLoopFlag = false 2415 _curLoopBlockDepth += 1 2416 else if _curLoopBlockDepth > 0 2417 _curLoopBlockDepth += 1 2401 2418 if .optional('COMMA') 2402 2419 token = .last 2403 2420 stmt = .stmt 2404 2421 if stmt 2405 2422 stmts.add(stmt) 2423 if _curLoopBlockDepth > 0, _curLoopBlockDepth -= 1 2406 2424 else 2407 2425 .throwError('Missing statement after comma.') 2408 2426 done = true … … 2413 2431 stmt = .stmt 2414 2432 if stmt 2415 2433 stmts.add(stmt) 2434 if _curLoopBlockDepth > 0, _curLoopBlockDepth -= 1 2416 2435 else 2417 2436 .throwError('Missing statement after colon.') 2418 2437 done = true … … 2423 2442 if stmt 2424 2443 stmts.add(stmt) 2425 2444 if .peek.which=='DEDENT' 2445 if _curLoopBlockDepth > 0, _curLoopBlockDepth -= 1 2426 2446 break 2427 2447 if not stmts.count 2428 2448 .throwError('Missing statements in block. Add a real statement or a "pass".') -
Tests/820-errors/300-statements/401-continue-break-wrong-places.cobra
1 """ 2 My Test 3 """ 4 5 class Program 6 7 def main 8 tom as int 9 print "hello 1" 10 continue # .error. continue 11 for tom = 0 .. 2 12 print tom 13 while true 14 branch tom 15 on 1 16 continue 17 else 18 tom = 1 19 print "hello 2" 20 break # .error. break 21 print "hello 3" 22 if true 23 continue # .error. continue 24 else 25 break # .error. break 26 print "hello 4" 27 28 No newline at end of file