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

fix(parser): fix some escape sequences in strings and indentation in block strings #633

Merged
merged 10 commits into from
Aug 31, 2023

Conversation

goto-bus-stop
Copy link
Member

@goto-bus-stop goto-bus-stop commented Aug 25, 2023

Follow-up to #638, fixing conversion of StringValue nodes to Rust strings.

Fixes #609
Fixes #611

This handles

This does not handle these unicode escape issues:

@goto-bus-stop goto-bus-stop self-assigned this Aug 25, 2023
@goto-bus-stop goto-bus-stop changed the title fix(parser): fix lexing escape sequences in block strings fix(parser): fix escape handling in strings Aug 28, 2023
@goto-bus-stop goto-bus-stop marked this pull request as draft August 28, 2023 10:26
@goto-bus-stop goto-bus-stop marked this pull request as ready for review August 31, 2023 09:01
@goto-bus-stop goto-bus-stop changed the title fix(parser): fix escape handling in strings fix(parser): fix escape handling in block strings Aug 31, 2023
@goto-bus-stop goto-bus-stop changed the title fix(parser): fix escape handling in block strings fix(parser): fix some escape sequences in strings and indentation in block strings Aug 31, 2023
Copy link
Contributor

@SimonSapin SimonSapin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Comment on lines +235 to +240
let line = &self.input[..index];
let rest = match self.input.get(index..=index + 1) {
Some("\r\n") => &self.input[index + 2..],
_ => &self.input[index + 1..],
};
self.input = rest;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is fine. It can be marginally nicer with split_at and strip_prefix:

Suggested change
let line = &self.input[..index];
let rest = match self.input.get(index..=index + 1) {
Some("\r\n") => &self.input[index + 2..],
_ => &self.input[index + 1..],
};
self.input = rest;
let (line, rest) = self.input.split_at(index);
// `rest` starts with \r or \n
self.input = rest.strip_prefix("\r\n").unwrap_or_else(|| &rest[1..])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my personal feeling is that split_at looks nicer but the manual match is more obviously correct despite being a bit noisy... though as i look back and forth i don't feel strongly anymore.

crates/apollo-parser/src/ast/node_ext.rs Outdated Show resolved Hide resolved
crates/apollo-parser/src/ast/node_ext.rs Outdated Show resolved Hide resolved
crates/apollo-parser/src/ast/node_ext.rs Outdated Show resolved Hide resolved
crates/apollo-parser/src/ast/node_ext.rs Show resolved Hide resolved
Copy link
Member

@lrlna lrlna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

@goto-bus-stop goto-bus-stop enabled auto-merge (squash) August 31, 2023 14:55
@goto-bus-stop goto-bus-stop merged commit 3626dca into main Aug 31, 2023
@goto-bus-stop goto-bus-stop deleted the parse-string branch August 31, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect parsing of string with trailing \" Block strings are parsed like non-block strings
3 participants