From 154ecc1533f69f05c1d6e837d24fb7a0c0b0880e 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: Thu, 7 Jun 2018 20:30:28 +0200 Subject: [PATCH] fix #896 --- .../SemanticRules.cs | 21 ++++++++++++++++++- TestSuite/formatstring5.pas | 6 ++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 TestSuite/formatstring5.pas diff --git a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs index 9416986f3..d0ac91a11 100644 --- a/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs +++ b/Parsers/PascalABCParserNewSaushkin/SemanticRules.cs @@ -421,12 +421,22 @@ namespace GPPGParserScanner List vars = new List(); //Dictionary var_offsets = new Dictionary(); List var_offsets = new List(); + Dictionary var_formats = new Dictionary(); + int ind = 0; while (match.Success) { string s = match.Value.Replace("{", "").Replace("}", ""); + int colon_pos = s.IndexOf(':'); + if (colon_pos != -1) + { + var_formats.Add(ind, s.Substring(colon_pos)); + s = s.Substring(0, colon_pos); + + } vars.Add(s); var_offsets.Add(match.Index); match = match.NextMatch(); + ind++; } if (vars.Count == 0) { @@ -439,7 +449,16 @@ namespace GPPGParserScanner { sb.Append(arr[i].Replace("![&", "{{").Replace("&]!", "}}")); if (i < arr.Length - 1) - sb.Append("{" + i + "}"); + { + sb.Append("{" + i); + string fmt; + if (var_formats.TryGetValue(i, out fmt)) + { + sb.Append(fmt); + } + sb.Append("}"); + } + } mc.parameters.Add(new string_const(sb.ToString(), str.source_context), str.source_context); for (int i = 0; i < vars.Count; i++) diff --git a/TestSuite/formatstring5.pas b/TestSuite/formatstring5.pas new file mode 100644 index 000000000..9f157657c --- /dev/null +++ b/TestSuite/formatstring5.pas @@ -0,0 +1,6 @@ +begin + var t := System.DateTime.Now; + var s1 := string.Format('date is {0:dd.MM.yy}',t); + var s2 := $'date is {t:dd.MM.yy}'; + assert(s1 = s2); +end. \ No newline at end of file