Ticket #20: blockComment1.patch

File blockComment1.patch, 4.9 kB (added by hopscc, 5 months ago)
  • Source/CobraTokenizer.cobra

     
    5050        var _inSubstStringSingle = false 
    5151        var _inSubstStringDouble = false 
    5252        var _inDocString = false 
     53        var _inCommentBlock = false 
    5354 
    5455        def init 
    5556                base.init 
     
    6566                sb.append('_inSubstStringSingle=[_inSubstStringSingle], ') 
    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, 
    7072        #       and retains the \n at the end of the line. This affects 
     
    8183                        r'INDENT_MIXED_ST               ^[ ]+[\t]+', 
    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]+', 
    88  
     91                         
    8992                        r'OPEN_GENERIC                  [A-Za-z_][A-Za-z0-9_]*<of[ \n\r\t]', 
    9093                        r'OPEN_IF                               if\(', 
    9194                        r'OPEN_CALL                             [A-Za-z_][A-Za-z0-9_]*\(', 
     
    380383                #print '<> onWHITESPACE_COMMENT_2' 
    381384                return nil 
    382385 
     386        ## 
     387        ## Comment out block 
     388        ## 
     389        def onCOMMENT_BLOCK_START(tok as IToken) as IToken? 
     390                #print '<> onCOMMENT_BLOCK_START', tok.lineNum 
     391                assert not _inCommentBlock 
     392                # narrow the tokenizer's token defs to a new shorter set 
     393                # TODO: cache the tokens below 
     394                t = List<of TokenDef>() 
     395                t.add(TokenRegexDef('COMMENT_BLOCK_STOP', r'[^# \t]?\#\/.*$')) 
     396                t.add(TokenRegexDef('COMMENT_BLOCK_LINE', '.*\n')) 
     397                .pushTokenDefs(t) 
     398                _inCommentBlock = true 
     399                return nil 
     400                 
     401        def onCOMMENT_BLOCK_LINE(tok as IToken) as IToken? 
     402                #print '<> onCOMMENT_BLOCK_LINE', tok.lineNum  
     403                assert _inCommentBlock, tok 
     404                return nil 
     405                 
     406        def onCOMMENT_BLOCK_STOP(tok as IToken) as IToken? 
     407                #print '<> onCOMMENT_BLOCK_STOP', tok.lineNum 
     408                assert _inCommentBlock, tok 
     409                _inCommentBlock = false 
     410                .popTokenDefs 
     411                return nil 
     412         
    383413        def onINDENT_MIXED_TSNS(tok as IToken) as IToken? 
    384414                # expecting tabs, spaces, non-whitespace 
    385415                assert tok.text.startsWith('\t') 
     
    817847        def onDOC_STRING_BODY_TEXT(tok as IToken) as IToken 
    818848                assert _inDocString, tok 
    819849                return tok 
    820  
    821  
     850                 
    822851        ## 
    823852        ## Simple string literals 
    824853        ## 
  • Tests/100-basics/018-multiline-comment.cobra

     
     1# Testing multiline/block  comments - /# and #/ on SOL 
     2namespace Test 
     3/# 1 
     4This section won't compile if uncommented 
     5a comment line 
     6        another comment line 
     7    x=55 + 2          
     8}#/ 
     9         
     10        class Test 
     11/# 2 
     12                _foo as int = 9 is shared 
     13                _bar as String is shared  
     14#/ 
     15                var foo1 as int = 9  
     16                        is shared, private 
     17 
     18 
     19/#{ 3 
     20        a comment TAB 
     21        # a comment SPACE TAB 
     22         # a comment TAB SPACE 
     23    # a comment 4 SPACEs 
     24     # a comment 5 SPACEs 
     25}#/ 
     26                def main is shared 
     27                        a = 1 
     28/# 
     29                        # test 
     30                        a += 1 
     31                        a += 1 
     32                        assert a==3 
     33                        a += _foo 
     34#/                       
     35            assert a==1 
     36                         
     37                        a = .foo1 
     38                        assert a == 9   # resolve to class var 
     39                         
     40                        a = .x 
     41                        assert a == 99 
     42                 
     43                        a = .x1 
     44                        assert a == 48 
     45                        return  
     46                         
     47                def x as int is shared 
     48                        ret=99 
     49/#{             ret += 1   
     50            ret += 1 
     51#/                      ret += 1  # rest of line after block comment termin ignored 
     52            return ret 
     53                 
     54/#               
     55                def foo1 as in is shared 
     56                        return 99 
     57#/                               
     58/#     # Comment out a method  
     59                def whatTimeIsLove is shared 
     60                        return nil 
     61#/ 
     62 
     63                def x1 as int is shared 
     64                        a =47 
     65/# 
     66            # comment across 2 methods 
     67 
     68            a += 1 
     69                        return a 
     70                 
     71                def  x2 is shared 
     72                        a = 48 
     73                        a += 2 
     74#/                       
     75 
     76                        a += 1 
     77            return a 
     78 
     79/# 
     80 
     81interface Stringy 
     82    def toStringX 
     83         
     84class String 
     85        implements Stringy 
     86                _s  
     87 
     88                def init() 
     89                        _s = 'xxxx' 
     90                         
     91                def toString 
     92                        return _s 
     93                 
     94#/ 
     95 
     96/# 
     97    test 
     98/#  these dont nest 
     99        assert _foo == 9 
     100        # / 
     101        assert _bar is nil 
     102#/ 
     103 
  • Developer/IntermediateReleaseNotes.text

     
    11Post 0.8 
    22 
     3* Add support for commenting full blocks of lines 
     4    '/#' block comment start and  '#/' block comment end as initial chars on line 
     5     
    36* 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. 
    47 
    58* Added support for declaring and raising events.