-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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(); | ||
} |
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
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_disposed) | ||
return; | ||
|
||
if (!disposing) | ||
return; | ||
|
||
_disposed = true; | ||
} | ||
} |