Skip to content

Commit

Permalink
Updated lexer abstractions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Mar 30, 2024
1 parent db42a08 commit ba9d6a8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/Pasper/Parsing/ILexer.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
using System.Collections;

namespace Pasper.Parsing;

/// <summary>
/// Represents a lexer for a serialization format.
/// </summary>
public interface ILexer
: IEnumerator<IToken?>
{
/// <summary>
/// Gets the token at the previous position of the lexer.
/// </summary>
public IToken? Previous { get; }

/// <summary>
/// Gets the token at the current position of the lexer.
/// </summary>
public IToken? Current { get; }

/// <summary>
/// Advances the lexer to the next token.
/// </summary>
/// <returns>
/// <see langword="true"/> if the lexer was successfully advanced to the next token;
/// otherwise, <see langword="false"/>.
/// </returns>
public bool MoveNext();

/// <summary>
/// Resets the lexer to its initial position.
/// </summary>
public void Reset();
}
50 changes: 50 additions & 0 deletions src/Pasper/Parsing/Lexer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections;

namespace Pasper.Parsing;

/// <summary>
/// Represents a lexer for a serialization format.
/// </summary>
public abstract class Lexer
: ILexer
{
private bool _disposed;

/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <inheritdoc/>
public abstract bool MoveNext();

/// <inheritdoc/>
public abstract void Reset();

/// <inheritdoc/>
public IToken? Current { get; protected set; }

/// <inheritdoc/>
object IEnumerator.Current =>
Current!;

/// <inheritdoc/>
public IToken? Previous { get; protected set; }

/// <summary>
/// Releases the unmanaged resources used by the <see cref="Lexer"/> and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">Indicates whether the method was called from the <see cref="Dispose"/> method.</param>

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.

Check failure on line 39 in src/Pasper/Parsing/Lexer.cs

View workflow job for this annotation

GitHub Actions / build

Ambiguous reference in cref attribute: 'Dispose'. Assuming 'Lexer.Dispose()', but could have also matched other overloads including 'Lexer.Dispose(bool)'.
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;

if (!disposing)
return;

_disposed = true;
}
}

0 comments on commit ba9d6a8

Please sign in to comment.