Open romainfrancois opened 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)
Implemented something that returns a list
, with components:
string
: The actual line of code,code
: The code within the // [[...]]
attribute,expr
: The code parsed as an R expression,index
: The line number where the attribute was found,file
: The file name.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:
symbol
!debug
foo(...)
bar::foo(...)
foo::bar
I just also pushed my code. we'll decide later what to do.
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
we need an R function that parses attributes from a file. Given a file, e.g.
the function should return a list of data structures capturing:
parse( text = "foo::bar" )
s
ofsomething
.