Skip to content

Add Lark.scan() for finding grammar matches in text, and parsing them.#1592

Open
erezsh wants to merge 3 commits into
masterfrom
scan_parse
Open

Add Lark.scan() for finding grammar matches in text, and parsing them.#1592
erezsh wants to merge 3 commits into
masterfrom
scan_parse

Conversation

@erezsh
Copy link
Copy Markdown
Member

@erezsh erezsh commented May 10, 2026

It finds and parses each non-overlapping match, yielding the longest possible match.

Reimplementation of the long-standing #1429 PR by @MegaIng on top of the merged TextSlice support, with some modifications.

Works in 2 steps. First parses without callbacks, for cheap cloning. Then finally replays the chosen match with user callbacks.

erezsh added 3 commits May 10, 2026 14:57
…uce__

Both methods only copied start_pos/line/column, silently dropping the end
positions.
It finds and parses each non-overlapping match, yielding the longest possible match.

Reimplementation of the long-standing #1429 PR on top of the merged
TextSlice support, with some modifications.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 98.58491% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.27%. Comparing base (eb015d1) to head (811ef1d).

Files with missing lines Patch % Lines
lark/lexer.py 95.65% 1 Missing ⚠️
lark/parser_frontends.py 98.24% 1 Missing ⚠️
tests/test_scan.py 99.21% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1592      +/-   ##
==========================================
+ Coverage   90.06%   90.27%   +0.21%     
==========================================
  Files          52       53       +1     
  Lines        8089     8297     +208     
==========================================
+ Hits         7285     7490     +205     
- Misses        804      807       +3     
Flag Coverage Δ
unittests 90.27% <98.58%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erezsh erezsh requested a review from MegaIng May 10, 2026 14:29
Copy link
Copy Markdown
Member

@MegaIng MegaIng left a comment

Choose a reason for hiding this comment

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

Looks very good, thank you for taking over this implementation, sorry for never getting around to it.

I genuinely don't have any detailed comments that aren't unrelated nits, this is very clean.

@erezsh
Copy link
Copy Markdown
Member Author

erezsh commented May 10, 2026

No worries, thanks for looking it over!

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