Wiki

Changes between Initial Version and Version 1 of CodeDoc

Show
Ignore:
Timestamp:
07/08/10 13:47:49 (14 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CodeDoc

    v1 v1  
     1= Cobra Code Documentation =  
     2 
     3Cobra code can be documented internally with two constructs 
     4    * Comments  
     5    * Docstrings 
     6 
     7Comments explain or clarify code and intent.[[BR]] 
     8Docstrings describe use of code. 
     9 
     10 
     11 
     12== Comments == 
     13 
     14Comments are used to provide some text to a person reading the code and are intended  
     15to describe implementation; i.e clarify the code used or describe intent  
     16or background to the code. 
     17 
     18Comment lines can be placed pretty much anywhere. 
     19 
     20There are two types of comments  
     21    * Single line 
     22    * Multiline 
     23 
     24=== Grammar === 
     25{{{ 
     26 
     27# ANY COMMENT TEXT 
     28code... # TRAILING COMMENT TEXT 
     29     
     30 
     31code... /# commented out (code) within line #/ ...code...  
     32 
     33code... 
     34/# 
     35multiline block  of code or text commented out 
     36# embedded line comment 
     37code... # trailing comment 
     38#/ 
     39code... 
     40}}}     
     41 
     42=== Single line comments === 
     43 
     44Single line comments are introduced with a '''#''' character.[[br]] 
     45The remainder of the line (upto the EOLn character) is ignored so far as  
     46tokenization and code generation is concerned. 
     47{{{ 
     48numberType = if(.typeProvider, .typeProvider.numberType, DecimalType()) 
     49# parse literal to same type as numberType 
     50}}} 
     51 
     52A multiline block of comment text can be specified with multiple single  
     53lines starting with '#'. [[br]] 
     54Using multiple single comment lines this way also helps visually delineate the 
     55descriptive block better. 
     56 
     57{{{ 
     58def onWHITESPACE_LINE(tok as IToken) as IToken? 
     59    # Eat these. 
     60    # Don't muck with perceived indentation level as 
     61    # these kinds of lines are irrelevant. 
     62    #print '<> onWHITESPACE_LINE' 
     63    return nil 
     64.... 
     65# Note: The Tokenizer class handles it's input one line at a time, 
     66#       and retains the \n at the end of the line. This affects 
     67#       the regex design for the tokens below. 
     68 
     69}}} 
     70 
     71 
     72The comment character can appear anywhere in a line so code may be 
     73described with an inline trailing comment. 
     74{{{ 
     75var _didLineContinuation as bool  # only meaningful after an EOL 
     76}}} 
     77 
     78  
     79=== !MultiLine Comments === 
     80 
     81Multiline comments are a block of text delimited by '''/#''' and '''#/'''.[[BR]] 
     82Everything from the first delimiter up to and including the first occurrence 
     83of the second delimiter is ignored 
     84(including any embedded single line or trailing comments. 
     85 
     86The most common use for this perhaps is to comment out a block of code. 
     87{{{ 
     88def startSource(fileName as String, source as String) as Tokenizer 
     89    /# 
     90    print '**********************************************' 
     91    print source 
     92    print '**********************************************' 
     93    #/ 
     94    _fileName = fileName 
     95    _stream = StringReader(source) 
     96    .afterStart 
     97    return this 
     98}}} 
     99 
     100You can also comment (out) code within a line with inline '''/#... #/''' 
     101{{{ 
     102x = /# -1 * #/ z * y 
     103# same as x = z * y  
     104 
     105params = .paramDecls(/#skipParen=#/true) 
     106}}} 
     107 
     108 
     109 
     110=== Special Comment Strings === 
     111 
     112Cobra generates warnings for things it detects can be done in a less verbose  
     113or more ''snakelike'' manner. [[br]] 
     114Mostly this is helpful, sometimes its irritating or unnecessary. 
     115 
     116You can suppress (all) warnings generated for a particular line with a  
     117trailing comment starting with the tag '''.nowarnings.''' (note leading and trailing '.').[[br]] 
     118Any subsequent text after the tag is ignored. 
     119{{{ 
     120# Normally this would warn with a suggestion to remove the trailing () 
     121callMe()    # .nowarnings.   I like explicit () for this call 
     122}}} 
     123 
     124 
     125 
     126=== Notes === 
     127 
     128Its not uncommon to provide comments describing additional code or capability 
     129to be implemented at a later date. [[br]] 
     130Usually this uses a tag '''TODO:''' followed by the notation. 
     131{{{ 
     132# TODO: move to CobraCore 
     133... 
     134# TODO: Add contract to enforce above statement 
     135}}} 
     136 
     137 
     138 
     139------------------------- 
     140== !DocStrings == 
     141 
     142Docstrings can be placed at various specific points in cobracode and are intended  
     143as documentation to describe the use of or as a summary of the docced item. 
     144 
     145Docstrings may be single line or multi line but in both cases are delimited start and end by triple ". [[BR]] 
     146e.g 
     147{{{ 
     148"""This is a single line docstring.""" 
     149 
     150""" 
     151This is a multiline Docstring. 
     152 
     153Leading summary line, blank line and descriptive text 
     154Leading and trailing triple-" delimiter each on its own line. 
     155""" 
     156}}} 
     157Docstrings are placed after the item being documented indented as if they were executable code. 
     158 
     159Single line docstrings are intended for documenting simple really obvious cases.[[br]] 
     160Multiline are for items that require a bit more description. 
     161 
     162For a good description of the form, format and intent of docstrings (wrt python) 
     163please see the [http://www.python.org/dev/peps/pep-0257/ python PEP]. 
     164 
     165Docstrings can appear: 
     166    * At the start of a Module (File) 
     167    * Immediately after a '''namespace''' declaration 
     168    * Immediately after an Object declaration: 
     169      '''class''', '''interface''', '''struct''', '''mixin''', '''enum''', '''event''' 
     170    * Immediately after an extension declaration ('''extend''') 
     171    * after a '''var''' or '''const''' declaration 
     172    * after a property definition ('''pro''', '''get''', '''set''') 
     173    * after a method or cue (initializer) declaration ( '''def''' and '''cue''') 
     174    * after a '''sig''' declaration 
     175 
     176=== Grammar === 
     177{{{ 
     178    """ TEXT """ 
     179 
     180    """ 
     181    TEXT LINE 
     182    SUBSEQUENT TEXT LINES ... 
     183    """ 
     184}}} 
     185=== Examples === 
     186 
     187{{{ 
     188"""Example module showing docstring positions""" 
     189 
     190 
     191class AClass 
     192    """ This is an example class containing lots of docstrings.""" 
     193     
     194    var _foofahCount = 0 
     195        """Used only with green wiglets""" 
     196         
     197    get hasFoofahs as bool 
     198       """True if number of  foofahs > 0""" 
     199        
     200    pro wigletIsGreen as bool 
     201        """Triggers foofah count if true.""" 
     202     
     203    cue init 
     204        """Std Initializer.""" 
     205        base.init 
     206         
     207    def doNothing 
     208        """Nothing happens in this method. comeback later""" 
     209        pass 
     210}}} 
     211 
     212 
     213=== Notes === 
     214 
     215The cobra compiler can be run to generate html files containing code entrypoints/signatures and docstrings for each listed file. 
     216{{{ 
     217cobra -doc standAlone.cobra 
     218 
     219cobra -doc main.cobra -files:files.cobra 
     220}}} 
     221 
     222 
     223== See Also == 
     224 
     225 
     226[wiki:LanguageTopics Back to Language Topics]