[Roxygen-commits] r56 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 19 23:07:46 CEST 2008
Author: pcd
Date: 2008-07-19 23:07:46 +0200 (Sat, 19 Jul 2008)
New Revision: 56
Modified:
pkg/R/Rd.R
pkg/R/parse.R
pkg/R/string.R
Log:
Reduce.paste abstraction; generalized Rd.expression; Rd params; gregexps out; TODO: escaped @
Modified: pkg/R/Rd.R
===================================================================
--- pkg/R/Rd.R 2008-07-19 21:07:34 UTC (rev 55)
+++ pkg/R/Rd.R 2008-07-19 21:07:46 UTC (rev 56)
@@ -1,13 +1,16 @@
#' @include list.R string.R functional.R
Rd <- function(partita) {
- ## TODO: param
+ Rd.expression <- function(key, ...)
+ sprintf('\\%s%s\n',
+ key,
+ Reduce.paste(function(expression)
+ sprintf('{%s}', trim(expression)),
+ c(...),
+ NIL.STRING))
- Rd.expression <- function(key, expression)
- sprintf('\\%s{%s}\n', key, expression)
+ parse.default <- function(key, ...)
+ cat(Rd.expression(key, c(...)))
- parse.default <- function(key, expression)
- cat(Rd.expression(key, trim(expression)))
-
parse.name <- Curry(parse.default, key='name')
parse.title <- Curry(parse.default, key='title')
@@ -49,6 +52,25 @@
parse.default('details', details)
}
+ params <- nil
+
+ parse.param <- function(expression)
+ ## Hack to access persistent `params'
+ assign('params',
+ append(params, list(expression)),
+ envir=parent.env(environment()))
+
+ parse.params <- function(params)
+ Reduce.paste(function(name.param)
+ Rd.expression('item',
+ car(name.param),
+ cadr(name.param)),
+ params,
+ '')
+
+ parse.arguments <- function(params)
+ parse.default('arguments', parse.params(params))
+
parse.noop <- function(expression) NULL
parsers <- list(name=parse.name,
@@ -63,12 +85,17 @@
concept=parse.concept,
aliases=parse.aliases,
keywords=parse.keywords,
- description=parse.description)
+ description=parse.description,
+ param=parse.param)
parser <- function(key)
if (is.null(f <- parsers[[key]])) parse.noop else f
+ ## Parse the rest first for side-effects (i.e. parameter-gathering).
for (partitum in partita)
for (key.value in zip.list(attributes(partitum)$names, partitum))
do.call(parser(car(key.value)), cdr(key.value))
+
+ ## Then parse the arguments.
+ parse.arguments(params)
}
Modified: pkg/R/parse.R
===================================================================
--- pkg/R/parse.R 2008-07-19 21:07:34 UTC (rev 55)
+++ pkg/R/parse.R 2008-07-19 21:07:46 UTC (rev 56)
@@ -180,7 +180,7 @@
caddr(preref))
delimited.lines <-
Filter(function(line) grep(LINE.DELIMITER, line), lines)
- ## Trim LINE.DELIMITER + one space
+ ## Trim LINE.DELIMITER + one space (benign for spaceless delimeters).
trimmed.lines <-
Map(function(line) substr(line, nchar(LINE.DELIMITER) + 2, nchar(line)),
delimited.lines)
@@ -188,6 +188,8 @@
if (is.nil(joined.lines))
nil
else {
+ ## Must be modified (with a PCRE look-behind?) to skip escaped
+ ## TAG.DELIMITERs.
elements <- car(strsplit(joined.lines, TAG.DELIMITER, fixed=T))
description <- car(elements)
parsed.elements <- Reduce(function(parsed, element)
Modified: pkg/R/string.R
===================================================================
--- pkg/R/string.R 2008-07-19 21:07:34 UTC (rev 55)
+++ pkg/R/string.R 2008-07-19 21:07:46 UTC (rev 56)
@@ -14,12 +14,6 @@
is.null.string <- function(string) regexpr(MATTER, string) < 0
-## Major source of inefficiency; resort to a words-string datatype
-## with pre-delineated words?
-words <- function(string) gregexpr(MATTER, string)[[1]]
-
-nwords <- function(string) length(words(string))
-
word.ref <- function(string, n) {
continue <- function(string, n, init) {
word <- regexpr(MATTER, string)
@@ -42,10 +36,11 @@
strcdr <- function(string) {
if (is.null.string(string))
stop('CDRing null-string')
- nwords <- nwords(string)
- if (nwords == 1) NIL.STRING
+ ref <- word.ref(string, 2)
+ if (ref$end < ref$start)
+ NIL.STRING
else
- substr(string, word.ref(string, 2)$start, nchar(string))
+ substr(string, ref$start, nchar(string))
}
strcons <- function(consor, consee, sep) {
@@ -53,8 +48,8 @@
else paste(consor, consee, sep=sep)
}
-## General enough to be designated `map'? Should it preserve
-## non-matter?
+## General enough to be designated `map': isn't it closer to a
+## specialized reduce?
strmap <- function(proc, sep, string) {
continue <- function(string)
if (is.null.string(string))
@@ -69,9 +64,16 @@
debug <- function(...) {
values <- list(...)
var.values <- zip.list(attributes(values)$names, values)
- cat(Reduce(function(pairs, var.value)
- Curry(paste, sep='')
- (pairs, sprintf('%s: %s; ', car(var.value), cadr(var.value))),
- var.values,
- NULL), '\n')
+ cat(Reduce.paste(function(var.value)
+ sprintf('%s: %s; ', car(var.value), cadr(var.value)),
+ var.values,
+ NIL.STRING),
+ '\n')
}
+
+Reduce.paste <- function(proc, elts, sep)
+ Reduce(function(parsed, elt)
+ Curry(paste, sep=sep)
+ (parsed, proc(elt)),
+ elts,
+ NIL.STRING)
More information about the Roxygen-commits
mailing list