Learn R Programming

treesitter.c (version 0.0.4.2)

preprocess_header: Run the C preprocessor on file using the provided compiler

Description

This function runs the configured C compiler with the -E preprocessor flag and returns the combined preprocessed output as a single string.

Usage

preprocess_header(file, cc = r_cc(), ccflags = NULL, ...)

Value

Character scalar with the preprocessed output of file.

Arguments

file

Path to a header file to preprocess.

cc

(Character) Compiler command to use. If NULL, resolved via r_cc().

ccflags

(Character) Additional flags to pass to the compiler.

...

Arguments passed on to preprocess_headers

dir

Directory where header files will be searched.

recursive

Logical; whether to search recursively.

pattern

File name pattern(s) used to identify header files.

Examples

Run this code
if (FALSE) {
# Check for a compiler before running an example that invokes the preprocessor
rcc <- treesitter.c::r_cc()
if (nzchar(rcc)) {
  rcc_prog <- strsplit(rcc, "\\s+")[[1]][1]
  if (nzchar(Sys.which(rcc_prog))) {
    tmp <- tempfile("hdr3")
    dir.create(tmp)
    path <- file.path(tmp, "p.h")
    writeLines(c("#define TYPE int", "TYPE foo(TYPE x);"), path)
    out <- preprocess_header(path)
    grepl("int foo\\(", out)
  } else {
    message("Skipping preprocess example: compiler not found on PATH")
  }
}
}

Run the code above in your browser using DataLab