[Roxygen-commits] r60 - in pkg: R sandbox

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jul 20 07:07:59 CEST 2008


Author: pcd
Date: 2008-07-20 07:07:59 +0200 (Sun, 20 Jul 2008)
New Revision: 60

Added:
   pkg/R/roclet.R
Modified:
   pkg/R/namespace.R
   pkg/sandbox/namespace.R
Log:
namespace roclet in generic style, no closure


Modified: pkg/R/namespace.R
===================================================================
--- pkg/R/namespace.R	2008-07-20 05:07:46 UTC (rev 59)
+++ pkg/R/namespace.R	2008-07-20 05:07:59 UTC (rev 60)
@@ -1,31 +1,23 @@
+#' @include roclet.R
 #' @include string.R
-#' @include functional.R
-#' @include list.R
-#' Revamp to use noop; relevata-model unnecessary.
-namespace <- function(partita) {
-  parse.default <- function(proc, parms)
-    cat(sprintf('%s(%s)\n', proc, strmap(Identity, ', ', parms)))
+parse.namespace.directive <- function(proc, parms)
+  cat(sprintf('%s(%s)\n', proc, strmap(Identity, ', ', parms)))
   
-  parsers <- list(exportClass=function(proc, parms)
-                  parse.default('exportClasses', parms),
-                  exportMethod=function(proc, parms)
-                  parse.default('exportMethods', parms),
-                  export=parse.default,
-                  exportPattern=parse.default,
-                  S3method=parse.default,
-                  import=parse.default,
-                  importFrom=parse.default,
-                  importClassesFrom=parse.default,
-                  importMethodsFrom=parse.default)
+namespace.roclet <- roclet(parse.namespace.directive)
 
-  parse.noop <- function(procedure, parameters) NULL
+namespace.roclet$register.parser('exportClass',
+                                 function(proc, parms)
+                                 default.parse('exportClasses', parms))
+namespace.roclet$register.parser('exportMethod',
+                                 function(proc, parms)
+                                 default.parse('exportMethods', parms))
 
-  parser <- function(procedure)
-    if (is.null(f <- parsers[[procedure]])) parse.noop else f
+namespace.roclet$register.default.parser('export')
+namespace.roclet$register.default.parser('exportPattern')
+namespace.roclet$register.default.parser('S3method')
+namespace.roclet$register.default.parser('import')
+namespace.roclet$register.default.parser('importFrom')
+namespace.roclet$register.default.parser('importClassesFrom')
+namespace.roclet$register.default.parser('importMethodsFrom')
 
-  for (partitum in partita)
-    for (key.value in key.values(partitum)) {
-      key <- car(key.value)
-      do.call(parser(key), list(key, cdr(key.value)))
-    }
-}
+namespace.roclet <- namespace.roclet$parse

Added: pkg/R/roclet.R
===================================================================
--- pkg/R/roclet.R	                        (rev 0)
+++ pkg/R/roclet.R	2008-07-20 05:07:59 UTC (rev 60)
@@ -0,0 +1,30 @@
+#' @include list.R
+roclet <- function(parse.default) {
+  roclet <- new.env(parent=emptyenv())
+
+  roclet$parsers <- list()
+
+  roclet$register.parser <- function(key, parser)
+    roclet$parsers[[key]] <- parser
+
+  roclet$register.default.parser <- function(key)
+    roclet$parsers[[key]] <- parse.default
+
+  roclet$parse <- function(partita) {
+    key.values <- function(partitum)
+      zip.list(attributes(partitum)$names, partitum)
+    
+    parse.noop <- function(key, value) NULL
+
+    parser <- function(key)
+      if (is.null(f <- roclet$parsers[[key]])) parse.noop else f
+
+    for (partitum in partita)
+      for (key.value in key.values(partitum)) {
+        key <- car(key.value)
+        do.call(parser(key), list(key, cdr(key.value)))
+      }
+  }
+
+  roclet
+}

Modified: pkg/sandbox/namespace.R
===================================================================
--- pkg/sandbox/namespace.R	2008-07-20 05:07:46 UTC (rev 59)
+++ pkg/sandbox/namespace.R	2008-07-20 05:07:59 UTC (rev 60)
@@ -13,4 +13,4 @@
 argc <- length(argv)
 files <- if (argc > 0) as.list(argv) else FILES
 
-namespace(do.call(parse.files, files))
+namespace.roclet(do.call(parse.files, files))



More information about the Roxygen-commits mailing list