Rcpp11 / attributes

Standalone implementation of Rcpp attributes.
Other
3 stars 1 forks source link

attribute parser #4

Open romainfrancois opened 10 years ago

romainfrancois commented 10 years ago

we need an R function that parses attributes from a file. Given a file, e.g.

...
// [[ foo::bar ]]
something

the function should return a list of data structures capturing:

romainfrancois commented 10 years ago

e.g.

> txt <- readLines( "/tmp/test.cpp")
> rx <- "^//[[:space:]]*[[][[](.*)[]][]].*"
> where <- grep( rx, txt )
> parse( text = gsub( rx, "\\1", txt[where] ) )
expression(Rcpp::export)
kevinushey commented 10 years ago

Implemented something that returns a list, with components:

romainfrancois commented 10 years ago

I have something too that i cooked up in the train. Sounds similar to what you have but it does some predispatch on the "type" of attribute:

romainfrancois commented 10 years ago

I just also pushed my code. we'll decide later what to do.

romainfrancois commented 10 years ago

I simplified my initial code so that parse_attribute gives a list of things of class "call_attribute" or "assignment_attribute":

> parse_attributes( '/tmp/foo.cpp' )
$attributes
$attributes[[1]]
$file
[1] "/tmp/foo.cpp"

$line
[1] 5

$content
 [1] "#include <Rcpp.h>"      "using namespace Rcpp ;" ""
 [4] ""                       "// [[Rcpp::export]]"    "int foo(int a, "
 [7] "    int b = 22"         "    ){"                 "  return 2 ;"
[10] "}"                      ""

$name
[1] "Rcpp::export"

$param
NULL

attr(,"class")
[1] "call_attribute"

$r_code_chunks
NULL

So this needs the handler called "Rcpp::export" with no param. Not yet sure what a handler is, as it has to have different meaning in the case of sourceCpp and compileAttributes