Changeset 1589 for cobra/trunk/Source/CobraParser.cobra
- Timestamp:
- 08/20/08 12:42:26 (5 months ago)
- Files:
-
- 1 modified
-
cobra/trunk/Source/CobraParser.cobra (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/CobraParser.cobra
r1585 r1589 97 97 98 98 var _spaceAgnosticIndentLevel as int 99 var _spaceAgnosticExprLevel as int 99 100 var _isContractOnSameLine as bool 100 101 … … 1239 1240 else 1240 1241 .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 1243 1245 nothingMore = true 1244 1246 if not hasIsNames … … 1289 1291 return method 1290 1292 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 1291 1311 def declareMethodSig as MethodSig 1292 1312 require _typeProvider … … 1568 1588 1569 1589 def paramDecls(skipParen as bool) as List<of Param> 1570 return .paramDecls(skipParen, 'RPAREN' )1590 return .paramDecls(skipParen, 'RPAREN', true) 1571 1591 1572 1592 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> 1573 1596 if not skipParen 1574 1597 .expect('LPAREN') … … 1576 1599 expectComma = false 1577 1600 while true 1601 if isSpaceAgnostic 1602 _spaceAgnostic 1578 1603 if .peek.which==rightParen 1579 1604 .grab … … 1581 1606 if expectComma 1582 1607 .expect('COMMA') 1608 if isSpaceAgnostic 1609 _spaceAgnostic 1583 1610 param = .paramDecl 1584 1611 params.add(param) … … 2408 2435 try 2409 2436 expr = .expression(0, nil) 2410 if expr.isParened 2437 if expr.isParened and expr.token.lineNum == .last.lineNum 2411 2438 _warning(expr.token, 'Unnecessary parentheses around expression. You can remove them.') 2412 2439 return expr … … 2489 2516 2490 2517 def expression2 as Expr 2518 if _spaceAgnosticExprLevel > 0 2519 _spaceAgnostic 2491 2520 peekToken = .peek 2492 2521 peek = peekToken.which … … 2504 2533 else if peek=='LPAREN' 2505 2534 .grab 2535 _spaceAgnosticExprLevel += 1 2506 2536 node = .expression(0, nil) 2507 2537 .expect('RPAREN') 2538 _spaceAgnosticExprLevel -= 1 2508 2539 node.isParened = true 2509 2540 return node … … 2610 2641 on 'OPEN_CALL' 2611 2642 assert not callName.endsWith('(') 2612 args = .commaSepExprs(['RPAREN'], false, true)2643 args = .commaSepExprs(['RPAREN'], true, true) 2613 2644 if .opStack.count and .opStack.peek == 'DOT' 2614 2645 return CallExpr(token, callName, args) … … 2626 2657 else, .throwError('Unexpected token [.last] in type arguments.') 2627 2658 .expect('LPAREN') 2628 args = .commaSepExprs(['RPAREN'], false, true)2659 args = .commaSepExprs(['RPAREN'], true, true) 2629 2660 return CallExpr(token, callName, typeArgs, args) 2630 2661 else … … 3272 3303 continue 3273 3304 break 3305 if _verbosity >= 5 3306 print '<> spaceAgnostic level=[_spaceAgnosticIndentLevel]' 3274 3307 3275 3308 def _finishSpaceAgnostic … … 3277 3310 Eats up the DEDENTs and INDENTs that balance out the ones encountered in spaceAgnostic. 3278 3311 """ 3279 if _verbosity >=53312 if _verbosity >= 5 3280 3313 print '<> finishSpaceAgnostic level=[_spaceAgnosticIndentLevel]' 3281 3314 if _spaceAgnosticIndentLevel 3282 while _spaceAgnosticIndentLevel >03315 while _spaceAgnosticIndentLevel > 0 3283 3316 .dedent 3284 3317 _spaceAgnosticIndentLevel -= 1 3285 while _spaceAgnosticIndentLevel <03318 while _spaceAgnosticIndentLevel < 0 3286 3319 .expect('INDENT') 3287 3320 _spaceAgnosticIndentLevel += 1
