Rcpp11 / attributes

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

Parsing tools #12

Open kevinushey opened 10 years ago

kevinushey commented 10 years ago

I added a couple of R level tools in utils.R, but those that search for characters are surely too slow. They could be written in C for efficiency.

FWIW, I find it's much easier to parse files as one big string with newlines embedded, rather than per line, so some of them are implemented with that expectation.

romainfrancois commented 10 years ago

that's probably something we can do in C++ indeed. Maybe borrow from @jjallaire parsing code in Rcpp.

romainfrancois commented 10 years ago

I'm borrowing a few lines of code from @jjallaire in the parse_cpp_function function:

With this file:

#include <Rcpp.h>
using namespace Rcpp ;

// [[Rcpp::export]]
int foo(int a, 
    int b = 22
    ){
  return 2 ;
}

I get:

> txt <- readLines( "/tmp/foo.cpp" )
> sign <- .Call( "parse_cpp_function", txt, 5L )
> sign
$name
[1] "foo"

$return_type
[1] "int"

$arguments
$arguments$a
   type default
  "int"      NA

$arguments$b
   type default
  "int"    "22"

Should get us started.