Skip to content

Commit

Permalink
Make short string parsing use Lexer's shared builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Apr 9, 2021
1 parent 26d1c97 commit db03d8c
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/Compilers/Lua/Portable/Parser/Lexer.ShortString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed partial class Lexer
{
private string ParseShortString()
{
var parsed = new StringBuilder();
_builder.Clear();
var delim = _reader.Read()!.Value;
RoslynDebug.Assert(delim is '"' or '\'');

Expand All @@ -30,68 +30,68 @@ private string ParseShortString()
if (_reader.IsAt('\n', 1))
{
_reader.Advance(2);
parsed.Append("\r\n");
_builder.Append("\r\n");
}
else
{
_reader.Advance(1);
parsed.Append('\r');
_builder.Append('\r');
}
break;

case 'a':
_reader.Advance(1);
parsed.Append('\a');
_builder.Append('\a');
break;

case 'b':
_reader.Advance(1);
parsed.Append('\b');
_builder.Append('\b');
break;

case 'f':
_reader.Advance(1);
parsed.Append('\f');
_builder.Append('\f');
break;

case 'n':
_reader.Advance(1);
parsed.Append('\n');
_builder.Append('\n');
break;

case 'r':
_reader.Advance(1);
parsed.Append('\r');
_builder.Append('\r');
break;

case 't':
_reader.Advance(1);
parsed.Append('\t');
_builder.Append('\t');
break;

case 'v':
_reader.Advance(1);
parsed.Append('\v');
_builder.Append('\v');
break;

case '\\':
_reader.Advance(1);
parsed.Append('\\');
_builder.Append('\\');
break;

case '\n':
_reader.Advance(1);
parsed.Append('\n');
_builder.Append('\n');
break;

case '\'':
_reader.Advance(1);
parsed.Append('\'');
_builder.Append('\'');
break;

case '"':
_reader.Advance(1);
parsed.Append('"');
_builder.Append('"');
break;

case '0':
Expand All @@ -107,7 +107,7 @@ private string ParseShortString()
{
var parsedCharInteger = parseDecimalInteger(escapeStart);
if (parsedCharInteger != char.MaxValue)
parsed.Append(parsedCharInteger);
_builder.Append(parsedCharInteger);
break;
}

Expand All @@ -116,7 +116,7 @@ private string ParseShortString()
_reader.Advance(1);
var parsedCharInteger = parseHexadecimalInteger(escapeStart);
if (parsedCharInteger != char.MaxValue)
parsed.Append(parsedCharInteger);
_builder.Append(parsedCharInteger);

if (!Options.SyntaxOptions.AcceptHexEscapesInStrings)
AddError(escapeStart, _reader.Position - escapeStart, ErrorCode.ERR_HexStringEscapesNotSupportedInVersion);
Expand All @@ -141,12 +141,12 @@ private string ParseShortString()
if (_reader.IsAt('\n', 1))
{
_reader.Advance(2);
parsed.Append("\r\n");
_builder.Append("\r\n");
}
else
{
_reader.Advance(1);
parsed.Append('\r');
_builder.Append('\r');
}

AddError(charStart, _reader.Position - charStart, ErrorCode.ERR_UnescapedLineBreakInString);
Expand All @@ -156,15 +156,15 @@ private string ParseShortString()
case '\n':
{
_reader.Advance(1);
parsed.Append('\n');
_builder.Append('\n');

AddError(charStart, _reader.Position - charStart, ErrorCode.ERR_UnescapedLineBreakInString);
}
break;

default:
_reader.Advance(1);
parsed.Append(peek);
_builder.Append(peek);
break;
}
}
Expand All @@ -178,7 +178,7 @@ private string ParseShortString()
AddError(ErrorCode.ERR_UnfinishedString);
}

return parsed.ToString();
return _builder.ToString();

char parseDecimalInteger(int start)
{
Expand Down

0 comments on commit db03d8c

Please sign in to comment.