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 174, Thu Jan 6 13:48:40 2011 UTC revision 175, Thu Jan 6 15:24:45 2011 UTC
# Line 135  Line 135 
135    list(examples = paste(ex, collapse = "\n"), value = value)    list(examples = paste(ex, collapse = "\n"), value = value)
136  }  }
137    
138  prefixed.lines <- function(src,...){  prefixed.lines <- structure(function(src,...){
139  ### The primary mechanism of inline documentation is via consecutive  ### The primary mechanism of inline documentation is via consecutive
140  ### groups of lines matching the specified prefix regular expression  ### groups of lines matching the specified prefix regular expression
141  ### "\code{^### }" (i.e. lines beginning with "\code{### }") are  ### "\code{^### }" (i.e. lines beginning with "\code{### }") are
# Line 155  Line 155 
155    f <- function(ch)cumsum(nchar(gsub(sprintf("[^%s]",ch),"",code)))    f <- function(ch)cumsum(nchar(gsub(sprintf("[^%s]",ch),"",code)))
156    parens <- f("(")-f(")")    parens <- f("(")-f(")")
157    body.begin <- which(diff(parens)<0 & parens[-1]==0)+2    body.begin <- which(diff(parens)<0 & parens[-1]==0)+2
158      if(length(body.begin)==0)body.begin <- 1 ## rare cases
159    is.arg <- function(){    is.arg <- function(){
160      gres <- grep("^\\s*#",src[start-1],perl=TRUE)      gres <- grep("^\\s*#",src[start-1],perl=TRUE)
161      0 == length(gres) && start<=body.begin      0 == length(gres) && start<=body.begin
# Line 163  Line 164 
164    for(i in seq_along(starts)){    for(i in seq_along(starts)){
165      start <- clines[starts[i]]      start <- clines[starts[i]]
166      end <- clines[ends[i]]      end <- clines[ends[i]]
167      lab <- if(end+1==length(src))"value"      lab <- if(all(grepl("^\\s*#",src[end:(length(src)-1)])))"value"
168      else if(start==2)"description"      else if(start==2)"description"
169      else if(is.arg()){      else if(is.arg()){
170        ##twutz: strip leading white spaces and brackets and ,        ##twutz: strip leading white spaces and brackets and ,
# Line 179  Line 180 
180      res[[lab]] <- decomment(src[start:end])      res[[lab]] <- decomment(src[start:end])
181    }    }
182    res    res
183    },ex=function(){
184    test <- function
185    ### the desc
186    (x,
187    ### the first argument
188     y ##<< another argument
189     ){
190      5
191    ### the return value
192    ##seealso<< foobar
193  }  }
194    src <- attr(test,"source")
195    prefixed.lines(src)
196    extract.xxx.chunks(src)
197    })
198    
199  extract.xxx.chunks <- function # Extract documentation from a function  extract.xxx.chunks <- function # Extract documentation from a function
200  ### Given source code of a function, return a list describing inline  ### Given source code of a function, return a list describing inline

Legend:
Removed from v.174  
changed lines
  Added in v.175

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