[Roxygen-commits] r63 - in pkg: R sandbox sandbox/collate
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jul 20 07:08:38 CEST 2008
Author: pcd
Date: 2008-07-20 07:08:38 +0200 (Sun, 20 Jul 2008)
New Revision: 63
Added:
pkg/R/collate.R
pkg/sandbox/collate.R
pkg/sandbox/collate/
pkg/sandbox/collate/belt.R
pkg/sandbox/collate/jacket.R
pkg/sandbox/collate/pants.R
pkg/sandbox/collate/shirt.R
pkg/sandbox/collate/shoes.R
pkg/sandbox/collate/socks.R
pkg/sandbox/collate/tie.R
pkg/sandbox/collate/undershorts.R
pkg/sandbox/collate/watch.R
Modified:
pkg/R/Rd.R
pkg/R/namespace.R
pkg/R/parse.R
pkg/R/roclet.R
Log:
collation via topological sort (not quite right)
Modified: pkg/R/Rd.R
===================================================================
--- pkg/R/Rd.R 2008-07-20 05:08:22 UTC (rev 62)
+++ pkg/R/Rd.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -60,7 +60,7 @@
parse.param <- function(key, expression)
assign.parent('params',
- append(params, expression),
+ append(params, list(expression)),
environment())
parse.params <- function()
Added: pkg/R/collate.R
===================================================================
--- pkg/R/collate.R (rev 0)
+++ pkg/R/collate.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,66 @@
+#' @include roclet.R
+#' @include string.R
+make.collate.roclet <- function() {
+ vertices <- NULL
+
+ make.vertex <- function(file) {
+ vertex <- new.env(parent=emptyenv())
+ vertex$file <- trim(file)
+ vertex$discovered <- -1
+ vertex$finished <- -1
+ vertex$predecessor <- NULL
+ vertex$ancestors <- NULL
+ vertex$is.discovered <-
+ function() vertex$discovered >= 0
+ vertex$is.finished <-
+ function() vertex$discovered >= 0
+ structure(vertex, class='vertex')
+ }
+
+ maybe.append.vertex <- function(file) {
+ file <- trim(file)
+ if (is.null(vertices[[file]]))
+ assign.parent('vertices',
+ append(vertices,
+ as.list(structure(c(make.vertex(file)),
+ names=file))),
+ environment())
+ }
+
+ parse.include <- function(key, file)
+ maybe.append.vertex(file)
+
+ pre.parse <- function(partitum)
+ maybe.append.vertex(partitum$srcref$filename)
+
+ topological.sort <- function(vertices) {
+ time <- 0
+ sorted <- NULL
+ visit <- function(predecessor) {
+ assign.parent('time', time + 1, environment())
+ predecessor$discovered <- time
+ for (ancestor in predecessor$ancestors)
+ if (!ancestor$is.discovered()) {
+ ancestor$predecessor <- predecessor
+ visit(ancestor)
+ }
+ predecessor$finished <- time
+ assign.parent('sorted',
+ append(predecessor$file, sorted),
+ environment())
+ }
+ for (vertex in vertices)
+ if (!vertex$is.discovered())
+ visit(vertex)
+ }
+
+ post.files <- function() print(topological.sort(vertices))
+
+ roclet <- make.roclet(parse.include,
+ pre.parse=pre.parse,
+ post.files=post.files)
+
+ roclet$register.default.parser('include')
+
+ roclet
+}
Modified: pkg/R/namespace.R
===================================================================
--- pkg/R/namespace.R 2008-07-20 05:08:22 UTC (rev 62)
+++ pkg/R/namespace.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -7,11 +7,11 @@
roclet <- make.roclet(parse.directive)
roclet$register.parser('exportClass',
- function(proc, parms)
- default.parse('exportClasses', parms))
+ function(proc, parms)
+ parse.directive('exportClasses', parms))
roclet$register.parser('exportMethod',
- function(proc, parms)
- default.parse('exportMethods', parms))
+ function(proc, parms)
+ parse.directive('exportMethods', parms))
roclet$register.default.parsers('export',
'exportPattern',
Modified: pkg/R/parse.R
===================================================================
--- pkg/R/parse.R 2008-07-20 05:08:22 UTC (rev 62)
+++ pkg/R/parse.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -4,7 +4,7 @@
TAG.DELIMITER <- '@'
#' No-op for sourceless files
-roxygen <- NULL
+roxygen <- function() NULL
#' Comment blocks (possibly null) that precede a file's expressions.
prerefs <- function(srcfile, srcrefs) {
@@ -227,15 +227,15 @@
srcfile <- attributes(srcref)$srcfile
lines <- getSrcLines(srcfile, car(srcref), caddr(srcref))
expression <- parse(text=lines)
+ parsed <- list(srcref=list(filename=srcfile$filename,
+ lloc=as.vector(srcref)))
pivot <- tryCatch(caar(expression), error=function(e) NULL)
- if (is.null(pivot))
- nil
- else {
+ if (!is.null(pivot)) {
parser <- parser.srcref(as.character(pivot))
- append(do.call(parser, list(expression)),
- list(srcref=list(filename=srcfile$filename,
- lloc=as.vector(srcref))))
+ parsed <- append(do.call(parser, list(expression)),
+ parsed)
}
+ parsed
}
parse.refs <- function(preref.srcrefs)
@@ -247,11 +247,8 @@
srcfile=srcfile))$srcref
if (length(srcrefs) > 0)
parse.refs(zip.list(prerefs(srcfile, srcrefs), srcrefs))
- else {
- warning(sprintf('%s has no statements (not even `roxygen\')',
- srcfile$filename))
+ else
nil
- }
}
parse.files <- function(...)
Modified: pkg/R/roclet.R
===================================================================
--- pkg/R/roclet.R 2008-07-20 05:08:22 UTC (rev 62)
+++ pkg/R/roclet.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -1,7 +1,9 @@
#' @include list.R
make.roclet <- function(parse.default,
pre.parse=NULL,
- post.parse=NULL) {
+ post.parse=NULL,
+ pre.files=NULL,
+ post.files=NULL) {
roclet <- new.env(parent=emptyenv())
roclet$parsers <- list()
@@ -33,17 +35,19 @@
if (!is.null(proc))
do.call(proc, list(...))
+ maybe.call(pre.files)
for (partitum in parse.files(...)) {
maybe.call(pre.parse, partitum)
for (key.value in key.values(partitum)) {
key <- car(key.value)
- do.call(parser(key), list(key, cdr(key.value)))
+ do.call(parser(key), c(key, cdr(key.value)))
}
maybe.call(post.parse, partitum)
}
+ maybe.call(post.files)
}
- roclet
+ structure(roclet, class='roclet')
}
assign.parent <- function(var, value, env)
Added: pkg/sandbox/collate/belt.R
===================================================================
--- pkg/sandbox/collate/belt.R (rev 0)
+++ pkg/sandbox/collate/belt.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,3 @@
+#' @include collate/pants.R
+#' @include collate/shirt.R
+roxygen()
Added: pkg/sandbox/collate/jacket.R
===================================================================
--- pkg/sandbox/collate/jacket.R (rev 0)
+++ pkg/sandbox/collate/jacket.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,3 @@
+#' @include collate/tie.R
+#' @include collate/belt.R
+roxygen()
Added: pkg/sandbox/collate/pants.R
===================================================================
--- pkg/sandbox/collate/pants.R (rev 0)
+++ pkg/sandbox/collate/pants.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,2 @@
+#' @include collate/undershorts.R
+roxygen()
Added: pkg/sandbox/collate/shirt.R
===================================================================
--- pkg/sandbox/collate/shirt.R (rev 0)
+++ pkg/sandbox/collate/shirt.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1 @@
+roxygen()
Added: pkg/sandbox/collate/shoes.R
===================================================================
--- pkg/sandbox/collate/shoes.R (rev 0)
+++ pkg/sandbox/collate/shoes.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,4 @@
+#' @include collate/socks.R
+#' @include collate/undershorts.R
+#' @include collate/pants.R
+roxygen()
Added: pkg/sandbox/collate/socks.R
===================================================================
--- pkg/sandbox/collate/socks.R (rev 0)
+++ pkg/sandbox/collate/socks.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1 @@
+roxygen()
Added: pkg/sandbox/collate/tie.R
===================================================================
--- pkg/sandbox/collate/tie.R (rev 0)
+++ pkg/sandbox/collate/tie.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,2 @@
+#' @include collate/shirt.R
+roxygen()
Added: pkg/sandbox/collate/undershorts.R
===================================================================
--- pkg/sandbox/collate/undershorts.R (rev 0)
+++ pkg/sandbox/collate/undershorts.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1 @@
+roxygen()
Added: pkg/sandbox/collate/watch.R
===================================================================
--- pkg/sandbox/collate/watch.R (rev 0)
+++ pkg/sandbox/collate/watch.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1 @@
+roxygen()
Added: pkg/sandbox/collate.R
===================================================================
--- pkg/sandbox/collate.R (rev 0)
+++ pkg/sandbox/collate.R 2008-07-20 05:08:38 UTC (rev 63)
@@ -0,0 +1,32 @@
+source('../R/functional.R')
+source('../R/list.R')
+source('../R/parse.R')
+source('../R/string.R')
+source('../R/roclet.R')
+source('../R/collate.R')
+
+FILES <- list('collate/belt.R',
+ 'collate/jacket.R',
+ 'collate/pants.R',
+ 'collate/shirt.R',
+ 'collate/shoes.R',
+ 'collate/socks.R',
+ 'collate/tie.R',
+ 'collate/undershorts.R',
+ 'collate/watch.R')
+
+argv <- commandArgs(trailingOnly=T)
+argc <- length(argv)
+files <- ifelse(argc > 0, as.list(argv), FILES)
+
+roclet <- make.collate.roclet()
+## do.call(roclet$parse, files)
+roclet$parse('collate/belt.R',
+ 'collate/jacket.R',
+ 'collate/pants.R',
+ 'collate/shirt.R',
+ 'collate/shoes.R',
+ 'collate/socks.R',
+ 'collate/tie.R',
+ 'collate/undershorts.R',
+ 'collate/watch.R')
More information about the Roxygen-commits
mailing list