[][src]Crate gpp

gpp is a Generic PreProcessor written in Rust.

It supports:

  • Simple macros, no function macros
  • #define
  • #undef
  • #ifdef
  • #ifndef
  • #elifdef
  • #elifndef
  • #else
  • #endif

It does not support #if or #elif.

This library is heavily inspired by minipre, however this library supports more commands like #define-s and #undef-s.

Examples

// Create a context for preprocessing
let mut context = gpp::Context::new();

// Add a macro to that context manually (context.macros is a HashMap)
context.macros.insert(String::from("my_macro"), String::from("my_value"));

// Process some text using that
assert_eq!(gpp::process_str("My macro is my_macro\n", &mut context).unwrap(), "My macro is my_value\n");

// Process some multi-line text, changing the context
assert_eq!(gpp::process_str("
    #define Line Row
    Line One
    Line Two
    The Third Line", &mut context).unwrap(), "
    Row One
    Row Two
    The Third Row\n");

// The context persists
assert_eq!(context.macros.get("Line").unwrap(), "Row");

// Try some more advanced statements
assert_eq!(gpp::process_str("
    Line Four
    #ifdef Line
    #undef Line
    #endif
    Line Five", &mut context).unwrap(), "
    Row Four
    Line Five\n");

Structs

Context

Context of the current processing.

LineError

Error struct for errors and a line number.

Enums

BufError

Error enum for errors caused by BufRead.

Error

Error enum for parsing errors.

Functions

process_buf

Process a generic BufRead.

process_line

Process a string line of input.

process_str

Process a multi-line string of text.