Skip to content

feat: update ParseCursor#196

Merged
ianlewis merged 5 commits intomainfrom
118-parser-testability
Apr 13, 2026
Merged

feat: update ParseCursor#196
ianlewis merged 5 commits intomainfrom
118-parser-testability

Conversation

@ianlewis
Copy link
Copy Markdown
Owner

@ianlewis ianlewis commented Apr 13, 2026

Description:

  • Rename ParserContext to ParseCursor and separate it from the context.Context.
  • Add a NewParseCursor to allow creating a ParseCursor. This should be useful for testing parse functions individually.
  • Rename CustomLexerCursor to LexCursor to make it a little less long-winded. Also rename NewCustomLexerCursor to NewLexCursor.

Related Issues:

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.

- 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>
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 updates the lexing/parsing public APIs to improve testability by renaming the cursor/context types and passing context.Context separately.

Changes:

  • Renamed ParserContextParseCursor and updated ParseState.Run to accept (context.Context, *ParseCursor[V]).
  • Renamed CustomLexerCursorLexCursor and updated LexState.Run signatures 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.

Comment thread parser.go
Comment thread parser.go Outdated
Comment thread custom.go Outdated
Comment thread README.md Outdated
Comment thread template_example_test.go
Comment thread parser_test.go
Comment thread parser_test.go
Comment thread parser_test.go
Comment thread parser_test.go
Comment thread parser_test.go Outdated
Signed-off-by: Ian Lewis <ian@ianlewis.org>
Signed-off-by: Ian Lewis <ian@ianlewis.org>
Signed-off-by: Ian Lewis <ian@ianlewis.org>
@ianlewis ianlewis merged commit 12a87a4 into main Apr 13, 2026
24 checks passed
@ianlewis ianlewis deleted the 118-parser-testability branch April 13, 2026 12:19
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.

2 participants