From d5a2d9205dd4f8ead3359b2ee59207d3f4e80c54 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sun, 12 Mar 2023 11:59:02 +0100 Subject: [PATCH] #2813 --- .../PascalABCParserNewSaushkin/SemanticRules.cs | 14 ++++++++++++-- TestSuite/errors/err0519_format_string.pas | 3 +++ TestSuite/formatstring9.pas | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 TestSuite/errors/err0519_format_string.pas create mode 100644 TestSuite/formatstring9.pas diff --git a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs index b0661c413..2b48ab4ef 100644 --- a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs +++ b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs @@ -489,11 +489,21 @@ namespace GPPGParserScanner } } + string str2 = sb.ToString(); if (str2.Trim().EndsWith("{")) { - parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str)); - return str; + int cnt = 0; + string tmp = str2.Trim(); + for (var i = 0; i < tmp.Length; i++) + if (tmp[i] == '{') + cnt++; + if (cnt % 2 == 1) + { + parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str)); + return str; + } + } mc.parameters.Add(new string_const(str2, str.source_context), str.source_context); for (int i = 0; i < vars.Count; i++) diff --git a/TestSuite/errors/err0519_format_string.pas b/TestSuite/errors/err0519_format_string.pas new file mode 100644 index 000000000..0b89595c4 --- /dev/null +++ b/TestSuite/errors/err0519_format_string.pas @@ -0,0 +1,3 @@ +begin + var s := $'{{{'; +end. \ No newline at end of file diff --git a/TestSuite/formatstring9.pas b/TestSuite/formatstring9.pas new file mode 100644 index 000000000..a532d2f2d --- /dev/null +++ b/TestSuite/formatstring9.pas @@ -0,0 +1,6 @@ +begin + var s := $'{{'; + assert(s = '{'); + s := $'{{{{'; + assert(s = '{{'); +end. \ No newline at end of file