Parse C header files for function declarations using tree-sitter
Source:R/parse-headers.R
parse_r_include_headers.RdThis utility uses the C language provided by this package and the
treesitter parser to find function declarations and definitions in
C header files. The default dir is R.home("include"), which is
typically where R's headers live.
Arguments
- dir
Directory to search for header files. Defaults to
R.home("include").- recursive
Whether to search recursively for headers. Default
TRUE.- pattern
File name pattern to match header files. Default is
\.h$and\.H$.- preprocess
Run the C preprocessor (using R's configured CC) on header files before parsing. Defaults to
FALSE.- cc
The C compiler to use for preprocessing. If
NULLthe function queriesR CMD config CCand falls back toSys.getenv("CC")and theccon PATH.- ccflags
Extra flags to pass to the compiler when preprocessing. If
NULLflags are taken fromR CMD config CFLAGSandR CMD config CPPFLAGS.- include_dirs
Additional directories to add to the include path for preprocessing. A character vector of directories.
- ...
Arguments passed on to
parse_headers_collectextract_paramsLogical; whether to extract parameter types for functions. Default
FALSE.extract_returnLogical; whether to extract return types for functions. Default
FALSE.
Examples
if (requireNamespace("treesitter", quietly = TRUE)) {
# Parse a small header file from a temp dir
tmp <- tempdir()
path <- file.path(tmp, "example.h")
writeLines(c(
"int foo(int a);",
"static inline int bar(void) { return 1; }"
), path)
parse_r_include_headers(dir = tmp)
}
#> name file line kind
#> 1 foo /tmp/RtmpgquING/example.h 1 declaration
#> 2 bar /tmp/RtmpgquING/example.h 2 definition