Support single quote strings
This commit is contained in:
parent
2327e18f77
commit
77be6fd996
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue