Support single quote strings
This commit is contained in:
parent
2327e18f77
commit
77be6fd996
|
@ -107,7 +107,8 @@ namespace Upsilon.Parser
|
||||||
case '^':
|
case '^':
|
||||||
return new SyntaxToken(SyntaxKind.RoofSign, _position, "^", null);
|
return new SyntaxToken(SyntaxKind.RoofSign, _position, "^", null);
|
||||||
case '"':
|
case '"':
|
||||||
return LexString();
|
case '\'':
|
||||||
|
return LexString(Current);
|
||||||
case '=':
|
case '=':
|
||||||
if (Next == '=')
|
if (Next == '=')
|
||||||
{
|
{
|
||||||
|
@ -174,26 +175,26 @@ namespace Upsilon.Parser
|
||||||
return new SyntaxToken(SyntaxKind.Number, start, numStr.ToString(), o);
|
return new SyntaxToken(SyntaxKind.Number, start, numStr.ToString(), o);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SyntaxToken LexString()
|
private SyntaxToken LexString(char current)
|
||||||
{
|
{
|
||||||
var start = _position;
|
var start = _position;
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
while (_position < _text.Length)
|
while (_position < _text.Length)
|
||||||
{
|
{
|
||||||
_position++;
|
_position++;
|
||||||
if (Current == '\\' && Next == '"')
|
if (Current == '\\' && Next == current)
|
||||||
{
|
{
|
||||||
sb.Append("\"");
|
sb.Append(current);
|
||||||
_position += 2;
|
_position += 2;
|
||||||
}
|
}
|
||||||
if (Current == '"')
|
if (Current == current)
|
||||||
break;
|
break;
|
||||||
sb.Append(Current);
|
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();
|
var res = sb.ToString();
|
||||||
|
|
Loading…
Reference in New Issue