This commit is contained in:
Бондарев Иван 2019-08-18 13:40:45 +02:00
parent 4b0966f6cb
commit 443736a641
5 changed files with 31 additions and 2 deletions

View file

@ -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)
{ {

View file

@ -0,0 +1,3 @@
begin
var s := $'{{1} {0}';
end.

View file

@ -0,0 +1,3 @@
begin
var s := $'{1}}';
end.

View file

@ -0,0 +1,3 @@
begin
var s := $'{1}} {0}';
end.

View 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.