Ticket #210: line-cont-plus-spaces.patch
File line-cont-plus-spaces.patch, 6.6 KB (added by hopscc, 12 years ago) |
---|
-
Source/CobraParser.cobra
3047 3047 else 3048 3048 throw 3049 3049 3050 var _implicitContinuationOps = [ 3051 'ASSIGN', 'AND', 'OR', 'STAR', 'SLASH', 'PLUS', 'MINUS', 3052 'EQ', 'NE', 'LT', 'GT', 'LE', 'GE', 'IN', 'NOTIN', 3053 'PLUS_EQUALS', 'MINUS_EQUALS', 'STAR_EQUALS', 'SLASH_EQUALS', 'PERCENT_EQUALS', 3054 'SLASHSLASH', 'PERCENT', 'AMPERSAND', 'VERTICAL_BAR', 'CARET', 'DOUBLE_LT', 3055 'DOUBLE_GT', 'AMPERSAND_EQUALS', 'VERTICAL_BAR_EQUALS', 'CARET_EQUALS', 3056 'DOUBLE_LT_EQUALS', 'DOUBLE_GT_EQUALS', 'STARSTAR', 'STARSTAR_EQUALS' 3057 ] 3050 shared 3051 var implicitContinuationOps = [ 3052 'ASSIGN', 'AND', 'OR', 'STAR', 'SLASH', 'PLUS', 'MINUS', 3053 'EQ', 'NE', 'LT', 'GT', 'LE', 'GE', 'IN', 'NOTIN', 3054 'PLUS_EQUALS', 'MINUS_EQUALS', 'STAR_EQUALS', 'SLASH_EQUALS', 'PERCENT_EQUALS', 3055 'SLASHSLASH', 'PERCENT', 'AMPERSAND', 'VERTICAL_BAR', 'CARET', 'DOUBLE_LT', 3056 'DOUBLE_GT', 'AMPERSAND_EQUALS', 'VERTICAL_BAR_EQUALS', 'CARET_EQUALS', 3057 'DOUBLE_LT_EQUALS', 'DOUBLE_GT_EQUALS', 'STARSTAR', 'STARSTAR_EQUALS' 3058 ] 3058 3059 3059 3060 def _continuedExpression(prec as int, opToken as IToken) as Expr 3060 3061 """ … … 3062 3063 Relies on _expressionMultilinePreBlock (on if, postwhile and while stmts) 3063 3064 and end of statement _finishSpaceAgnostic to handle subsequent indent/dedent cleanup 3064 3065 """ 3065 if .peek.which == 'EOL' and opToken.which in _implicitContinuationOps3066 if .peek.which == 'EOL' and opToken.which in CobraParser.implicitContinuationOps 3066 3067 _spaceAgnostic # eat the following EOL and remove any now hanging indents 3067 3068 right = .expression(prec) 3068 3069 return right -
Source/CobraTokenizer.cobra
450 450 return t 451 451 452 452 def _processNumIndentLevels(numTabs as int) as IToken? 453 if .justDidLineContinuation 453 if .justDidLineContinuation and not _implicitLineContinuation 454 454 if numTabs < _indentCount 455 455 .recordError('Must indent same amount or more on a continued line.') 456 456 return nil … … 477 477 return firstTok 478 478 479 479 var _didLineContinuation as bool # only meaningful after an EOL 480 480 var _implicitLineContinuation as bool # only meaningful after an EOL 481 481 482 get justDidLineContinuation as bool 482 return .lastToken and .lastToken.which == 'EOL' and _didLineContinuation 483 483 return .lastToken and .lastToken.which == 'EOL' and (_didLineContinuation or _implicitLineContinuation) 484 485 shared 486 var implicitContinuationOps = [ 487 'COMMA', 'ASSIGN', 'AND', 'OR', 'STAR', 'SLASH', 'PLUS', 'MINUS', 488 'EQ', 'NE', 'LT', 'LE', 'GE', 'IN', 'NOTIN', # 'GT' confuses Generic dcls 489 'PLUS_EQUALS', 'MINUS_EQUALS', 'STAR_EQUALS', 'SLASH_EQUALS', 'PERCENT_EQUALS', 490 'SLASHSLASH', 'PERCENT', 'AMPERSAND', 'VERTICAL_BAR', 'CARET', 'DOUBLE_LT', 491 'AMPERSAND_EQUALS', 'VERTICAL_BAR_EQUALS', 'CARET_EQUALS', # ditto 'DOUBLE_GT' 492 'DOUBLE_LT_EQUALS', 'DOUBLE_GT_EQUALS', 'STARSTAR', 'STARSTAR_EQUALS' 493 ] 494 484 495 def onEOL(tok as IToken) as IToken? 485 496 _didLineContinuation = .lastToken and .lastToken.text == '_' and .lastToken.which == 'ID' 497 _implicitLineContinuation = .lastToken and .lastToken.which in CobraTokenizer.implicitContinuationOps 486 498 return tok 487 499 488 500 def onSINGLE_LINE_COMMENT_BLOCK(tok as IToken) as IToken? -
Tests/110-basics-two/150-line-continuation/130-implicit-line-cont-plus-wspc.cobra
1 # these implicitly continued lines have Tabs AND spaces 2 class X 3 4 def foo(i as int, j as int) as int 5 return i + j 6 7 def main 8 assert .foo(1, 2) ==3 9 assert .foo(1, 10 2) == 3 # tabs only 11 assert .foo(1, 12 2) == 3 # tabs and spaces 13 14 .stmtExpr 15 .cond 16 17 18 def stmtExpr 19 assert (1 + # braces ok 20 2) == 3 21 assert (1 + # braces ok 22 2) 23 assert 1 * # implicit trailing '*', 0 indent + space 24 2 == 2 25 26 assert 1 + # implicit trailing '+', 1 indent + spaces 27 2 == 3 28 29 assert (1 + # braces, double indent plus spaces 30 12) == 13 31 assert 1 + # trailing '+', double indent after plus spaces 32 2 == 3 33 assert 3 - # trailing '-', double indent after 34 2 == 1 35 36 assert 3 * # ((3*1) + 4) -(8/2) # multiple lines 37 1 + 38 4 - 39 8 / 40 2 == 3 41 42 a = 1 43 b = 2 44 assert (a == 1 and 45 b == 2) 46 assert a == 1 and #implicit on 'and' 47 b == 2 48 assert a == 1 or # implicit on or 49 b == 2 50 51 def cond 52 a=99 53 b=99 54 55 56 # 2nd perhaps subsequent lines indented 1 or 2 indents (plus spaces) 57 if a > 98 and 58 b == 99 59 assert true, 'OK - 1 indent' 60 else 61 assert false, 'fail' 62 63 if a > 98 and 64 b == 99 65 assert true, 'OK - 2 indents' 66 else 67 assert false, 'fail' 68 69 if a > 98 and 70 b == 99 or 71 a == b 72 assert true, 'OK - 1 indent' 73 else 74 assert false, 'fail' -
Tests/110-basics-two/150-line-continuation/120-implicit-line-cont-ops.cobra
18 18 19 19 assert 1 + # implicit trailing '+', 1 indent 20 20 2 == 3 21 #assert (1 + # Ticket 210: Cannot mix tabs and spaces in indentation.22 #2)23 #assert 1 + # Both tickets.24 #2 == 321 assert (1 + # Ticket 210: Cannot mix tabs and spaces in indentation. 22 2) 23 assert 1 + # Both tickets. 24 2 == 3 25 25 26 26 assert (1 + # braces, double indent 27 27 12) == 13 … … 45 45 assert a == 1 or # implicit on or 46 46 b == 2 47 47 48 #assert a == 1 and # implicit on and and tabs+spaces49 #b == 248 assert a == 1 and # implicit on and and tabs+spaces 49 b == 2 50 50 51 51 52 52 def cond … … 99 99 if a > 98 and b == 99, assert true, 'OK - 2' 100 100 else, assert false, 'fail' 101 101 102 /# TODO Fix this case 102 /# TODO Fix this case (when disallow back indent) 103 103 if a > 98 and 104 104 b == 99, assert true, 'OK - 2' 105 105 else, assert true, 'fail'