Skip to content

Commit

Permalink
preprocessor: 2.18 built in macros (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Oct 9, 2024
1 parent e90a831 commit bb52cfb
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion libs/preprocessor/src/defines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ pub struct Defines {
const BUILTIN_CONST: [(&str, u8); 2] = [("__ARMA__", 1), ("__ARMA3__", 1)];

/// Built-in macros that HEMTT supports, generated by the preprocessor
const BUILTIN_GEN: [&str; 4] = ["__COUNTER__", "__COUNTER_RESET__", "__FILE__", "__LINE__"];
const BUILTIN_GEN: [&str; 6] = [
"__COUNTER__",
"__COUNTER_RESET__",
"__FILE__",
"__FILE_NAME__",
"__FILE_SHORT__",
"__LINE__",
];

/// Built-in macros that HEMTT intentionally does not support
const BUILTIN_PROTEST: [&str; 16] = [
Expand Down Expand Up @@ -75,6 +82,7 @@ impl Defines {
self.global.contains_key(key)
}

#[allow(clippy::too_many_lines)]
pub fn get_with_gen(
&mut self,
key: &Rc<Token>,
Expand Down Expand Up @@ -141,6 +149,38 @@ impl Defines {
DefineSource::Generated,
));
}
"__FILE_NAME__" => {
let path = site.path().filename();
return Some((
key.clone(),
Definition::Value(vec![Rc::new(Token::new(
Symbol::Word(path),
key.position().clone(),
))]),
DefineSource::Generated,
));
}
"__FILE_SHORT__" => {
// drop the last extension, `test.inc.sqf` -> `test.inc`
let path = site.path().filename();
let path = path
.chars()
.rev()
.skip_while(|c| *c != '.')
.skip(1)
.collect::<Vec<_>>()
.iter()
.rev()
.collect::<String>();
return Some((
key.clone(),
Definition::Value(vec![Rc::new(Token::new(
Symbol::Word(path),
key.position().clone(),
))]),
DefineSource::Generated,
));
}
"__LINE__" => {
return Some((
key.clone(),
Expand Down

0 comments on commit bb52cfb

Please sign in to comment.