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