Conversation
- Rename `ParserContext` to `ParseCursor` and separate it from the `context.Context`. - Rename `CustomLexerCursor` to `LexCursor` to make it a little less long-winded. Signed-off-by: Ian Lewis <ian@ianlewis.org>
Signed-off-by: Ian Lewis <ian@ianlewis.org>
There was a problem hiding this comment.
Pull request overview
This PR updates the lexing/parsing public APIs to improve testability by renaming the cursor/context types and passing context.Context separately.
Changes:
- Renamed
ParserContext→ParseCursorand updatedParseState.Runto accept(context.Context, *ParseCursor[V]). - Renamed
CustomLexerCursor→LexCursorand updatedLexState.Runsignatures accordingly. - Updated examples/tests/docs/changelog to use the new cursor types and constructors (
NewParseCursor,NewLexCursor).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
parser.go |
Introduces ParseCursor, updates ParseState API, and wires Parser.Parse to pass ctx + cursor. |
custom.go |
Renames lexer cursor to LexCursor, updates LexState function types and lexer execution. |
README.md |
Updates documentation/examples to reflect the new cursor types and parsing API. |
CHANGELOG.md |
Notes the renames in the Unreleased section. |
template_example_test.go |
Updates template lexer/parser example code to the new cursor APIs. |
ini_example_test.go |
Updates INI lexer/parser example code to the new cursor APIs. |
infix_example_test.go |
Updates Pratt parser example to accept context.Context + ParseCursor. |
lexparse_test.go |
Updates parser state implementations and lexer state signatures to the new APIs. |
parser_test.go |
Refactors parser tests to construct/use ParseCursor explicitly. |
custom_test.go |
Refactors lexer cursor tests to use LexCursor/NewLexCursor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Ian Lewis <ian@ianlewis.org>
Signed-off-by: Ian Lewis <ian@ianlewis.org>
Signed-off-by: Ian Lewis <ian@ianlewis.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
ParserContexttoParseCursorand separate it from thecontext.Context.NewParseCursorto allow creating aParseCursor. This should be useful for testing parse functions individually.CustomLexerCursortoLexCursorto make it a little less long-winded. Also renameNewCustomLexerCursortoNewLexCursor.Related Issues:
Checklist:
CONTRIBUTING.mddocumentation.CHANGELOG.mdif applicable.