Skip to main content

preprocess

Function preprocess 

Source
pub fn preprocess(
    input: String,
    origin: Option<PathBuf>,
    includefolders: &[PathBuf],
    warnings: &mut dyn WarningSink,
) -> Result<(String, PreprocessInfo), Error>
Expand description

Reads input string and returns preprocessed string with an info struct containing the origins of the lines in the output.

path is the path to the input if it is known and is used for relative includes and error messages. includefolders are the folders searched recursively for absolute includes (see IncludeFolders for folders that are only checked directly).

§Errors

Returns an error on parse failures, unreadable includes or invalid include folders.

§Examples

let input = String::from("
#define QUOTE(x) #x
#define DOUBLES(x,y) x##_##y

foo = QUOTE(DOUBLES(abc, xyz));
");

let (output, _) = preprocess(input, None, &Vec::new(), &mut Warnings::new()).expect("Failed to preprocess");

assert_eq!("foo = \"abc_xyz\";", output.trim());