Ticket #341: spaceWrap.patch
File spaceWrap.patch, 2.4 KB (added by hopscc, 11 years ago) |
---|
-
CobraTokenizer.cobra
217 217 r'CARET s ^', 218 218 r'TILDE s ~', 219 219 220 r'EQ s ==',220 r'EQ s ==', 221 221 r'NE s <>', 222 222 r'LT s <', 223 223 r'GT s >', … … 239 239 r'DOUBLE_LT_EQUALS s <<=', 240 240 r'DOUBLE_GT_EQUALS s >>=', 241 241 242 # r'QUESTION_DOT s ?.', 242 243 r'QUESTION_EQUALS s ?=', 243 244 r'BANG_EQUALS s !=', 244 245 ] … … 259 260 return tokens 260 261 261 262 ## popular single chars 262 263 /# 263 264 def makeASSIGN(definition as String) as TokenDef? 264 265 return CharTokenDef('ASSIGN', c'=') 265 266 … … 282 283 return CharTokenDef('RBRACKET', c']') 283 284 284 285 ## end popular single chars 285 286 #/ 286 287 ## popular strings 287 288 288 289 def makeDOTDOT(definition as String) as TokenDef? … … 494 495 .throwError('Ambiguous comment at /#. For an end-of-line comment, put a space between / and #. For an inline comment, end it with #/. For a block comment, put /# at the beginning of a line.') 495 496 return .commentToken(tok) 496 497 498 var _lastSpaceToken as IToken? # keep to detect spaces between tokens 499 497 500 def onSPACE(tok as IToken) as IToken? 498 501 # eat these 502 _lastSpaceToken = tok 499 503 return nil 500 504 501 505 def onAT_ID(tok as IToken) as IToken? … … 733 737 tok.value = s 734 738 return tok 735 739 740 var _parenDepth = 0 736 741 742 def onLPAREN(tok as IToken) as IToken? 743 _parenDepth += 1 744 return tok 745 746 def onRPAREN(tok as IToken) as IToken? 747 if _parenDepth >0, _parenDepth -= 1 748 return tok 749 750 # enforcing formatting for space wrapped operators 751 def onASSIGN(tok as IToken) as IToken? 752 return _chkSpaceWrap(tok) 753 754 def onEQ(tok as IToken) as IToken? 755 return _chkSpaceWrap(tok) 756 757 def _chkSpaceWrap(tok as IToken) as IToken? 758 c = _sourceLine[0] 759 #I think this is less annoying if only ops outside enclosing () are forced space wrapped 760 # e.g ASSIGN: name = (t0=foo).bar 761 if _parenDepth == 0 and (not (.lastToken.charNum < _lastSpaceToken.charNum) or not (c == c' ' or c == c'\t')) 762 .recordError('Need at least one whitespace character around the operator ("[tok.text]" ([tok.which])).') 763 else 764 return tok 765 return nil 766 737 767 ## 738 768 ## String substitution handling 739 769 ## … … 1308 1338 assert state == 3 or state == 4 1309 1339 return TokenMatch(input) 1310 1340 1311 1312 1341 class SpaceTokenDef inherits TokenDef 1313 1342 1314 1343 test