Skip to content

Commit

Permalink
Fixed minor issues with the JSON lexer.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Mar 30, 2024
1 parent 9ddbcff commit 3ab36c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Pasper.Json/Parsing/JsonLexer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

using Pasper.Json.Tokens;
using Pasper.Parsing;

Expand All @@ -23,11 +25,12 @@ public sealed class JsonLexer(string json)
/// <inheritdoc/>
public bool MoveNext()
{
if (_currentIndex >= json.Length)
if (!TryGetNextToken(out var currentToken))
return false;

Previous = Current;
return TryGetNextToken();
Current = currentToken;
return true;
}

/// <inheritdoc/>
Expand All @@ -38,12 +41,17 @@ public void Reset()
Current = null;
}

private bool TryGetNextToken()
private bool TryGetNextToken([NotNullWhen(true)] out IToken? token)

Check failure on line 44 in src/Pasper.Json/Parsing/JsonLexer.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'NotNullWhenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 44 in src/Pasper.Json/Parsing/JsonLexer.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'NotNullWhen' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 44 in src/Pasper.Json/Parsing/JsonLexer.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'NotNullWhenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 44 in src/Pasper.Json/Parsing/JsonLexer.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'NotNullWhen' could not be found (are you missing a using directive or an assembly reference?)
{
SkipWhitespace();
if (_currentIndex >= json.Length)
{
token = null;
return false;
}

var currentChar = json[_currentIndex];
IToken? currentToken = currentChar switch
var currentCharacter = json[_currentIndex];
token = currentCharacter switch
{
'{' => new BeginObject(),
'}' => new EndObject(),
Expand All @@ -52,14 +60,13 @@ private bool TryGetNextToken()
_ => null
};

if (currentToken is not null)
if (token is not null)
{
Current = currentToken;
_currentIndex++;
return true;
}

throw new UnexpectedTokenException(_lineNumber, _columnNumber, currentChar.ToString());
throw new UnexpectedTokenException(_lineNumber, _columnNumber, currentCharacter.ToString());
}

private void SkipWhitespace()
Expand Down
2 changes: 2 additions & 0 deletions test/Pasper.Json.Tests/Pasper.Json.Tests.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=parsing_005Cjsonlexer/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 3ab36c8

Please sign in to comment.