Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use narrow type for string parsing patterns (#7211)
## Summary This PR adds a new enum type `StringType` which is either a string literal, byte literal or f-string. The motivation behind this is to have a narrow type which is accepted in `concatenate_strings` as that function is only applicable for the mentioned 3 types. This makes the code more readable and easy to reason about. A future improvement (which was prototyped here and removed) is to split the current string literal pattern in LALRPOP definition into two parts: 1. A single string literal or a f-string: This means no checking for bytes / non-bytes and other unnecessary compution 2. Two or more of string/byte/f-string: This will call the `concatenate_strings` function. The reason for removing the second change is because of how ranges work. The range for an individual string/byte is the entire range which includes the quotes as well but if the same string/byte is part of a f-string, then it only includes the range for the content (without the quotes / inner range). The current string parser returns with the former range. To give an example, for `"foo"`, the range of the string would be `0..5`, but for `f"foo"` the range of the string would be `2..5` while the range for the f-string expression would be `0..6`. The ranges are correct but they differ in the context the string constant itself is being used for. Is it part of a f-string or is it a standalone string? ## Test Plan `cargo test`
- Loading branch information