Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse: fix // inside single quote strings #740

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 11 additions & 4 deletions libs/preprocessor/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub fn parse(path: &WorkspacePath) -> Result<Vec<Rc<Token>>, Error> {
let mut line = 1;
let mut col = 0;
let mut offset = 0;
let mut in_string = false;
let mut in_single_string = false;
let mut in_double_string = false;
let mut skipping_comment = false;
for pair in pairs {
let start = LineCol(offset, (line, col));
Expand All @@ -44,7 +45,7 @@ pub fn parse(path: &WorkspacePath) -> Result<Vec<Rc<Token>>, Error> {
col = 0;
}
Rule::COMMENT => {
if in_string {
if in_single_string || in_double_string {
if !skipping_comment {
tokens.push(Rc::new(Token::new(
Symbol::Word(pair.as_str().to_string()),
Expand Down Expand Up @@ -74,9 +75,15 @@ pub fn parse(path: &WorkspacePath) -> Result<Vec<Rc<Token>>, Error> {
}
}
}
Rule::single_quote => {
if !skipping_comment && !in_double_string {
in_single_string = !in_single_string;
col += 1;
}
}
Rule::double_quote => {
if !skipping_comment {
in_string = !in_string;
if !skipping_comment && !in_single_string {
in_double_string = !in_double_string;
col += 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions libs/preprocessor/tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bootstrap!(addon_in_ifdef);
bootstrap!(cba_is_admin);
bootstrap!(cba_multiline);
bootstrap!(comment_edgecase);
bootstrap!(comment_in_quote);
bootstrap!(define_builtin);
bootstrap!(define_function_empty);
bootstrap!(define_function_multiline);
Expand Down
12 changes: 12 additions & 0 deletions libs/preprocessor/tests/bootstrap/comment_in_quote/expected.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
url1 = 'http://www.zombo.com';
url2 = "http://www.zombo.com";

"'//'
'// a
""'//""
"

'"//"
"// c
''"//''
'
12 changes: 12 additions & 0 deletions libs/preprocessor/tests/bootstrap/comment_in_quote/source.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
url1 = 'http://www.zombo.com';// "Great Site"
url2 = "http://www.zombo.com";

"'//'
'// a
""'//""
"// b

'"//"
"// c
''"//''
'// d
Loading