diff --git a/Source/Silverfly/Lexer.cs b/Source/Silverfly/Lexer.cs index 4727e40..b97c6ba 100644 --- a/Source/Silverfly/Lexer.cs +++ b/Source/Silverfly/Lexer.cs @@ -319,6 +319,11 @@ public bool IsSpecialToken(string tokenName) return tokenName != "#" && tokenName.StartsWith('#'); } + /// + /// Opens a new lexer context of the specified type. + /// + /// The type of the lexer context to open, which must implement and have a parameterless constructor. + /// A new instance of that allows setting the current context. public LexerContext OpenContext() where TContext : ILexerContext, new() { @@ -326,12 +331,33 @@ public LexerContext OpenContext() return new LexerContext((c) => _context = c); } + /// + /// Retrieves the current lexer context of the specified type. + /// + /// The type of the lexer context to retrieve, which must implement and have a parameterless constructor. + /// The current context of type . + /// Thrown if the current context is not of type . + public TContext GetContext() + where TContext : ILexerContext, new() + { + return (TContext)_context; + } + + /// + /// Checks if the current context is of the specified type. + /// + /// The type to check against, which must implement and have a parameterless constructor. + /// true if the current context is of type ; otherwise, false. public bool IsContext() where TContext : ILexerContext, new() { return _context is TContext; } + /// + /// Determines whether there is currently an active lexer context. + /// + /// true if there is an active context; otherwise, false. public bool HasContext() { return _context is not null;