Skip to content

feat: refactor API for CustomLexer#176

Merged
ianlewis merged 1 commit intomainfrom
173-feature-refactor-lexer-and-parser-api
Jan 25, 2026
Merged

feat: refactor API for CustomLexer#176
ianlewis merged 1 commit intomainfrom
173-feature-refactor-lexer-and-parser-api

Conversation

@ianlewis
Copy link
Copy Markdown
Owner

@ianlewis ianlewis commented Jan 25, 2026

Description:

Refactor the API for CustomLexer to add a CustomLexerContext. The context wraps the context.Context during lexing, and provides methods for accessing the input stream.

Related Issues:

Updates #173

Checklist:

  • Review the CONTRIBUTING.md documentation.
  • Add a reference to a related issue in the repository.
  • Add a description of the changes proposed in the pull request.
  • Add unit tests if applicable.
  • Update documentation if applicable.
  • Add a note in the CHANGELOG.md if applicable.

Refactor the API for `CustomLexer` to add a `CustomLexerContext`. The
context wraps the `context.Context` during lexing, and provides methods
for accessing the input stream.

Signed-off-by: Ian Lewis <ian@ianlewis.org>
@ianlewis ianlewis linked an issue Jan 25, 2026 that may be closed by this pull request
@ianlewis ianlewis requested a review from Copilot January 25, 2026 06:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the CustomLexer API by introducing a new CustomLexerContext type that wraps context.Context and provides access to lexer methods. The refactoring moves lexer interaction methods from CustomLexer to CustomLexerContext, changing the signature of LexState.Run to accept the new context type instead of both context.Context and *CustomLexer.

Changes:

  • Introduced CustomLexerContext type that embeds context.Context and provides methods for lexer interaction
  • Updated LexState.Run signature to accept *CustomLexerContext instead of context.Context and *CustomLexer
  • Moved public lexer methods (Peek, Advance, Emit, etc.) to CustomLexerContext while keeping implementation in CustomLexer as private methods
  • Updated all lexer state functions and tests to use the new API
  • Updated tests to use t.Context() instead of manually creating contexts with cancel functions

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
custom.go Added CustomLexerContext type with public methods delegating to private CustomLexer methods; updated LexState interface
custom_test.go Updated all test functions to use CustomLexerContext instead of direct CustomLexer access; renamed tests to reflect context usage
template_example_test.go Updated lexer state functions to accept *CustomLexerContext parameter
ini_example_test.go Updated lexer state functions to accept *CustomLexerContext parameter
lexparse_test.go Updated test contexts to use t.Context() and updated lexErrState.Run signature
CHANGELOG.md Added entry documenting the API refactoring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ianlewis ianlewis merged commit 1214b4b into main Jan 25, 2026
24 checks passed
@ianlewis ianlewis deleted the 173-feature-refactor-lexer-and-parser-api branch January 25, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Refactor lexer and parser API

2 participants