Changeset 1570

Show
Ignore:
Timestamp:
08/06/08 21:46:58 (4 months ago)
Author:
Chuck.Esterbrook
Message:

Added block comments /# ... #/
They don't nest yet. They can't be used inline.
credit:hopscc
ticket:20

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/CobraTokenizer.cobra

    r1549 r1570  
    5151        var _inSubstStringDouble = false 
    5252        var _inDocString = false 
     53        var _inCommentBlock = false 
    5354 
    5455        def init 
     
    6667                sb.append('_inSubstStringDouble=[_inSubstStringDouble], ') 
    6768                sb.append('_inDocString=[_inDocString]') 
     69                sb.append('_inCommentBlock=[_inCommentBlock]') 
    6870 
    6971        # Note: The Tokenizer class handles it's input one line at a time, 
     
    8284                        r'INDENT_ALL_TABS               ^[\t]+', 
    8385                        r'INDENT_ALL_SPACES             ^[ ]+', 
    84                         r'NO_INDENT                             ^(?=[^\t\n#])', 
     86                        r'NO_INDENT                             ^(?=[^\t\n#\/])', 
    8587                        r'EOL                                   \n', 
     88                        r'COMMENT_BLOCK_START   ^\/\#.*$',   
    8689                        r'SINGLE_LINE_COMMENT   \#.*', 
    8790                        r'SPACE                                 [ \t]+', 
     
    381384                return nil 
    382385 
     386        ## 
     387        ## Comment out block 
     388        ## 
     389         
     390        var _commentBlockStop as TokenRegexDef? 
     391        var _commentBlockLine as TokenRegexDef? 
     392 
     393        def onCOMMENT_BLOCK_START(tok as IToken) as IToken? 
     394                #print '<> onCOMMENT_BLOCK_START', tok 
     395                assert not _inCommentBlock 
     396                # 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 
     405                return nil 
     406                 
     407        def onCOMMENT_BLOCK_LINE(tok as IToken) as IToken? 
     408                #print '<> onCOMMENT_BLOCK_LINE', tok.lineNum  
     409                assert _inCommentBlock, tok 
     410                return nil 
     411                 
     412        def onCOMMENT_BLOCK_STOP(tok as IToken) as IToken? 
     413                #print '<> onCOMMENT_BLOCK_STOP', tok.lineNum 
     414                assert _inCommentBlock, tok 
     415                _inCommentBlock = false 
     416                .popTokenDefs 
     417                return nil 
     418 
    383419        def onINDENT_MIXED_TSNS(tok as IToken) as IToken? 
    384420                # expecting tabs, spaces, non-whitespace