Skip to content

[string_scanner] Extract LineScannerMixin and deduplicate eager scann… - #2569

Open
amanmaurya92 wants to merge 4 commits into
dart-lang:mainfrom
amanmaurya92:refactor-string-scanner-mixin
Open

[string_scanner] Extract LineScannerMixin and deduplicate eager scann…#2569
amanmaurya92 wants to merge 4 commits into
dart-lang:mainfrom
amanmaurya92:refactor-string-scanner-mixin

Conversation

@amanmaurya92

Copy link
Copy Markdown
Contributor

Description

This PR refactors LineScanner and EagerSpanScanner in package:string_scanner to share eager line and column tracking implementation via LineScannerMixin:

  • Deduplication: Extracted shared line/column state tracking, position= setter logic, _adjustLineAndColumn, scanChar, readChar, and scan into mixin LineScannerMixin on StringScanner.
  • EagerSpanScanner cleanup: Updated EagerSpanScanner to use with LineScannerMixin, eliminating ~120 lines of duplicate regex-based state tracking and removing the legacy TODO(nweiz) tracking sdk#23770.
  • Zero Breaking Changes: Preserves existing class contracts, behavior, and public API compatibility.
  • Changelog: Added an entry in pkgs/string_scanner/CHANGELOG.md.

Verification

  • dart analyze: 0 issues found.
  • dart test: All 185 tests passed across line_scanner, span_scanner, string_scanner, and error_test.
  • dart format: Code formatted according to Dart style guide.

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.

@amanmaurya92
amanmaurya92 requested a review from a team as a code owner August 30, 2026 19:11

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the line and column tracking logic by introducing a new LineScannerMixin on StringScanner. This mixin is then used by both LineScanner and EagerSpanScanner, successfully eliminating a significant amount of duplicated code. The feedback suggests adding a code example to the documentation of the newly introduced public LineScannerMixin to comply with the repository's style guide.

Comment thread pkgs/string_scanner/lib/src/line_scanner.dart
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.

1 participant