Skip to content

Commit

Permalink
fix define directive not parsing strings properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Maiori44 committed Oct 23, 2023
1 parent 12dbcab commit e961a95
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions core/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,43 @@ pub fn preprocess_code(
"define" => {
let name = code.read_identifier()?;
let mut has_values = false;
let mut string_char = 0u8; //basically recreating read_string...
let mut skip_next = false; //refactor in 4.0?
let value = code.read(
|code| Ok(code.read_char_unchecked()),
|_, (c, ..)| {
if c == b'$' {
has_values = true;
|code, (c, ..)| {
match c {
b'$' => {
has_values = true;
false
}
_ if skip_next && code.comment == CommentState::String => {
skip_next = false;
false
}
b'\n' => code.comment != CommentState::String,
_ if c == string_char && code.comment == CommentState::String => {
code.comment = CommentState::None;
false
}
b'\'' | b'"' | b'`' if code.comment != CommentState::String => {
code.comment = CommentState::String;
string_char = c;
false
}
b'\\' if code.comment == CommentState::String => {
skip_next = true;
false
}
_ => false
}
c == b'\n'
},
)?;
if code.comment == CommentState::String {
return Err(
error("Unterminated string", code.line, code.column, code.filename)
);
}
let value = value.trim();
variables.insert(
name,
Expand Down

0 comments on commit e961a95

Please sign in to comment.