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 102, Fri May 14 18:48:40 2010 UTC revision 105, Tue May 18 17:32:43 2010 UTC
# Line 67  Line 67 
67                   "((?:\\n###[^\\n]*)+)",#comment value lines \\1                   "((?:\\n###[^\\n]*)+)",#comment value lines \\1
68                   "([\\w\\W]*)[}]",#examples \\2                   "([\\w\\W]*)[}]",#examples \\2
69                   sep="")                   sep="")
70           SEP <- "----------"           SEP <- "-/-/-/-/-=====-----"
71           REP <- paste("\\1",SEP,"\\2",sep="")           REP <- paste("\\1",SEP,"\\2",sep="")
72           r <- strsplit(gsub(FIND,REP,after,perl=TRUE),split=SEP)[[1]]           r <- strsplit(gsub(FIND,REP,after,perl=TRUE),split=SEP)[[1]]
73           l <- strsplit(r,split="\n")           l <- strsplit(r,split="\n")
          if(length(l)<2||l[[2]]=="")return(list())  
74           excode <- c(l[[2]],"")           excode <- c(l[[2]],"")
75             if(length(l)<2||paste(excode,collapse="")=="")return(list())
76           prefixes <- gsub("(\\s*).*","\\1",excode,perl=TRUE)[grep("\\w",excode)]           prefixes <- gsub("(\\s*).*","\\1",excode,perl=TRUE)[grep("\\w",excode)]
77           FIND <- prefixes[which.min(nchar(prefixes))]           FIND <- prefixes[which.min(nchar(prefixes))]
78           list(examples=paste(sub(FIND,"",excode),collapse="\n"),           list(examples=paste(sub(FIND,"",excode),collapse="\n"),
# Line 637  Line 637 
637    }    }
638    invisible(docs)    invisible(docs)
639  }  }
640    
641    extract.docs.code <- function
642    ### Write code to a file and parse it to r objs, then run all the
643    ### parsers and return the documentation list.
644    (code,
645    ### Character vector of code lines.
646     parsers,
647    ### List of Parser Functions.
648     verbose=TRUE,
649    ### Echo names of Parser Functions?
650     ...
651    ### Additional arguments to pass to Parser Functions.
652     ){
653      code.file <- tempfile()
654      writeLines(code,code.file)
655      e <- new.env()
656      old <- options(keep.source.pkgs=TRUE)
657      tryCatch(suppressWarnings(sys.source(code.file,e)),error=function(e){
658        stop("source ",code.file," failed with error:\n",e)
659      })
660      options(old)
661      objs <- sapply(ls(e),get,e,simplify=FALSE)
662    
663      ## apply parsers in sequence to code and objs
664      docs <- list()
665      for(i in seq_along(parsers)){
666        N <- names(parsers[i])
667        if(verbose){
668          if(is.character(N) && N!=""){
669            cat(N," ",sep="")
670          }else cat('. ')
671        }
672        p <- parsers[[i]]
673        ## This is the argument list that each parser receives:
674        L <- p(code=code,objs=objs,docs=docs,...)
675        docs <- combine(docs,L)
676      }
677      if(verbose)cat("\n")
678      docs
679    ### A list of extracted documentation from code.
680    }

Legend:
Removed from v.102  
changed lines
  Added in v.105

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