Ticket #116: multiline-if-indent.patch
File multiline-if-indent.patch, 3.6 KB (added by hopscc, 16 years ago) |
---|
-
Source/CobraParser.cobra
2124 2124 else 2125 2125 # for x in stuff 2126 2126 return ForEnumerableStmt(token, varr, what, .block) 2127 2127 2128 2128 def ifStmt as Stmt 2129 2129 token = .expect('IF') 2130 cond = .expression2130 cond = _expressionMultiLinePreBlock # was .expression 2131 2131 trueStmts = .block 2132 2132 falseStmts as BlockStmt? 2133 2133 if .peek.which=='ELSE' … … 2165 2165 def postWhileStmt as Stmt 2166 2166 token = .expect('POST') 2167 2167 .expect('WHILE') 2168 return PostWhileStmt(token, .expression, .block)2168 return PostWhileStmt(token, _expressionMultiLinePreBlock, .block) 2169 2169 2170 2170 def traceStmt as TraceStmt? 2171 2171 """ … … 2363 2363 return UsingStmt(token, varr, initExpr, block) 2364 2364 2365 2365 def whileStmt as Stmt 2366 return WhileStmt(.expect('WHILE'), .expression, .block)2366 return WhileStmt(.expect('WHILE'), _expressionMultiLinePreBlock, .block) 2367 2367 2368 2368 def yieldStmt as Stmt 2369 2369 token = .expect('YIELD') … … 2566 2566 2567 2567 var _inExpression as int 2568 2568 2569 def _expressionMultiLinePreBlock as Expr 2570 cond = .expression 2571 if cond.token.lineNum <> .last.lineNum and _spaceAgnosticIndentLevel <> 0 2572 # expression broken across multiple lines and changed indentation 2573 # unwind indentation and correct indentation tokens for the expected following block 2574 _spaceAgnostic 2575 _spaceAgnosticIndentLevel=0 2576 if .peek.which <> 'COMMA' 2577 .undo 2578 .replace(.peek.copy('INDENT')) 2579 .undo 2580 .replace(.peek.copy('EOL')) 2581 return cond 2582 2569 2583 def expression as Expr 2570 2584 test 2571 2585 assert 0 not in _binaryOpPrec.values -
Tests/110-basics-two/160-lines-and-comments/420-multiline-in-if.cobra
1 # Test multiline expressions in if-statements with non matching indentation 2 class IfSpaceAgnostic 3 def main is shared 4 a=99 5 b=99 6 7 if (a > 98 and 8 b == 99 ) # matching indent - otherwise OK 9 assert true, 'OK - 0' 10 else, assert false, 'fail' 11 12 if (a > 98 and 13 b == 99 ) 14 assert true, 'OK - 1 indent' 15 else 16 assert false, 'fail' 17 18 if (a > 98 and 19 b == 99 ) 20 assert true, 'OK - 2 indents' 21 else 22 assert false, 'fail' 23 24 if (a > 98 and 25 b == 99 ) 26 assert true, 'OK - 4 indents' 27 else 28 assert false, 'fail' 29 30 31 if (a > 98 and b == 99 ), assert true, 'OK - 2' #.no-warnings. 32 else, assert false, 'fail' 33 34 /# # TODO: fix this 35 if (a > 98 and 36 b == 99 ), assert true, 'OK - 2' 37 else, assert true, 'fail' 38 #/ 39 # pathological back indentation 40 if (a > 98 and 41 b == 99 ) 42 assert true, 'OK - 1 DEDENT)' 43 else 44 assert false, 'fail' 45 46 if b==99 or a==99 47 assert true, 'normal' 48 49 if b==99 or a==99, assert true, 'normal' -
Developer/IntermediateReleaseNotes.text
247 247 * Fixed: Cobra does not read "non-nilable" from DLL parameter types. 248 248 249 249 * Fixed: Cobra does not give a sensible error message when the `X` in `print to X, ...` is not a valid destination. ticket:63 250 251 * Fixed: multiline expression in if with different indentation. ticket:116