Changeset 1571

Show
Ignore:
Timestamp:
08/06/08 23:14:44 (4 months ago)
Author:
Chuck.Esterbrook
Message:

Support nested block comments.

Location:
cobra/trunk
Files:
3 added
3 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r1569 r1571  
    11Post 0.8 
     2 
     3* Add support for commenting full blocks of lines using /# and #/. Block comments can be nested. 
     4        '/#' block comment start and  '#/' block comment end as initial chars on line 
    25 
    36* Added support for a Cobra compiler directive to specify the type for `number` 
    47    type of number and integer literals same as command line -number option 
    58    %% number  'decimal' | 'float' | 'float32' | 'float64' 
    6      
     9 
    710* Added a new built-in doc tool accessible via "cobra -doc ...". The documentation is generated to local HTML files using your declarations, doc strings, contracts, etc. 
    811 
  • cobra/trunk/Source/CobraTokenizer.cobra

    r1570 r1571  
    5151        var _inSubstStringDouble = false 
    5252        var _inDocString = false 
    53         var _inCommentBlock = false 
     53        var _inCommentBlock = 0 
    5454 
    5555        def init 
     
    341341                # _tokenDefsByWhich['STRING_PART_SINGLE'].isActiveCall = def(tokenizer)=tokenizer.inSubstStringSingle 
    342342                # _tokenDefsByWhich['STRING_STOP_SINGLE'].isActiveCall = def(tokenizer)=tokenizer.inSubstStringSingle 
    343                 for which in @[ 
    344                                 'RBRACKET_SPECIAL' , 
    345                                 'STRING_PART_SINGLE', 'STRING_STOP_SINGLE', 
    346                                 'STRING_PART_DOUBLE', 'STRING_STOP_DOUBLE', 
    347                                 'STRING_PART_FORMAT', 
    348                                 ] 
    349                                         _tokenDefsByWhich[which].isActive = false 
     343 
     344                # recover from multiline comments 
     345                while _tokenDefsByWhich.containsKey('COMMENT_BLOCK_LINE') 
     346                        .popTokenDefs 
     347                _inCommentBlock = 0 
     348 
     349                inactivate = [ 
     350                        'RBRACKET_SPECIAL' , 
     351                        'STRING_PART_SINGLE', 'STRING_STOP_SINGLE', 
     352                        'STRING_PART_DOUBLE', 'STRING_STOP_DOUBLE', 
     353                        'STRING_PART_FORMAT', 
     354                ] 
     355                for which in inactivate 
     356                        _tokenDefsByWhich[which].isActive = false 
    350357 
    351358        def isActiveCall(tok as TokenDef) as bool is override 
     
    387394        ## Comment out block 
    388395        ## 
    389          
    390         var _commentBlockStop as TokenRegexDef? 
    391         var _commentBlockLine as TokenRegexDef? 
     396 
     397        var _commentBlockDefs as List<of TokenDef>?      
    392398 
    393399        def onCOMMENT_BLOCK_START(tok as IToken) as IToken? 
    394400                #print '<> onCOMMENT_BLOCK_START', tok 
    395                 assert not _inCommentBlock 
     401                assert _inCommentBlock >= 0, tok 
    396402                # narrow the tokenizer's token defs to a new shorter set 
    397                 if _commentBlockStop is nil 
    398                         _commentBlockStop = TokenRegexDef('COMMENT_BLOCK_STOP', r'[^# \t]?\#\/.*$') 
    399                         _commentBlockLine = TokenRegexDef('COMMENT_BLOCK_LINE', '.*\n') 
    400                 t = List<of TokenDef>() 
    401                 t.add(_commentBlockStop) 
    402                 t.add(_commentBlockLine) 
    403                 .pushTokenDefs(t) 
    404                 _inCommentBlock = true 
     403                if _inCommentBlock == 0 
     404                        if _commentBlockDefs is nil 
     405                                # CC: _commentBlockDefs = List<of TokenDef>[_commentBlockStop, _commentBlockLine] # instead of the next 5 lines 
     406                                defs = List<of TokenDef>() 
     407                                defs.add(.tokenDefsByWhich['COMMENT_BLOCK_START']) 
     408                                defs.add(TokenRegexDef('COMMENT_BLOCK_STOP', r'[^# \t]?\#\/.*$')) 
     409                                defs.add(TokenRegexDef('COMMENT_BLOCK_LINE', '.*\n')) 
     410                                _commentBlockDefs = defs 
     411                        .pushTokenDefs(_commentBlockDefs to !) 
     412                _inCommentBlock += 1 
    405413                return nil 
    406414                 
    407415        def onCOMMENT_BLOCK_LINE(tok as IToken) as IToken? 
    408416                #print '<> onCOMMENT_BLOCK_LINE', tok.lineNum  
    409                 assert _inCommentBlock, tok 
     417                assert _inCommentBlock > 0, tok 
    410418                return nil 
    411419                 
    412420        def onCOMMENT_BLOCK_STOP(tok as IToken) as IToken? 
    413421                #print '<> onCOMMENT_BLOCK_STOP', tok.lineNum 
    414                 assert _inCommentBlock, tok 
    415                 _inCommentBlock = false 
    416                 .popTokenDefs 
     422                assert _inCommentBlock > 0, tok 
     423                _inCommentBlock -= 1 
     424                if _inCommentBlock == 0 
     425                        .popTokenDefs 
    417426                return nil 
    418427 
  • cobra/trunk/Source/Tokenizer.cobra

    r1540 r1571  
    365365        get errors from var 
    366366 
     367        get tokenDefsInOrder from _tokenDefs 
     368 
     369        get tokenDefsByWhich from var 
     370         
    367371 
    368372        ## Other