Skip to content

Commit

Permalink
docs: Add XML Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Oct 13, 2024
1 parent fd18482 commit 8be2fe2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Source/Silverfly/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,45 @@ public bool IsSpecialToken(string tokenName)
return tokenName != "#" && tokenName.StartsWith('#');
}

/// <summary>
/// Opens a new lexer context of the specified type.
/// </summary>
/// <typeparam name="TContext">The type of the lexer context to open, which must implement <see cref="ILexerContext"/> and have a parameterless constructor.</typeparam>
/// <returns>A new instance of <see cref="LexerContext{TContext}"/> that allows setting the current context.</returns>
public LexerContext<TContext> OpenContext<TContext>()
where TContext : ILexerContext, new()
{
_context = new TContext();
return new LexerContext<TContext>((c) => _context = c);
}

/// <summary>
/// Retrieves the current lexer context of the specified type.
/// </summary>
/// <typeparam name="TContext">The type of the lexer context to retrieve, which must implement <see cref="ILexerContext"/> and have a parameterless constructor.</typeparam>
/// <returns>The current context of type <typeparamref name="TContext"/>.</returns>
/// <exception cref="InvalidCastException">Thrown if the current context is not of type <typeparamref name="TContext"/>.</exception>
public TContext GetContext<TContext>()
where TContext : ILexerContext, new()
{
return (TContext)_context;
}

/// <summary>
/// Checks if the current context is of the specified type.
/// </summary>
/// <typeparam name="TContext">The type to check against, which must implement <see cref="ILexerContext"/> and have a parameterless constructor.</typeparam>
/// <returns><c>true</c> if the current context is of type <typeparamref name="TContext"/>; otherwise, <c>false</c>.</returns>
public bool IsContext<TContext>()
where TContext : ILexerContext, new()
{
return _context is TContext;
}

/// <summary>
/// Determines whether there is currently an active lexer context.
/// </summary>
/// <returns><c>true</c> if there is an active context; otherwise, <c>false</c>.</returns>
public bool HasContext()
{
return _context is not null;
Expand Down

0 comments on commit 8be2fe2

Please sign in to comment.