Title: | Retrieve Code Decorations |
---|---|
Description: | Retrieves code comment decorations for C++ languages of the form '\\ [[xyz]]', which are used for automated wrapping of C++ functions. |
Authors: | Davis Vaughan [aut, cre] |
Maintainer: | Davis Vaughan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.2.9000 |
Built: | 2024-06-07 04:33:01 UTC |
Source: | https://github.com/r-lib/decor |
Decorations in a 'C++' file
cpp_decorations(pkg = ".", files = cpp_files(pkg = pkg), is_attribute = FALSE)
pkg |
The path to a package's root directory. |
files |
Paths to 'C++' files. If given, 'pkg' will not be used. |
is_attribute |
If 'TRUE' the decorations are C++11 attributes, if 'FALSE' they are comments. |
A tibble with the decorations found, containing fields: - file - The filename for the decoration - line - The line the decoration was found - decoration - The name of the decoration - params - Any parameters given with the decoration - context - The text of the decoration line and all lines until the next decoration (or the end of the file).
# Setup
f <- tempfile()
writeLines("[[cpp11::register]] int fun(int x = 1) { return x + 1; }", f)
# Retrieve the decorations in the file
cpp_decorations(files = f, is_attribute = TRUE)
# Cleanup
unlink(f)
'C++' files from a package
cpp_files(pkg = ".")
pkg |
The path to a package's root directory. |
A character vector of 'C++' files found in the package, ordered according to the C locale, for stability across different sessions and platforms.
# Setup
pkg <- tempfile()
dir.create(file.path(pkg, "src"), recursive = TRUE)
file.create(file.path(pkg, "src", "code.c"))
file.create(file.path(pkg, "src", "code.cpp"))
# List the files, only the C++ file will be listed
cpp_files(pkg)
# Cleanup
unlink(pkg, recursive = TRUE)
Parses a C++ function returning a tibble with the function name and return type and a list column with the arguments of the function.
parse_cpp_function(context, is_attribute = FALSE)
context |
The function context, as obtained by the 'context' column from [cpp_decorations()] |
is_attribute |
If 'TRUE' the decorations are C++11 attributes, if 'FALSE' they are comments. |
A tibble with the following fields: - name - The name of the function - return_type - The return type of the function - args - A list column containing a tibble of the functions arguments - type - The type of the argument - name - The name of the argument - default - The default value of the argument (if any).
# Setup
context <- "int fun(int x) { return x + 1; }"
# Parse the function
parse_cpp_function(context)