Skip to content

Commit

Permalink
Cleaned up string token handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Mar 30, 2024
1 parent ca01548 commit e42b18d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Pasper.Json/Parsing/JsonLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ private bool TryGetStringToken([NotNullWhen(true)] out IToken? token)
throw new UnexpectedTokenException(_lineNumber, _columnNumber, "EOF");

var value = json.Substring(startIndex + 1, endIndex - startIndex - 1);
var isProperty = Previous is BeginObjectToken or EndValueToken;
token = isProperty
? new PropertyNameToken(value)
: Previous is EndNameToken
? new LiteralStringToken(value)
: throw new UnexpectedTokenException(_lineNumber, _columnNumber, value);
token = Previous switch
{
EndNameToken => new LiteralStringToken(value),
BeginObjectToken or EndValueToken => new PropertyNameToken(value),
_ => throw new UnexpectedTokenException(_lineNumber, _columnNumber, value)
};

_currentIndex = endIndex + 1;
return true;
Expand Down

0 comments on commit e42b18d

Please sign in to comment.