[−][src]Crate gpp
gpp is a Generic PreProcessor written in Rust.
It supports:
- Simple macros, no function macros
- #include
- #define
- #undef
- #ifdef
- #ifndef
- #elifdef
- #elifndef
- #else
- #endif
#includes work differently from C, as they do not require (and do not work with) quotes or <>,
so #include file.txt
is the correct syntax. It does not support #if or #elif, and recursive
macros will cause the library to get stuck.
This library is heavily inspired by minipre, however this library supports more commands like #define, #undef and #include.
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
Error | Error enum for parsing errors. |
Functions
process_buf | Process a generic BufRead and write to a generic Write. |
process_file | Process a file. |
process_line | Process a string line of input. |
process_str | Process a multi-line string of text. |