fix #2076
This commit is contained in:
parent
4b0966f6cb
commit
443736a641
|
|
@ -421,6 +421,7 @@ namespace GPPGParserScanner
|
||||||
if (!str.Value.Contains("{"))
|
if (!str.Value.Contains("{"))
|
||||||
return str;
|
return str;
|
||||||
string val = str.Value.Replace("{{","![&").Replace("}}}","}&]!").Replace("}}", "&]!");
|
string val = str.Value.Replace("{{","![&").Replace("}}}","}&]!").Replace("}}", "&]!");
|
||||||
|
|
||||||
string[] arr = Regex.Split(val, @"\{[^\}]+\}");
|
string[] arr = Regex.Split(val, @"\{[^\}]+\}");
|
||||||
Match match = Regex.Match(val, @"\{[^\}]+\}");
|
Match match = Regex.Match(val, @"\{[^\}]+\}");
|
||||||
List<string> vars = new List<string>();
|
List<string> vars = new List<string>();
|
||||||
|
|
@ -442,13 +443,18 @@ namespace GPPGParserScanner
|
||||||
var_formats.Add(ind, s.Substring(colon_pos));
|
var_formats.Add(ind, s.Substring(colon_pos));
|
||||||
s = s.Substring(0, colon_pos);
|
s = s.Substring(0, colon_pos);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (s.IndexOf("&]!") != -1 || s.IndexOf("![&") != -1)
|
||||||
|
{
|
||||||
|
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
vars.Add(s);
|
vars.Add(s);
|
||||||
var_offsets.Add(match.Index);
|
var_offsets.Add(match.Index);
|
||||||
match = match.NextMatch();
|
match = match.NextMatch();
|
||||||
ind++;
|
ind++;
|
||||||
}
|
}
|
||||||
if (vars.Count == 0)
|
if (vars.Count == 0 && val.IndexOf("![&") == -1 && val.IndexOf("{") != -1)
|
||||||
{
|
{
|
||||||
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
||||||
return str;
|
return str;
|
||||||
|
|
@ -457,6 +463,11 @@ namespace GPPGParserScanner
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < arr.Length; i++)
|
for (int i = 0; i < arr.Length; i++)
|
||||||
{
|
{
|
||||||
|
if (arr[i].IndexOf("{") != -1 || arr[i].IndexOf("}") != -1)
|
||||||
|
{
|
||||||
|
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
sb.Append(arr[i].Replace("![&", "{{").Replace("&]!", "}}"));
|
sb.Append(arr[i].Replace("![&", "{{").Replace("&]!", "}}"));
|
||||||
if (i < arr.Length - 1)
|
if (i < arr.Length - 1)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
3
TestSuite/errors/err0335.pas
Normal file
3
TestSuite/errors/err0335.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
begin
|
||||||
|
var s := $'{{1} {0}';
|
||||||
|
end.
|
||||||
3
TestSuite/errors/err0336.pas
Normal file
3
TestSuite/errors/err0336.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
begin
|
||||||
|
var s := $'{1}}';
|
||||||
|
end.
|
||||||
3
TestSuite/errors/err0337.pas
Normal file
3
TestSuite/errors/err0337.pas
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
begin
|
||||||
|
var s := $'{1}} {0}';
|
||||||
|
end.
|
||||||
9
TestSuite/formatstring7.pas
Normal file
9
TestSuite/formatstring7.pas
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
begin
|
||||||
|
var s1 := $'{{0}} {1}';
|
||||||
|
assert(s1 = '{0} 1');
|
||||||
|
var s2 := $'';
|
||||||
|
var s3 := $'{{0}}';
|
||||||
|
assert(s3 = '{0}');
|
||||||
|
s3 := $'{{1 {0}';
|
||||||
|
assert(s3 = '{1 0');
|
||||||
|
end.
|
||||||
Loading…
Reference in a new issue