From f195202c8778dbf71d5c0fcf1bf120140bcffe27 Mon Sep 17 00:00:00 2001 From: peefy Date: Wed, 3 Jul 2024 12:09:40 +0800 Subject: [PATCH] fix: joined str parse and format & support \$ escape for str interpolation Signed-off-by: peefy --- kclvm/Cargo.lock | 41 ++-- kclvm/ast_pretty/src/node.rs | 26 ++- .../ast_pretty/src/test_data/codelayout.input | 21 +- .../src/test_data/codelayout.output | 19 ++ kclvm/ast_pretty/src/test_data/str.output | 4 +- kclvm/parser/src/parser/stmt.rs | 67 ++++-- kclvm/parser/src/tests/error_recovery.rs | 3 + ...r_recovery__joined_string_recovery_11.snap | 143 ++++++++++++ ...r_recovery__joined_string_recovery_12.snap | 207 ++++++++++++++++++ ...r_recovery__joined_string_recovery_13.snap | 127 +++++++++++ ...or_recovery__joined_string_recovery_7.snap | 2 +- ...or_recovery__joined_string_recovery_8.snap | 6 +- ...or_recovery__joined_string_recovery_9.snap | 6 +- .../str_interpolation/dollar_escape_0/main.k | 2 +- .../dollar_escape_0/stdout.golden | 2 +- .../str_interpolation/simple_2/stdout.golden | 2 +- 16 files changed, 609 insertions(+), 69 deletions(-) create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_11.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_12.snap create mode 100644 kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_13.snap diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 0c370f554..7dcce07a1 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -2895,53 +2895,52 @@ dependencies = [ [[package]] name = "protoc-bin-vendored" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "005ca8623e5633e298ad1f917d8be0a44bcf406bf3cde3b80e63003e49a3f27d" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" dependencies = [ "protoc-bin-vendored-linux-aarch_64", "protoc-bin-vendored-linux-ppcle_64", "protoc-bin-vendored-linux-x86_32", "protoc-bin-vendored-linux-x86_64", + "protoc-bin-vendored-macos-aarch_64", "protoc-bin-vendored-macos-x86_64", "protoc-bin-vendored-win32", ] [[package]] name = "protoc-bin-vendored-linux-aarch_64" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb9fc9cce84c8694b6ea01cc6296617b288b703719b725b8c9c65f7c5874435" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" [[package]] name = "protoc-bin-vendored-linux-ppcle_64" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d2a07dcf7173a04d49974930ccbfb7fd4d74df30ecfc8762cf2f895a094516" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" [[package]] name = "protoc-bin-vendored-linux-x86_32" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54fef0b04fcacba64d1d80eed74a20356d96847da8497a59b0a0a436c9165b0" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" [[package]] name = "protoc-bin-vendored-linux-x86_64" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8782f2ce7d43a9a5c74ea4936f001e9e8442205c244f7a3d4286bd4c37bc924" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" + +[[package]] +name = "protoc-bin-vendored-macos-aarch_64" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" [[package]] name = "protoc-bin-vendored-macos-x86_64" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5de656c7ee83f08e0ae5b81792ccfdc1d04e7876b1d9a38e6876a9e09e02537" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" [[package]] name = "protoc-bin-vendored-win32" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9653c3ed92974e34c5a6e0a510864dab979760481714c172e0a34e437cb98804" +version = "3.1.0" +source = "git+https://github.com/andermatt64/rust-protoc-bin-vendored#b6274dad0ed303b6dd27389722744947419649e5" [[package]] name = "quote" diff --git a/kclvm/ast_pretty/src/node.rs b/kclvm/ast_pretty/src/node.rs index bc0543a0c..5c8f3f57d 100644 --- a/kclvm/ast_pretty/src/node.rs +++ b/kclvm/ast_pretty/src/node.rs @@ -781,21 +781,25 @@ impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> { } fn walk_joined_string(&mut self, joined_string: &'ctx ast::JoinedString) -> Self::Result { - let quote_str = if joined_string.is_long_string { - "\"\"\"" + if !joined_string.raw_value.is_empty() { + self.write(&joined_string.raw_value) } else { - "\"" - }; - self.write(quote_str); - for value in &joined_string.values { - match &value.node { - ast::Expr::StringLit(string_lit) => { - self.write(&string_lit.value.replace('\"', "\\\"")); + let quote_str = if joined_string.is_long_string { + "\"\"\"" + } else { + "\"" + }; + self.write(quote_str); + for value in &joined_string.values { + match &value.node { + ast::Expr::StringLit(string_lit) => { + self.write(&string_lit.value.replace('\"', "\\\"")); + } + _ => self.expr(value), } - _ => self.expr(value), } + self.write(quote_str); } - self.write(quote_str); } fn walk_formatted_value(&mut self, formatted_value: &'ctx ast::FormattedValue) -> Self::Result { diff --git a/kclvm/ast_pretty/src/test_data/codelayout.input b/kclvm/ast_pretty/src/test_data/codelayout.input index 8df50874f..d36aeb3cb 100644 --- a/kclvm/ast_pretty/src/test_data/codelayout.input +++ b/kclvm/ast_pretty/src/test_data/codelayout.input @@ -80,4 +80,23 @@ aaaa = (1 + 2 / 2) if _a == 2 + + 134.3 else ("a"*3) bbbb = "{}". format(a) empty_list = [] empty_config = {} -number_suffix = 1Gi \ No newline at end of file +number_suffix = 1Gi +long_string_0 = """ +value +""" +long_string_1 = """\ +value +""" +long_string_2 = """\ +value""" +joined_data_0 = '\"false\" ${item.kind}: ${item.metadata.name}' +joined_data_1 = "\"false\" ${item.kind}: ${item.metadata.name}" +joined_data_2 = '''\ + ${CC} +''' +joined_data_3 = '''\ + $${CC} +''' +joined_data_4 = '''\ + \${CC} +''' \ No newline at end of file diff --git a/kclvm/ast_pretty/src/test_data/codelayout.output b/kclvm/ast_pretty/src/test_data/codelayout.output index d0d175158..b2338351d 100644 --- a/kclvm/ast_pretty/src/test_data/codelayout.output +++ b/kclvm/ast_pretty/src/test_data/codelayout.output @@ -86,3 +86,22 @@ bbbb = "{}".format(a) empty_list = [] empty_config = {} number_suffix = 1Gi +long_string_0 = """ +value +""" +long_string_1 = """\ +value +""" +long_string_2 = """\ +value""" +joined_data_0 = '\"false\" ${item.kind}: ${item.metadata.name}' +joined_data_1 = "\"false\" ${item.kind}: ${item.metadata.name}" +joined_data_2 = '''\ + ${CC} +''' +joined_data_3 = '''\ + $${CC} +''' +joined_data_4 = '''\ + \${CC} +''' diff --git a/kclvm/ast_pretty/src/test_data/str.output b/kclvm/ast_pretty/src/test_data/str.output index c9b149b0c..f9f69d934 100644 --- a/kclvm/ast_pretty/src/test_data/str.output +++ b/kclvm/ast_pretty/src/test_data/str.output @@ -3,6 +3,6 @@ b = "${a}" c = """1""" d = """${c}""" e = '1' -f = "${a}" +f = '${a}' g = '''1''' -h = """${c}""" +h = '''${c}''' diff --git a/kclvm/parser/src/parser/stmt.rs b/kclvm/parser/src/parser/stmt.rs index a543de9c1..3c60027e8 100644 --- a/kclvm/parser/src/parser/stmt.rs +++ b/kclvm/parser/src/parser/stmt.rs @@ -1640,37 +1640,56 @@ impl<'a> Parser<'a> { let mut data_off = 0; let mut raw_off: usize = quote_space; loop { - if let (Some(i), Some(data_i)) = + if raw_off >= raw_data.len() || data_off >= data.len() { + break; + } + if let (Some(raw_i), Some(data_i)) = (raw_data[raw_off..].find("${"), data[data_off..].find("${")) { - if let (Some(j), Some(data_j)) = ( - raw_data[raw_off + i..].find('}'), - data[data_off + i..].find('}'), + if let (Some(raw_j), Some(data_j)) = ( + raw_data[raw_off + raw_i..].find('}'), + data[data_off + data_i..].find('}'), ) { - let lo: usize = raw_off + i; - let hi: usize = raw_off + i + j + 1; + let raw_lo: usize = raw_off + raw_i; + let raw_hi: usize = raw_off + raw_i + raw_j + 1; let data_lo: usize = data_off + data_i; let data_hi: usize = data_off + data_i + data_j + 1; let s0 = &data[data_off..data_lo]; - let s1 = &raw_data[lo..hi]; - - let s0_expr = node_ref!(Expr::StringLit(StringLit { - is_long_string: false, - raw_value: s0.to_string(), - value: s0.to_string().replace("$$", "$"), - })); - - let s1_expr = parse_expr(self, s1, pos + new_byte_pos(lo as u32)); - - if !s0.is_empty() { - joined_value.values.push(s0_expr); + let s0_raw = &raw_data[raw_off..raw_lo]; + let s1_raw = &raw_data[raw_lo..raw_hi]; + + // Handling \${} Escapes + let is_escape = !s0_raw.is_empty() && &s0_raw[s0_raw.len() - 1..] == "\\"; + if is_escape { + let s_raw = &raw_data[raw_off..raw_hi]; + let s = &data[data_off..data_hi].replace("\\$", "$"); + joined_value + .values + .push(node_ref!(Expr::StringLit(StringLit { + is_long_string: false, + raw_value: s_raw.to_string(), + value: s.to_string(), + }))); + } else { + if !s0.is_empty() { + joined_value + .values + .push(node_ref!(Expr::StringLit(StringLit { + is_long_string: false, + raw_value: s0_raw.to_string(), + value: s0.to_string(), + }))); + } + joined_value.values.push(parse_expr( + self, + s1_raw, + pos + new_byte_pos(raw_lo as u32), + )); } - joined_value.values.push(s1_expr); - data_off = data_hi; - raw_off = hi; + raw_off = raw_hi; continue; } else { self.sess.struct_message_error( @@ -1681,7 +1700,7 @@ impl<'a> Parser<'a> { .values .push(node_ref!(Expr::StringLit(StringLit { is_long_string: false, - raw_value: data[data_off..].to_string(), + raw_value: raw_data[raw_off..].to_string(), value: data[data_off..].to_string(), }))); break; @@ -1695,8 +1714,8 @@ impl<'a> Parser<'a> { .values .push(node_ref!(Expr::StringLit(StringLit { is_long_string: false, - raw_value: data[data_off..].to_string(), - value: data[data_off..].to_string().replace("$$", "$"), + raw_value: raw_data[raw_off..].to_string(), + value: data[data_off..].to_string(), }))); break; } diff --git a/kclvm/parser/src/tests/error_recovery.rs b/kclvm/parser/src/tests/error_recovery.rs index 77c2440b5..fe61588e5 100644 --- a/kclvm/parser/src/tests/error_recovery.rs +++ b/kclvm/parser/src/tests/error_recovery.rs @@ -219,6 +219,9 @@ parse_expr_snapshot! { joined_string_recovery_9, r#"'''\ parse_expr_snapshot! { joined_string_recovery_10, r#"""" ${CC} """"# } +parse_expr_snapshot! { joined_string_recovery_11, r#"'\"false\" ${item.kind}: ${item.metadata.name}'"# } +parse_expr_snapshot! { joined_string_recovery_12, r#"'\"false\" ${item.kind}: ${item.metadata.name} \"true\" ${item} '"# } +parse_expr_snapshot! { joined_string_recovery_13, r#"'\"false\" \${item.kind}: a${item.metadata.name} \"true\" \${item} '"# } parse_expr_snapshot! { lambda_recovery_0, r#"lambda"# } parse_expr_snapshot! { lambda_recovery_1, r#"lambda {"# } parse_expr_snapshot! { lambda_recovery_2, r#"lambda {}"# } diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_11.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_11.snap new file mode 100644 index 000000000..8343e4ae8 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_11.snap @@ -0,0 +1,143 @@ +--- +source: parser/src/tests/error_recovery.rs +expression: "crate::tests::parsing_expr_string(r#\"'\\\"false\\\" ${item.kind}: ${item.metadata.name}'\"#)" +--- +Node { + node: JoinedString( + JoinedString { + is_long_string: false, + values: [ + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\\\"false\\\" ", + value: "\"false\" ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "item", + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 17, + }, + Node { + node: "kind", + filename: "", + line: 1, + column: 18, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 22, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 22, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: ": ", + value: ": ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "item", + filename: "", + line: 1, + column: 27, + end_line: 1, + end_column: 31, + }, + Node { + node: "metadata", + filename: "", + line: 1, + column: 32, + end_line: 1, + end_column: 40, + }, + Node { + node: "name", + filename: "", + line: 1, + column: 41, + end_line: 1, + end_column: 45, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 27, + end_line: 1, + end_column: 45, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 27, + end_line: 1, + end_column: 45, + }, + ], + raw_value: "'\\\"false\\\" ${item.kind}: ${item.metadata.name}'", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 47, +} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_12.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_12.snap new file mode 100644 index 000000000..235648fa5 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_12.snap @@ -0,0 +1,207 @@ +--- +source: parser/src/tests/error_recovery.rs +expression: "crate::tests::parsing_expr_string(r#\"'\\\"false\\\" ${item.kind}: ${item.metadata.name} \\\"true\\\" ${item} '\"#)" +--- +Node { + node: JoinedString( + JoinedString { + is_long_string: false, + values: [ + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\\\"false\\\" ", + value: "\"false\" ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "item", + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 17, + }, + Node { + node: "kind", + filename: "", + line: 1, + column: 18, + end_line: 1, + end_column: 22, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 22, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 13, + end_line: 1, + end_column: 22, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: ": ", + value: ": ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "item", + filename: "", + line: 1, + column: 27, + end_line: 1, + end_column: 31, + }, + Node { + node: "metadata", + filename: "", + line: 1, + column: 32, + end_line: 1, + end_column: 40, + }, + Node { + node: "name", + filename: "", + line: 1, + column: 41, + end_line: 1, + end_column: 45, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 27, + end_line: 1, + end_column: 45, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 27, + end_line: 1, + end_column: 45, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: " \\\"true\\\" ", + value: " \"true\" ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "item", + filename: "", + line: 1, + column: 58, + end_line: 1, + end_column: 62, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 58, + end_line: 1, + end_column: 62, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 58, + end_line: 1, + end_column: 62, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: " ", + value: " ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + ], + raw_value: "'\\\"false\\\" ${item.kind}: ${item.metadata.name} \\\"true\\\" ${item} '", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 65, +} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_13.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_13.snap new file mode 100644 index 000000000..cb1becd17 --- /dev/null +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_13.snap @@ -0,0 +1,127 @@ +--- +source: parser/src/tests/error_recovery.rs +expression: "crate::tests::parsing_expr_string(r#\"'\\\"false\\\" \\${item.kind}: a${item.metadata.name} \\\"true\\\" \\${item} '\"#)" +--- +Node { + node: JoinedString( + JoinedString { + is_long_string: false, + values: [ + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: "\\\"false\\\" \\${item.kind}", + value: "\"false\" ${item.kind}", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: ": a", + value: ": a", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: FormattedValue( + FormattedValue { + is_long_string: false, + value: Node { + node: Identifier( + Identifier { + names: [ + Node { + node: "item", + filename: "", + line: 1, + column: 29, + end_line: 1, + end_column: 33, + }, + Node { + node: "metadata", + filename: "", + line: 1, + column: 34, + end_line: 1, + end_column: 42, + }, + Node { + node: "name", + filename: "", + line: 1, + column: 43, + end_line: 1, + end_column: 47, + }, + ], + pkgpath: "", + ctx: Load, + }, + ), + filename: "", + line: 1, + column: 29, + end_line: 1, + end_column: 47, + }, + format_spec: None, + }, + ), + filename: "", + line: 1, + column: 29, + end_line: 1, + end_column: 47, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: " \\\"true\\\" \\${item}", + value: " \"true\" ${item}", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + Node { + node: StringLit( + StringLit { + is_long_string: false, + raw_value: " ", + value: " ", + }, + ), + filename: "", + line: 1, + column: 1, + end_line: 1, + end_column: 1, + }, + ], + raw_value: "'\\\"false\\\" \\${item.kind}: a${item.metadata.name} \\\"true\\\" \\${item} '", + }, + ), + filename: "", + line: 1, + column: 0, + end_line: 1, + end_column: 68, +} diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_7.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_7.snap index e41fdfb36..60205c006 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_7.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_7.snap @@ -11,7 +11,7 @@ Node { node: StringLit( StringLit { is_long_string: false, - raw_value: "\n", + raw_value: "\\n", value: "\n", }, ), diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_8.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_8.snap index 868e55fd3..c679d1782 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_8.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_8.snap @@ -11,7 +11,7 @@ Node { node: StringLit( StringLit { is_long_string: false, - raw_value: "a\nb", + raw_value: "a\\nb", value: "a\nb", }, ), @@ -63,8 +63,8 @@ Node { node: StringLit( StringLit { is_long_string: false, - raw_value: "}\n", - value: "}\n", + raw_value: "\\n", + value: "\n", }, ), filename: "", diff --git a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_9.snap b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_9.snap index fa8064ae2..d93090334 100644 --- a/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_9.snap +++ b/kclvm/parser/src/tests/snapshots/kclvm_parser__tests__error_recovery__joined_string_recovery_9.snap @@ -11,7 +11,7 @@ Node { node: StringLit( StringLit { is_long_string: false, - raw_value: " ", + raw_value: "\\\n ", value: " ", }, ), @@ -61,8 +61,8 @@ Node { node: StringLit( StringLit { is_long_string: false, - raw_value: "C}\n", - value: "C}\n", + raw_value: "\n", + value: "\n", }, ), filename: "", diff --git a/test/grammar/datatype/str_interpolation/dollar_escape_0/main.k b/test/grammar/datatype/str_interpolation/dollar_escape_0/main.k index 7f61501a7..f520662a5 100644 --- a/test/grammar/datatype/str_interpolation/dollar_escape_0/main.k +++ b/test/grammar/datatype/str_interpolation/dollar_escape_0/main.k @@ -1,3 +1,3 @@ a = 1 b = 1 -data = "$$${a * 1}$$ ${b / 1} $$$$$" + " $$ " +data = "$\${a * 1}$$ ${b / 1} $$$$$" + " $$ " diff --git a/test/grammar/datatype/str_interpolation/dollar_escape_0/stdout.golden b/test/grammar/datatype/str_interpolation/dollar_escape_0/stdout.golden index 668abcf60..18d567464 100644 --- a/test/grammar/datatype/str_interpolation/dollar_escape_0/stdout.golden +++ b/test/grammar/datatype/str_interpolation/dollar_escape_0/stdout.golden @@ -1,3 +1,3 @@ a: 1 b: 1 -data: '$1$ 1.0 $$$ $$ ' +data: '$${a * 1}$$ 1.0 $$$$$ $$ ' diff --git a/test/grammar/datatype/str_interpolation/simple_2/stdout.golden b/test/grammar/datatype/str_interpolation/simple_2/stdout.golden index 7f87c2cca..5355d583f 100644 --- a/test/grammar/datatype/str_interpolation/simple_2/stdout.golden +++ b/test/grammar/datatype/str_interpolation/simple_2/stdout.golden @@ -1,3 +1,3 @@ a: 1 b: 1 -data: '$1$ 1.0 $$ $$ ' +data: '$$1$$ 1.0 $$$$ $$ '