extendr / rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically
https://extendr.github.io/rextendr/
Other
196 stars 28 forks source link

`{rextendr}` parser cannot handle `#[extendr]` attributes with parentheses #138

Closed Ilia-Kosenkov closed 3 years ago

Ilia-Kosenkov commented 3 years ago

extendr now can be configured by providing different flags to the #[extendr] attribute. The current implementation of {rextendr} parser, which determine what exports should be generated, is unable to handle parentheses in the attribute, see output below

# No parentheses, works fine  
rextendr:::find_exports(c("#[extendr]", "fn test_fn() {}"))  
#> # A tibble: 1 x 3
#>   name    type  lifetime
#>   <chr>   <chr> <chr>   
#> 1 test_fn fn    <NA>

# Semantically the same, but parser fails because of parentheses
rextendr:::find_exports(c("#[extendr()]", "fn test_fn() {}"))
#> Error: Problem with `mutate()` input `..1`.
#> x Column `name` not found in `.data`
#> i Input `..1` is `.data$name`.

Created on 2021-08-23 by the reprex package (v2.0.0)

Somewhat related to #131

clauswilke commented 3 years ago

I thought we recently committed a fix for this (#130). Is it only empty parentheses that cause issues?

yutannihilation commented 3 years ago

I didn't expect empty parentheses. We can fix here, if necessary.

https://github.com/extendr/rextendr/blob/31c3cd331b0923f17da22c0f27d2168c2014f1e7/R/find_exports.R#L21

Ilia-Kosenkov commented 3 years ago

I probably lost track of implemented changes, let me double-check this.

Ilia-Kosenkov commented 3 years ago

Ok, it indeed fails if there is nothing in parentheses:

# Equivalent to
# #[extendr()]
# fn test_fn() {}
rextendr:::find_exports(c("#[extendr()]",  "fn test_fn () {}"))
#> Error: Problem with `mutate()` input `..1`.
#> i `..1 = .data$name`.
#> x Column `name` not found in `.data`

# Works if space is put into the parentheses
# #[extendr( )]
# fn test_fn() {}
rextendr:::find_exports(c("#[extendr( )]",  "fn test_fn () {}"))
#> # A tibble: 1 x 3
#>   name    type  lifetime
#>   <chr>   <chr> <chr>   
#> 1 test_fn fn    <NA>

packageDescription("rextendr")$GithubSHA1
#> [1] "31c3cd331b0923f17da22c0f27d2168c2014f1e7"

Created on 2021-08-23 by the reprex package (v2.0.1)