Support single quote strings

This commit is contained in:
Deukhoofd 2018-12-07 20:15:27 +01:00
parent 2327e18f77
commit 77be6fd996
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 8 additions and 7 deletions

View File

@ -107,7 +107,8 @@ namespace Upsilon.Parser
case '^':
return new SyntaxToken(SyntaxKind.RoofSign, _position, "^", null);
case '"':
return LexString();
case '\'':
return LexString(Current);
case '=':
if (Next == '=')
{
@ -174,26 +175,26 @@ namespace Upsilon.Parser
return new SyntaxToken(SyntaxKind.Number, start, numStr.ToString(), o);
}
private SyntaxToken LexString()
private SyntaxToken LexString(char current)
{
var start = _position;
var sb = new StringBuilder();
while (_position < _text.Length)
{
_position++;
if (Current == '\\' && Next == '"')
if (Current == '\\' && Next == current)
{
sb.Append("\"");
sb.Append(current);
_position += 2;
}
if (Current == '"')
if (Current == current)
break;
sb.Append(Current);
}
if (Current != '"')
if (Current != current)
{
_diagnostics.LogBadCharacter(new TextSpan(_position, 1), '"', Current);
_diagnostics.LogBadCharacter(new TextSpan(_position, 1), current, Current);
}
var res = sb.ToString();