Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
improved test cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-pogor committed Nov 19, 2024
1 parent 611260e commit f17b961
Show file tree
Hide file tree
Showing 22 changed files with 626 additions and 256 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ dotnet_diagnostic.SA1308.severity = none
# SA1311: Static readonly fields should begin with upper-case letter
dotnet_diagnostic.SA1311.severity = none

# SA1503: Braces should not be omitted
dotnet_diagnostic.SA1503.severity = none

# CSharp code style settings:
[*.cs]
# Newline settings
Expand Down
47 changes: 47 additions & 0 deletions OffDotNet.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Solution>
<Folder Name="/Solution Items/">
<File Path=".editorconfig" />
<File Path=".gitattributes" />
<File Path=".gitignore" />
<File Path=".netconfig" />
<File Path="README.md" />
<File Path="Directory.Build.targets" />
<File Path="stryker-config.json" />
<File Path="LICENSE" />
<File Path="Directory.Build.props" />
<File Path="stylecop.json" />
<File Path="Directory.Packages.props" />
<File Path=".deepsource.toml" />
</Folder>
<Folder Name="/Solution Items/.config/">
<File Path=".config\dotnet-tools.json" />
</Folder>
<Folder Name="/Solution Items/.github/">
<File Path=".github\CODEOWNERS" />
<File Path=".github\dependabot.yml" />
</Folder>
<Folder Name="/Solution Items/.github/workflows/">
<File Path=".github\workflows\dotnet.yml" />
<File Path=".github\workflows\codeql.yml" />
<File Path=".github\workflows\dependency-review.yml" />
<File Path=".github\workflows\scorecard.yml" />
</Folder>
<Folder Name="/Solution Items/tools/">
<File Path="tools\code-coverage.bat" />
<File Path="tools\code-coverage.ps1" />
<File Path="tools\mutation-testing.bat" />
<File Path="tools\mutation-testing.ps1" />
<File Path="tools\benchmarks.bat" />
<File Path="tools\benchmarks.ps1" />
</Folder>
<Folder Name="/src/">
<Project Path="src\OffDotNet.CodeAnalysis.Pdf\OffDotNet.CodeAnalysis.Pdf.csproj" Type="Classic C#" />
<Project Path="src\OffDotNet.CodeAnalysis\OffDotNet.CodeAnalysis.csproj" Type="Classic C#" />
<File Path="src\Directory.Build.props" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests\OffDotNet.CodeAnalysis.Pdf.Tests\OffDotNet.CodeAnalysis.Pdf.Tests.csproj" Type="Classic C#" />
<Project Path="tests\OffDotNet.CodeAnalysis.Tests\OffDotNet.CodeAnalysis.Tests.csproj" Type="Classic C#" />
<File Path="tests\Directory.Build.props" />
</Folder>
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Configurations;
namespace OffDotNet.CodeAnalysis.Pdf.Configs;

public sealed record DiagnosticOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Pdf.Configurations;
namespace OffDotNet.CodeAnalysis.Pdf.Configs;

using OffDotNet.CodeAnalysis.Configs;

public sealed record RootConfigurations
{
public const string SectionName = "OffDotNet";

public required DiagnosticOptions Diagnostic { get; init; }

public required TextCursorOptions TextCursor { get; init; }
}
3 changes: 2 additions & 1 deletion src/OffDotNet.CodeAnalysis.Pdf/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

using OffDotNet.CodeAnalysis.Pdf.Configs;

namespace OffDotNet.CodeAnalysis.Pdf;

using Configurations;
using Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using OffDotNet.CodeAnalysis.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

using OffDotNet.CodeAnalysis.Pdf.Configs;

namespace OffDotNet.CodeAnalysis.Pdf.Diagnostics;

using Configurations;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OffDotNet.CodeAnalysis.Diagnostics;
Expand Down
4 changes: 2 additions & 2 deletions src/OffDotNet.CodeAnalysis.Pdf/Syntax/RawSyntaxToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ internal static RawSyntaxToken Create(SyntaxKind kind, Option<AbstractNode> lead
/// <param name="trailing">Whether to include trailing trivia.</param>
protected override void WriteTokenTo(TextWriter writer, bool leading, bool trailing)
{
if (leading && LeadingTrivia.IsSome(out var leadingTrivia))
if (leading && LeadingTrivia.TryGetValue(out var leadingTrivia))
{
leadingTrivia.WriteTo(writer, leading: true, trailing: false);
}

writer.Write(this.Text);

if (trailing && TrailingTrivia.IsSome(out var trailingTrivia))
if (trailing && TrailingTrivia.TryGetValue(out var trailingTrivia))
{
trailingTrivia.WriteTo(writer, leading: false, trailing: true);
}
Expand Down
11 changes: 11 additions & 0 deletions src/OffDotNet.CodeAnalysis/Configs/TextCursorOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// <copyright file="TextCursorOptions.cs" company="Sunt Programator">
// Copyright (c) Sunt Programator. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>

namespace OffDotNet.CodeAnalysis.Configs;

public sealed record TextCursorOptions
{
public int WindowSize { get; init; } = 2048;
}
2 changes: 1 addition & 1 deletion src/OffDotNet.CodeAnalysis/Lexer/ISourceText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface ISourceText

byte this[int position] { get; }

void CopyTo(int sourceIndex, byte[] destination, int destinationIndex, int count);
void CopyTo(int sourceIndex, Span<byte> destination, int destinationIndex, int count);
}
26 changes: 17 additions & 9 deletions src/OffDotNet.CodeAnalysis/Lexer/ITextCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,31 @@ public interface ITextCursor : IDisposable
bool IsAtEnd { get; }

/// <summary>Gets the start offset inside the window (relative to the <see cref="ISourceText"/> start).</summary>
int Basis { get; }
int WindowStart { get; }

/// <summary>Gets the end offset inside the window (relative to the <see cref="Basis"/>).</summary>
/// <summary>Gets the end offset inside the window (relative to the <see cref="WindowStart"/>).</summary>
int Offset { get; }

/// <summary>Gets the absolute position in the <see cref="ISourceText"/>.</summary>
int Position => Basis + Offset;
int Position => WindowStart + Offset;

/// <summary>Gets a value indicating whether the window is in parsing lexeme mode.</summary>
bool IsLexemeMode { get; }

/// <summary>Gets the lexeme start offset relative to the <see cref="Basis">window start</see>.</summary>
int LexemeBasis { get; }
/// <summary>Gets the lexeme start offset relative to the <see cref="WindowStart">window start</see>.</summary>
int LexemeStart { get; }

/// <summary>Gets the absolute position of the lexeme in the <see cref="ISourceText"/>.</summary>
int LexemePosition => Basis + LexemeBasis;
int LexemePosition => WindowStart + LexemeStart;

/// <summary>Gets the width of the lexeme.</summary>
int LexemeWidth => Offset - LexemeBasis;
int LexemeWidth => Offset - LexemeStart;

/// <summary>Gets the text window.</summary>
ReadOnlyMemory<byte> Window { get; }

/// <summary>Gets the number of characters in the window.</summary>
int WindowCount { get; }
int WindowSize { get; }

/// <summary>
/// Peeks at the byte at the specified delta from the current position.
Expand Down Expand Up @@ -99,7 +102,12 @@ public interface ITextCursor : IDisposable
/// <returns>True if the cursor was advanced; otherwise, false.</returns>
bool TryAdvance(ReadOnlySpan<byte> subtext);

/// <summary>Starts parsing a lexeme and sets the <see cref="LexemeBasis"/> to the current <see cref="Offset"/> value.</summary>
/// <summary>Slides the text window to the specified start position and size.</summary>
/// <param name="windowStart">The start position of the window.</param>
/// <param name="windowSize">The size of the window.</param>
void SlideTextWindow(int windowStart = -1, int windowSize = -1);

/// <summary>Starts parsing a lexeme and sets the <see cref="LexemeStart"/> to the current <see cref="Offset"/> value.</summary>
public void StartLexemeMode();

/// <summary>Stops parsing a lexeme.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/OffDotNet.CodeAnalysis/Lexer/StringText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal StringText(in ReadOnlySpan<byte> source)

public byte this[int position] => Source.Span[position];

public void CopyTo(int sourceIndex, byte[] destination, int destinationIndex, int count)
public void CopyTo(int sourceIndex, Span<byte> destination, int destinationIndex, int count)
{
Source.Span.Slice(sourceIndex, count).CopyTo(destination.AsSpan(destinationIndex));
Source.Span.Slice(sourceIndex, count).CopyTo(destination[destinationIndex..]);
}
}
Loading

0 comments on commit f17b961

Please sign in to comment.