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 104, Tue May 18 16:35:08 2010 UTC revision 106, Tue May 18 17:39:20 2010 UTC
# Line 88  Line 88 
88  ### Parse R code to extract inline documentation from comments around  ### Parse R code to extract inline documentation from comments around
89  ### each function. These are not able to be retreived simply by  ### each function. These are not able to be retreived simply by
90  ### looking at the "source" attribute. This is a Parser Function that  ### looking at the "source" attribute. This is a Parser Function that
91  ### can be used in the parser list of package.skeleton.dx().  ### can be used in the parser list of package.skeleton.dx(). TODO:
92    ### Modularize this into separate Parser Functions for S4 classes,
93    ### prefixes, ##<< blocks, etc. Right now it is not very clean!
94  (code,  (code,
95  ### Code lines in a character vector containing multiple R objects to  ### Code lines in a character vector containing multiple R objects to
96  ### parse for documentation.  ### parse for documentation.
# Line 637  Line 639 
639    }    }
640    invisible(docs)    invisible(docs)
641  }  }
642    
643    extract.docs.code <- function
644    ### Write code to a file and parse it to r objs, then run all the
645    ### parsers and return the documentation list.
646    (code,
647    ### Character vector of code lines.
648     parsers,
649    ### List of Parser Functions.
650     verbose=TRUE,
651    ### Echo names of Parser Functions?
652     ...
653    ### Additional arguments to pass to Parser Functions.
654     ){
655      code.file <- tempfile()
656      writeLines(code,code.file)
657      e <- new.env()
658      old <- options(keep.source.pkgs=TRUE)
659      tryCatch(suppressWarnings(sys.source(code.file,e)),error=function(e){
660        stop("source ",code.file," failed with error:\n",e)
661      })
662      options(old)
663      objs <- sapply(ls(e),get,e,simplify=FALSE)
664    
665      ## apply parsers in sequence to code and objs
666      docs <- list()
667      for(i in seq_along(parsers)){
668        N <- names(parsers[i])
669        if(verbose){
670          if(is.character(N) && N!=""){
671            cat(N," ",sep="")
672          }else cat('. ')
673        }
674        p <- parsers[[i]]
675        ## This is the argument list that each parser receives:
676        L <- p(code=code,objs=objs,docs=docs,...)
677        docs <- combine(docs,L)
678      }
679      if(verbose)cat("\n")
680      docs
681    ### A list of extracted documentation from code.
682    }

Legend:
Removed from v.104  
changed lines
  Added in v.106

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