pub fn preprocess<'s>(
src: impl Iterator<Item = SpannedToken<'s>>,
state: &mut PreprocessorState<'s>,
cache: &'s PreprocessorCache<'s>,
) -> Result<Vec<SpannedToken<'s>>, ()>Expand description
Preprocess the given token stream, elaborating any compiler directives
state is augmented during preprocessing (and can be examined afterwards,
likely to inspect any errors found), and cache is used to retain any new
files/spans found during preprocessing
preprocess returns the elaborated stream, as well as whether the
initial stream was consumed completely (false if an irrecoverable
error was encountered)
let file_contents = "
`define TEST(a, b) a + b
`TEST(1, 2)
";
let tokens = lex(file_contents, "test_file.v").tokens();
let mut pp_tokens = preprocess(tokens, &mut state, &cache).unwrap().into_iter();
assert_eq!(pp_tokens.next().unwrap().0, Token::UnsignedNumber("1"));
assert_eq!(pp_tokens.next().unwrap().0, Token::Plus);
assert_eq!(pp_tokens.next().unwrap().0, Token::UnsignedNumber("2"));
assert_eq!(pp_tokens.next(), None)