From 96e14545119ce00f1c17bd93b22c086c03d66162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 2 Sep 2018 12:25:14 +0200 Subject: [PATCH] fix #1067 --- .../SemanticRules.cs | 7 ++++- TestSuite/formatstring6.pas | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 TestSuite/formatstring6.pas diff --git a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs index 45a526dc7..52e1ce126 100644 --- a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs +++ b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs @@ -431,7 +431,12 @@ namespace GPPGParserScanner while (match.Success) { string s = match.Value.Replace("{", "").Replace("}", ""); - int colon_pos = s.IndexOf(':'); + int colon_pos = s.LastIndexOf(':'); + int comma_pos = s.LastIndexOf(','); + int bracket_pos = s.LastIndexOf(')'); + int sqbracked_pos = s.LastIndexOf(']'); + if (comma_pos != -1 && comma_pos > bracket_pos && comma_pos > sqbracked_pos) + colon_pos = comma_pos; if (colon_pos != -1 && s.IndexOf('?') == -1) { var_formats.Add(ind, s.Substring(colon_pos)); diff --git a/TestSuite/formatstring6.pas b/TestSuite/formatstring6.pas new file mode 100644 index 000000000..353bb9430 --- /dev/null +++ b/TestSuite/formatstring6.pas @@ -0,0 +1,28 @@ +begin + var a := 3.1; + var s := $'{a,6:F2}'; + var s2 := string.Format('{0,6:F2}',a); + assert(s = s2); + s := $'{a,-10}'; + s2 := string.Format('{0,-10}', a); + assert(s = s2); + s := $'a is {a,6:N2}'; + s2 := string.Format('a is {0,6:N2}',a); + assert(s = s2); + s := $'{Min(2,3),-5:F2}'; + s2 := string.Format('{0,-5:F2}', Min(2,3)); + assert(s = s2); + s := $'{Min(2,3):F2}'; + s2 := string.Format('{0:F2}', Min(2,3)); + assert(s = s2); + var arr1 := Arr(1,2,3); + s := $'{arr1[2],-5:F2}'; + s2 := string.Format('{0,-5:F2}', arr1[2]); + var arr2 := new integer[2,2]; + s := $'{arr2[0,0],-5:F2}'; + s2 := string.Format('{0,-5:F2}', arr2[0,0]); + assert(s = s2); + s := $'{arr2[0,0]}'; + s2 := string.Format('{0}', arr2[0,0]); + assert(s = s2); +end. \ No newline at end of file