Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Skip whitespaces in preprocessor #462

Merged
merged 6 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lex/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ int main(){}
assert_same_exact("#define f(a) <a>\nf ", "\nf ");
assert_same_exact("#define f(a) <a>\nf ;", "\nf ;");
assert_same_exact("#define f(a) <a>\nf;", "\nf;");
assert_same_exact("#define f(a) 1\n#define h f (2)\nh", "\n1");
}

#[test]
Expand Down
13 changes: 8 additions & 5 deletions src/lex/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,16 @@ fn replace_function(
data: Token::Whitespace(_),
..
})) => {
let spaces = inner.next().unwrap();
let spaces = incoming.pop_front().or_else(|| inner.next()).unwrap();
let left_paren = incoming.front().or_else(|| inner.peek());
if let Some(Ok(Locatable {
data: Token::LeftParen,
..
})) = inner.peek()
})) = left_paren
{
inner.next();
if incoming.pop_front().is_none() {
inner.next();
}
break;
}
let id_token = Ok(location.with(Token::Id(id)));
Expand All @@ -246,8 +249,8 @@ fn replace_function(
// If this branch is matched, this is not a macro call,
// since all other cases are covered above.
// So just append the identifier and the current token to the stack.
Some(Ok(Locatable { data: _, .. })) => {
let token = inner.next().unwrap();
Some(Ok(_)) => {
let token = incoming.pop_front().or_else(|| inner.next()).unwrap();
hdamron17 marked this conversation as resolved.
Show resolved Hide resolved
let id_token = Ok(location.with(Token::Id(id)));
errors.push(id_token);
errors.push(token);
Expand Down