SCM

SCM Repository

[inlinedocs] Diff of /pkg/inlinedocs/R/parsers.R
ViewVC logotype

Diff of /pkg/inlinedocs/R/parsers.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 257, Sun May 1 17:03:01 2011 UTC revision 270, Mon May 23 15:53:47 2011 UTC
# Line 89  Line 89 
89  ### Character vector of code lines with preceding whitespace removed.  ### Character vector of code lines with preceding whitespace removed.
90  }  }
91    
 examples.after.return <- function  
 ### Get examples from inline definitions after return()  
 ### PhG: this does not work well! Think of these situations:  
 ### 1) You have multiple return() in the code of your function,  
 ### 2) You have return() appearing is some example code, ...  
 ### I can hardly propose a hack here. The whole code of the function  
 ### must be parsed, and one must determine which one is the last line  
 ### of code that is actually executed.  
 ###  
 ### I make two propositions here  
 ### 1) to keep the same mechanism that has the advantage of simplicity  
 ###    but to use a special tag  
 ###    ##examples<< or #{{{examples to separate  
 ###    function code from examples explicitly, and  
 ### 2) to place the example in an "ex" attribute  
 ###    attached to the function  
 ###    (see next parser). That solution will be also interesting for  
 ###    documenting datasets, something not done yet by inlinedocs!  
 (src,name="",...) {  
   ## Look for the examples mark  
   m <- grep("^\\s*(##examples<<|#\\{\\{\\{examples)", src)  
   if (!length(m)) return(list())  
   if (length(m) > 1)  
     warning("More than one examples tag for ", name,  
             ". Taking the last one")  
   m <- m[length(m)]  
   ## Look for the lines containing return value comments just before  
   r <- grep("\\s*### ", src[1:(m-1)])  
     if (!length(r)) {  
       value <- NULL  
     } else {  
       ## Only take consecutive lines before the mark  
       keep <- rev((m - rev(r)) == 1:length(r))  
       if (!any(keep)) {  
         value <- NULL  
       } else {  
         value <- decomment(src[r[keep]])  
       }  
     }  
   ## Collect now the example code beneath the mark  
   ex <- src[(m + 1):(length(src) - 1)]  
   ## Possibly eliminate a #}}} tag  
   ex <- ex[!grepl("#}}}", ex)]  
   ## Eliminate leading tabulations or four spaces  
   ex <- kill.prefix.whitespace(ex)  
   ## Add an empty line before and after example  
   ex <- c("", ex, "")  
   ## Return examples and value  
   list(examples = ex, value = value)  
 }  
   
92  prefixed.lines <- structure(function(src,...){  prefixed.lines <- structure(function(src,...){
93  ### The primary mechanism of inline documentation is via consecutive  ### The primary mechanism of inline documentation is via consecutive
94  ### groups of lines matching the specified prefix regular expression  ### groups of lines matching the specified prefix regular expression
# Line 484  Line 433 
433  ### individual object.  ### individual object.
434  forfun.parsers <-  forfun.parsers <-
435    list(prefixed.lines=prefixed.lines,    list(prefixed.lines=prefixed.lines,
        examples.after.return=examples.after.return,  
436         extract.xxx.chunks=extract.xxx.chunks,         extract.xxx.chunks=extract.xxx.chunks,
437         ## title from first line of function def         ## title from first line of function def
438         title.from.firstline=function(src,...){         title.from.firstline=function(src,...){

Legend:
Removed from v.257  
changed lines
  Added in v.270

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge