[Roxygen-commits] r20 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 3 02:42:10 CEST 2008


Author: pcd
Date: 2008-06-03 02:42:10 +0200 (Tue, 03 Jun 2008)
New Revision: 20

Modified:
   pkg/R/list.R
   pkg/R/parse.R
Log:
parse srcrefs


Modified: pkg/R/list.R
===================================================================
--- pkg/R/list.R	2008-06-02 18:10:40 UTC (rev 19)
+++ pkg/R/list.R	2008-06-03 00:42:10 UTC (rev 20)
@@ -11,6 +11,10 @@
   list[2:length(list)]
 }
 
+caar <- function(list) {
+  car(car(list))
+}
+
 cadr <- function(list) {
   car(cdr(list))
 }
@@ -23,6 +27,10 @@
   car(cddr(list))
 }
 
+cadar <- function(list) {
+  cadr(car(list))
+}
+
 is.even <- function(a) {
   a %% 2 == 0
 }

Modified: pkg/R/parse.R
===================================================================
--- pkg/R/parse.R	2008-06-02 18:10:40 UTC (rev 19)
+++ pkg/R/parse.R	2008-06-03 00:42:10 UTC (rev 20)
@@ -1,4 +1,5 @@
 source('list.R')
+source('functional.R')
 
 LINE.DELIMITER <- '#\''
 TAG.DELIMITER <- '@'
@@ -34,13 +35,17 @@
   append(parse.ref(car(preref.srcref)),
          parse.ref(cadr(preref.srcref)))
 
-parse.default <- function(...) {
+parse.preref <- function(...) {
   list(unknown=paste(...))
 }
 
+parse.srcref <- function(...) {
+  nil
+}
+
 parse.element <- function(element) {
   tokens <- car(strsplit(element, ' ', fixed=T))
-  parser <- parser(car(tokens))
+  parser <- parser.preref(car(tokens))
   do.call(parser, as.list(cdr(tokens)))
 }
 
@@ -60,11 +65,18 @@
 
 parse.param <- parse.name.description
 
-parser <- function(key) {
+parse.setClass <- function(expression)
+  list(class=cadr(car(expression)))
+
+parser.default <- function(key, default) {
   f <- sprintf('parse.%s', key)
-  if (length(ls(1, pattern=f)) > 0) f else parse.default
+  if (length(ls(1, pattern=f)) > 0) f else default
 }
 
+parser.preref <- Curry(parser.default, default=parse.preref)
+
+parser.srcref <- Curry(parser.default, default=parse.srcref)
+
 paste.list <- function(list) {
   do.call(paste, list)
 }
@@ -89,9 +101,17 @@
                             cdr(elements), parse.description(car(elements)))
 } 
 
-parse.ref.srcref <- function(srcref)
-  list(srcref=list(filename=attributes(srcref)$srcfile$filename,
-         lloc=as.vector(srcref)))
+parse.ref.srcref <- function(srcref) {
+  srcfile <- attributes(srcref)$srcfile
+  lines <- getSrcLines(srcfile, car(srcref), caddr(srcref))
+  expression <- parse(text=lines)
+  pivot <- caar(expression)
+  parser <- parser.srcref(as.character(pivot))
+  append(do.call(parser, list(expression)),
+         list(srcref=list(filename=attributes(srcref)$srcfile$filename,
+                lloc=as.vector(srcref))))
+         
+}
 
 parse.refs <- function(prerefs.srcrefs)
   Map(parse.ref, prerefs.srcrefs)



More information about the Roxygen-commits mailing list