Skip to content

Commit 65a784f

Browse files
committed
fix!: add rust config for noop string escapes
1 parent 9ced4e8 commit 65a784f

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

sqlglot/tokens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ def _quotes_to_format(
600600
tokens_preceding_hint={
601601
_TOKEN_TYPE_TO_INDEX[v] for v in klass.TOKENS_PRECEDING_HINT
602602
},
603+
string_escapes_noop=klass._STRING_ESCAPES_NOOP,
603604
)
604605
token_types = RsTokenTypeSettings(
605606
bit_string=_TOKEN_TYPE_TO_INDEX[TokenType.BIT_STRING],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"white_space":{"\n":55,"\t":54,"\r":55," ":54},"single_tokens":{"\"":320,",":6,".":7,"[":2,"*":14,":":10,"]":3,"'":320,"(":0,")":1,"?":311,"-":8,"@":47,"$":46},"keywords":{"..":7},"numeric_literals":{},"identifiers":{"\"":"\""},"identifier_escapes":["\\"],"string_escapes":["\\"],"quotes":{"'":"'"},"format_strings":{"N'":["'",70],"n'":["'",70]},"has_bit_strings":false,"has_hex_strings":false,"comments":{"{#":"#}","--":null,"/*":"*/"},"var_single_tokens":[],"commands":[237,341,205,234,324],"command_prefix_tokens":[13,197],"tokens_preceding_hint":[261,334,221,361],"heredoc_tag_is_identifier":false,"string_escapes_allowed_in_raw_strings":true,"nested_comments":true,"hint_start":"/*+"}
1+
{"white_space":{"\n":55,"\t":54,"\r":55," ":54},"single_tokens":{"\"":320,",":6,".":7,"[":2,"*":14,":":10,"]":3,"'":320,"(":0,")":1,"?":311,"-":8,"@":47,"$":46},"keywords":{"..":7},"numeric_literals":{},"identifiers":{"\"":"\""},"identifier_escapes":["\\"],"string_escapes":["\\"],"quotes":{"'":"'"},"format_strings":{"N'":["'",70],"n'":["'",70]},"has_bit_strings":false,"has_hex_strings":false,"comments":{"{#":"#}","--":null,"/*":"*/"},"var_single_tokens":[],"commands":[237,341,205,234,324],"command_prefix_tokens":[13,197],"tokens_preceding_hint":[261,334,221,361],"heredoc_tag_is_identifier":false,"string_escapes_allowed_in_raw_strings":true,"nested_comments":true,"hint_start":"/*+","string_escapes_noop":[]}

sqlglotrs/src/settings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub struct TokenizerSettings {
104104
pub string_escapes_allowed_in_raw_strings: bool,
105105
pub nested_comments: bool,
106106
pub hint_start: String,
107+
pub string_escapes_noop: HashSet<char>,
107108
}
108109

109110
#[pymethods]
@@ -130,6 +131,7 @@ impl TokenizerSettings {
130131
string_escapes_allowed_in_raw_strings: bool,
131132
nested_comments: bool,
132133
hint_start: String,
134+
string_escapes_noop: HashSet<String>,
133135
) -> Self {
134136
let to_char = |v: &String| {
135137
if v.len() == 1 {
@@ -158,6 +160,7 @@ impl TokenizerSettings {
158160
identifier_escapes.iter().map(&to_char).collect();
159161

160162
let string_escapes_native: HashSet<char> = string_escapes.iter().map(&to_char).collect();
163+
let string_escapes_noop_native: HashSet<char> = string_escapes_noop.iter().map(&to_char).collect();
161164

162165
let var_single_tokens_native: HashSet<char> =
163166
var_single_tokens.iter().map(&to_char).collect();
@@ -183,6 +186,7 @@ impl TokenizerSettings {
183186
string_escapes_allowed_in_raw_strings,
184187
nested_comments,
185188
hint_start,
189+
string_escapes_noop: string_escapes_noop_native,
186190
};
187191

188192
#[cfg(feature = "profiling")]

sqlglotrs/src/tokenizer.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,17 @@ impl<'a> TokenizerState<'a> {
665665
{
666666
let peek_char_str = self.peek_char.to_string();
667667
let equal_delimiter = delimiter == peek_char_str;
668-
if equal_delimiter || escapes.contains(&self.peek_char) {
668+
669+
if equal_delimiter
670+
|| escapes.contains(&self.peek_char)
671+
|| self.settings.string_escapes_noop.contains(&self.peek_char)
672+
{
669673
if equal_delimiter {
670674
text.push(self.peek_char);
675+
} else if self.settings.string_escapes_noop.contains(&self.peek_char)
676+
&& self.current_char != self.peek_char
677+
{
678+
text.push(self.peek_char);
671679
} else {
672680
text.push(self.current_char);
673681
text.push(self.peek_char);

0 commit comments

Comments
 (0)