Skip to content

Commit

Permalink
Preprocessor: handle # in root arguments with quote (#577)
Browse files Browse the repository at this point in the history
* Preprocessor: handle # in root arguments with quote

* fmt comment
  • Loading branch information
BrettMayson authored Oct 15, 2023
1 parent c56252a commit 7323c1a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion libs/preprocessor/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ impl Processor {
}
(Symbol::Directive, false) => {
let token = stream.next().expect("peeked above");
if in_macro.is_some() && stream.peek().map_or(false, |t| t.symbol().is_word()) {
if in_macro.is_some()
&& stream.peek().map_or(false, |t| t.symbol().is_word())
// check if the # token is from another file, or defined before the callsite, ie not in the root arguments
&& (token.position().path() != callsite.unwrap().path()
|| token.position().start().0 < callsite.unwrap().start().0)
{
self.output(
Token::new(Symbol::DoubleQuote, token.position().clone()),
buffer,
Expand Down
11 changes: 6 additions & 5 deletions libs/preprocessor/tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,35 @@ bootstrap!(cba_is_admin);
bootstrap!(cba_multiline);
bootstrap!(comment_edgecase);
bootstrap!(define_builtin);
bootstrap!(define_function);
bootstrap!(define_function_empty);
bootstrap!(define_function_multiline);
bootstrap!(define_function);
bootstrap!(define_inside_else);
bootstrap!(define_multi);
bootstrap!(define_nested);
bootstrap!(define_nested_nested);
bootstrap!(define_nested);
bootstrap!(define_single);
bootstrap!(define_undef);
bootstrap!(define_use_define);
bootstrap!(define_with_dash);
bootstrap!(hashtag_outside_macro);
bootstrap!(if_nested);
bootstrap!(if_operators);
bootstrap!(if_pass);
bootstrap!(if_read);
bootstrap!(if_value);
bootstrap!(ignore_quoted);
bootstrap!(include);
bootstrap!(include_empty);
bootstrap!(include);
bootstrap!(join_digit);
bootstrap!(join_ignore);
bootstrap!(name_collision);
bootstrap!(procedural_texture);
bootstrap!(quote);
bootstrap!(quote_recursive);
bootstrap!(quote);
bootstrap!(redefine_external);
bootstrap!(self_recursion);
bootstrap!(sqf);
bootstrap!(sqf_select);
bootstrap!(sqf);
bootstrap!(strings);
bootstrap!(utf);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

"#structural"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define QOUTE(s) #s

QOUTE(#structural)

0 comments on commit 7323c1a

Please sign in to comment.