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 108, Wed May 26 12:00:17 2010 UTC revision 109, Mon Jun 7 08:42:15 2010 UTC
# Line 133  Line 133 
133  ### lonely$parsefun(attr(extract.docs.file,"source"),"extract.docs.file")  ### lonely$parsefun(attr(extract.docs.file,"source"),"extract.docs.file")
134  lonely <- sapply(forall.parsers,function(L)L[[2]])  lonely <- sapply(forall.parsers,function(L)L[[2]])
135    
136  extract.docs.file <- function # Extract documentation from a file  extra.code.docs <- function # Extract documentation from code chunks
137  ### Parse R code to extract inline documentation from comments around  ### Parse R code to extract inline documentation from comments around
138  ### each function. These are not able to be retreived simply by  ### each function. These are not able to be retreived simply by
139  ### looking at the "source" attribute. This is a Parser Function that  ### looking at the "source" attribute. This is a Parser Function that
# Line 251  Line 251 
251  }  }
252    
253  ### List of parsers to use by default with package.skeleton.dx.  ### List of parsers to use by default with package.skeleton.dx.
254  default.parsers <- c(extract.docs.file=extract.docs.file,  default.parsers <-
255                       sapply(forall.parsers,function(L)L[[1]](L[[2]])))    c(extra.code.docs=extra.code.docs,
256        sapply(forall.parsers,function(L)L[[1]](L[[2]])),
257        edit.package.file=function(desc,...){
258          in.details <- setdiff(colnames(desc),"Description")
259          details <- paste(paste(in.details,": \\tab ",desc[,in.details],"\\cr",
260                                 sep=""),collapse="\n")
261          L <-
262            list(list(title=desc[,"Title"],
263                      description=desc[,"Description"],
264                      `tabular{ll}`=details,
265                      author=desc[,"Maintainer"]))
266          names(L) <- paste(desc[,"Package"],"-package",sep="")
267          L
268        })
269    
270  extract.docs.fun <- function # Extract documentation from a function  extract.docs.fun <- function # Extract documentation from a function
271  ### Given source code of a function, return a list describing inline  ### Given source code of a function, return a list describing inline
# Line 693  Line 706 
706    invisible(docs)    invisible(docs)
707  }  }
708    
709  extract.docs.code <- function  apply.parsers <- function
710  ### Write code to a file and parse it to r objs, then run all the  ### Parse code to r objs, then run all the parsers and return the
711  ### parsers and return the documentation list.  ### documentation list.
712  (code,  (code,
713  ### Character vector of code lines.  ### Character vector of code lines.
714   parsers,   parsers=default.parsers,
715  ### List of Parser Functions.  ### List of Parser Functions.
716   verbose=TRUE,   verbose=FALSE,
717  ### Echo names of Parser Functions?  ### Echo names of Parser Functions?
718   ...   ...
719  ### Additional arguments to pass to Parser Functions.  ### Additional arguments to pass to Parser Functions.
720   ){   ){
   code.file <- tempfile()  
   writeLines(code,code.file)  
721    e <- new.env()    e <- new.env()
722    old <- options(keep.source.pkgs=TRUE)    old <- options(keep.source.pkgs=TRUE)
723    tryCatch(suppressWarnings(sys.source(code.file,e)),error=function(e){    on.exit(options(old))
724      stop("source ",code.file," failed with error:\n",e)    ##tryCatch({
725    })      exprs <- parse(text=code)
726    options(old)      for (i in exprs) eval(i, e)
727    ##   },error=function(err){
728    ##     print(i)
729    ##     stop("eval or parse failed with error:\n",err)
730    ##   })
731    objs <- sapply(ls(e),get,e,simplify=FALSE)    objs <- sapply(ls(e),get,e,simplify=FALSE)
732    
   ## apply parsers in sequence to code and objs  
733    docs <- list()    docs <- list()
734    
735    # PhG: Automatically determine who is S3 methods    # PhG: Automatically determine who is S3 methods
# Line 736  Line 750 
750          }          }
751      }      }
752    }    }
753      ## apply parsers in sequence to code and objs
754    for(i in seq_along(parsers)){    for(i in seq_along(parsers)){
755      N <- names(parsers[i])      N <- names(parsers[i])
756      if(verbose){      if(verbose){
# Line 752  Line 767 
767    docs    docs
768  ### A list of extracted documentation from code.  ### A list of extracted documentation from code.
769  }  }
770    
771    extract.docs.file <- function
772    ### Apply all parsers relevant to extract info from just 1 code file.
773    (f,
774    ### File name of R code to read and parse.
775     parsers=list(extra.code.docs,default.parsers$parsefun),
776    ### Parser Functions to use to parse the code and extract
777    ### documentation.
778     ...
779    ### Other arguments to pass to Parser Functions.
780     ){
781      apply.parsers(readLines(f),parsers,verbose=FALSE,...)
782    }

Legend:
Removed from v.108  
changed lines
  Added in v.109

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