Show
Ignore:
Timestamp:
08/20/08 12:42:26 (5 months ago)
Author:
Chuck.Esterbrook
Message:

Added support for implicit line continuation for items in parentheses.
credit:hopscc
ticket:31

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/CobraParser.cobra

    r1585 r1589  
    9797 
    9898        var _spaceAgnosticIndentLevel as int 
     99        var _spaceAgnosticExprLevel as int 
    99100        var _isContractOnSameLine as bool 
    100101 
     
    12391240                else 
    12401241                        .endOfLine 
    1241                 if not .optional('INDENT') 
    1242                         # with no indent there can be no additional specs like attributes, contracts or body 
     1242 
     1243                if _noMoreSpecs()   
     1244                        # No additional specs like attributes, contracts or body 
    12431245                        nothingMore = true 
    12441246                        if not hasIsNames 
     
    12891291                        return method 
    12901292 
     1293        def _noMoreSpecs as bool 
     1294                """ 
     1295                Return a bool indicating that there is no (correctly indented) additional specs  
     1296                like attributes, contracts or body following. 
     1297                """ 
     1298                if _spaceAgnosticIndentLevel == 0          # param decls all on same line  
     1299                        noMoreSpecs = not .optional('INDENT')  # anything else must be indented 
     1300                else 
     1301                        sail = _spaceAgnosticIndentLevel 
     1302                        if sail > 0 
     1303                                _spaceAgnosticIndentLevel -= 1  # for missing indent 
     1304                        _finishSpaceAgnostic 
     1305                        if sail >= 1 
     1306                                noMoreSpecs = .optional('DEDENT') is not nil  
     1307                        else 
     1308                                noMoreSpecs = not .optional('INDENT') 
     1309                return noMoreSpecs       
     1310                                 
    12911311        def declareMethodSig as MethodSig 
    12921312                require _typeProvider 
     
    15681588 
    15691589        def paramDecls(skipParen as bool) as List<of Param> 
    1570                 return .paramDecls(skipParen, 'RPAREN') 
     1590                return .paramDecls(skipParen, 'RPAREN', true) 
    15711591 
    15721592        def paramDecls(skipParen as bool, rightParen as String) as List<of Param> 
     1593                return .paramDecls(skipParen, rightParen, false)  
     1594                 
     1595        def paramDecls(skipParen as bool, rightParen as String, isSpaceAgnostic as bool) as List<of Param> 
    15731596                if not skipParen 
    15741597                        .expect('LPAREN') 
     
    15761599                expectComma = false 
    15771600                while true 
     1601                        if isSpaceAgnostic 
     1602                                _spaceAgnostic 
    15781603                        if .peek.which==rightParen 
    15791604                                .grab 
     
    15811606                        if expectComma 
    15821607                                .expect('COMMA') 
     1608                        if isSpaceAgnostic 
     1609                                _spaceAgnostic 
    15831610                        param = .paramDecl 
    15841611                        params.add(param) 
     
    24082435                        try 
    24092436                                expr = .expression(0, nil) 
    2410                                 if expr.isParened 
     2437                                if expr.isParened and expr.token.lineNum == .last.lineNum 
    24112438                                        _warning(expr.token, 'Unnecessary parentheses around expression. You can remove them.') 
    24122439                                return expr 
     
    24892516 
    24902517        def expression2 as Expr 
     2518                if _spaceAgnosticExprLevel > 0 
     2519                        _spaceAgnostic 
    24912520                peekToken = .peek 
    24922521                peek = peekToken.which 
     
    25042533                else if peek=='LPAREN' 
    25052534                        .grab 
     2535                        _spaceAgnosticExprLevel += 1 
    25062536                        node = .expression(0, nil) 
    25072537                        .expect('RPAREN') 
     2538                        _spaceAgnosticExprLevel -= 1 
    25082539                        node.isParened = true 
    25092540                        return node 
     
    26102641                        on 'OPEN_CALL' 
    26112642                                assert not callName.endsWith('(') 
    2612                                 args = .commaSepExprs(['RPAREN'], false, true) 
     2643                                args = .commaSepExprs(['RPAREN'], true, true) 
    26132644                                if .opStack.count and .opStack.peek == 'DOT' 
    26142645                                        return CallExpr(token, callName, args) 
     
    26262657                                                else, .throwError('Unexpected token [.last] in type arguments.') 
    26272658                                .expect('LPAREN') 
    2628                                 args = .commaSepExprs(['RPAREN'], false, true) 
     2659                                args = .commaSepExprs(['RPAREN'], true, true) 
    26292660                                return CallExpr(token, callName, typeArgs, args) 
    26302661                        else 
     
    32723303                                        continue 
    32733304                        break 
     3305                if _verbosity >= 5 
     3306                        print '<> spaceAgnostic level=[_spaceAgnosticIndentLevel]' 
    32743307 
    32753308        def _finishSpaceAgnostic 
     
    32773310                Eats up the DEDENTs and INDENTs that balance out the ones encountered in spaceAgnostic. 
    32783311                """ 
    3279                 if _verbosity>=5 
     3312                if _verbosity >= 5 
    32803313                        print '<> finishSpaceAgnostic level=[_spaceAgnosticIndentLevel]' 
    32813314                if _spaceAgnosticIndentLevel 
    3282                         while _spaceAgnosticIndentLevel>0 
     3315                        while _spaceAgnosticIndentLevel > 0 
    32833316                                .dedent 
    32843317                                _spaceAgnosticIndentLevel -= 1 
    3285                         while _spaceAgnosticIndentLevel<0 
     3318                        while _spaceAgnosticIndentLevel < 0 
    32863319                                .expect('INDENT') 
    32873320                                _spaceAgnosticIndentLevel += 1