Wiki

Ticket #116: multiline-if-indent.patch

File multiline-if-indent.patch, 3.6 KB (added by hopscc, 15 years ago)
  • Source/CobraParser.cobra

     
    21242124        else 
    21252125            # for x in stuff 
    21262126            return ForEnumerableStmt(token, varr, what, .block) 
    2127  
     2127             
    21282128    def ifStmt as Stmt 
    21292129        token = .expect('IF') 
    2130         cond = .expression 
     2130        cond = _expressionMultiLinePreBlock     # was .expression 
    21312131        trueStmts = .block 
    21322132        falseStmts as BlockStmt? 
    21332133        if .peek.which=='ELSE' 
     
    21652165    def postWhileStmt as Stmt 
    21662166        token = .expect('POST') 
    21672167        .expect('WHILE') 
    2168         return PostWhileStmt(token, .expression, .block) 
     2168        return PostWhileStmt(token, _expressionMultiLinePreBlock, .block) 
    21692169 
    21702170    def traceStmt as TraceStmt? 
    21712171        """ 
     
    23632363        return UsingStmt(token, varr, initExpr, block) 
    23642364 
    23652365    def whileStmt as Stmt 
    2366         return WhileStmt(.expect('WHILE'), .expression, .block) 
     2366        return WhileStmt(.expect('WHILE'), _expressionMultiLinePreBlock, .block) 
    23672367 
    23682368    def yieldStmt as Stmt 
    23692369        token = .expect('YIELD') 
     
    25662566 
    25672567    var _inExpression as int 
    25682568     
     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         
    25692583    def expression as Expr 
    25702584        test 
    25712585            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 
     2class 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

     
    247247* Fixed: Cobra does not read "non-nilable" from DLL parameter types. 
    248248 
    249249* 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