Ticket #283: indent-lit.patch
File indent-lit.patch, 3.4 KB (added by hopscc, 11 years ago) |
---|
-
Source/CobraParser.cobra
3378 3378 3379 3379 def literalList as ListLit 3380 3380 token = .expect('LBRACKET') 3381 sail = _spaceAgnosticIndentLevel 3381 3382 exprs = .commaSepExprs('RBRACKET.', true) 3383 _adjustForIndents(_spaceAgnosticIndentLevel - sail) 3382 3384 return ListLit(token, exprs) 3383 3385 3386 def _adjustForIndents(extraIndents as int) 3387 """ 3388 Absorb any trailing dedents due indentation in a commaSepExpr with spaceAgnostic. 3389 This allows collectionLit terminating delimiters to be indented wrt line containing 3390 leading delimiter. 3391 """ 3392 if extraIndents >0 and .peek.which == 'EOL' 3393 _finishSpaceAgnostic 3394 # reassert the trailing EOL the spaceAgnostic cleanup cleared 3395 .ungrab 3396 .replace(.peek.copy('EOL', '\n')) 3397 3384 3398 def literalArray as ArrayLit 3385 3399 token = .expect('ARRAY_OPEN') 3400 sail = _spaceAgnosticIndentLevel 3386 3401 exprs = .commaSepExprs('RBRACKET.', true) 3402 _adjustForIndents(_spaceAgnosticIndentLevel - sail) 3387 3403 return ArrayLit(token, exprs) 3388 3404 3389 3405 def literalDictOrSet as CompositeLiteral … … 3414 3430 throw Exception('') # for code flow analysis 3415 3431 3416 3432 def _literalSet(token as IToken, expr as Expr?) as SetLit 3433 sail = _spaceAgnosticIndentLevel 3417 3434 if expr 3418 3435 exprs = [expr] 3419 3436 while true … … 3429 3446 _spaceAgnostic 3430 3447 if .optional('RCURLY') 3431 3448 break 3432 returnSetLit(token, exprs)3449 litSet = SetLit(token, exprs) 3433 3450 else 3434 3451 .expect('COMMA') 3435 3452 _spaceAgnostic 3436 3453 .expect('RCURLY') 3437 return SetLit(token, List<of Expr>()) 3438 3454 litSet = SetLit(token, List<of Expr>()) 3455 _adjustForIndents(_spaceAgnosticIndentLevel - sail) 3456 return litSet 3457 3439 3458 def _literalDict(token as IToken, expr as Expr?) as DictLit 3459 sail = _spaceAgnosticIndentLevel 3440 3460 if expr 3441 3461 expectComma = false 3442 3462 entries = List<of List<of Expr>>() … … 3464 3484 value = .expression 3465 3485 entries.add([key, value]) 3466 3486 expectComma = true 3467 returnDictLit(token, entries)3487 litDict = DictLit(token, entries) 3468 3488 else 3469 3489 .expect('COLON') 3470 3490 _spaceAgnostic 3471 3491 .expect('RCURLY') 3472 return DictLit(token, List<of List<of Expr>>()) 3473 3492 litDict = DictLit(token, List<of List<of Expr>>()) 3493 _adjustForIndents(_spaceAgnosticIndentLevel - sail) 3494 return litDict 3495 3474 3496 def nameExpr as NameExpr 3475 3497 nameToken = .expect('ID') 3476 3498 name = nameToken.text -
Tests/320-misc-two/450-list-lit-indent.cobra
1 # indented closing delimiter gave parse error - tkt:283 2 class ListIndent 3 4 var t = [ 0, 1, 3 5 ] 6 var aa= @[1,2,3 7 ] 8 9 var obj as Object? 10 11 def main 12 pass -
Tests/320-misc-two/452-dict-set-lit-indent.cobra
1 # indented closing delimiter gave parse error - tkt:283 2 class LitDictIndent 3 4 var t = { 'a': 0, 'b':1, 'c':3 5 } 6 var aa= {1,2,3 7 } 8 9 var obj as Object? 10 11 def main 12 pass