Skip to content

docs: add Panics sections to line_col() and PrattParser::parse()#1167

Merged
tomtau merged 1 commit into
pest-parser:masterfrom
MasterOfFeelingFish:clawoss/docs/document-panics
Apr 19, 2026
Merged

docs: add Panics sections to line_col() and PrattParser::parse()#1167
tomtau merged 1 commit into
pest-parser:masterfrom
MasterOfFeelingFish:clawoss/docs/document-panics

Conversation

@MasterOfFeelingFish
Copy link
Copy Markdown
Contributor

@MasterOfFeelingFish MasterOfFeelingFish commented Apr 19, 2026

Two public functions that can panic were missing # Panics documentation:

  • Position::line_col() panics when the position is out of bounds
  • PrattParser::parse() panics when mappers are missing for operator types or unexpected tokens are encountered

Addresses #999

Summary by CodeRabbit

  • Documentation
    • Updated library API documentation to clarify edge case behaviors and error scenarios.

@MasterOfFeelingFish MasterOfFeelingFish requested a review from a team as a code owner April 19, 2026 03:44
@MasterOfFeelingFish MasterOfFeelingFish requested review from tomtau and removed request for a team April 19, 2026 03:44
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 19, 2026

📝 Walkthrough

Walkthrough

This pull request adds Rustdoc documentation to two public functions in the pest library, specifically documenting the panic conditions that occur when functions receive out-of-bounds or invalid input. No functional logic or control flow was modified.

Changes

Cohort / File(s) Summary
Documentation Updates
pest/src/position.rs, pest/src/pratt_parser.rs
Added "# Panics" sections to Rustdoc comments for Position::line_col() and PrattParserMap::parse(), explicitly documenting conditions that cause panics when input is out of bounds or missing required mappings.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A rabbit hops through docs so bright,
Adding panic notes left and right,
When bounds are wrong or maps run thin,
Now readers know just where they've been!
Fear no more, dear functions dear—
Your panic paths are crystal clear! 📚

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding documentation sections for panic conditions in two public functions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pest/src/pratt_parser.rs (1)

315-319: Consider documenting the empty pairs panic condition.

The documentation accurately covers the panic conditions for missing mappers and unexpected tokens. However, it doesn't mention that parse() also panics when pairs is empty (as shown in Line 342's expect call). While this is documented at the struct level (Line 104), including it here would make the method documentation more complete and self-contained.

📝 Suggested enhancement
 /// # Panics
 ///
-/// Panics if the input pairs contain a prefix operator with no [`map_prefix`],
+/// Panics if the input pairs are empty, contain a prefix operator with no [`map_prefix`],
 /// an infix operator with no [`map_infix`], a postfix operator with no [`map_postfix`],
 /// or an unexpected token that is not a valid prefix, primary, infix, or postfix expression.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pest/src/pratt_parser.rs` around lines 315 - 319, Update the parse() method
docs to also state that it will panic when the provided pairs iterator is empty
(the expect call at parse()'s body will trigger), so the panic conditions list
includes "panics if pairs is empty" in addition to the existing missing mapper
and unexpected token cases; reference the parse() function and the struct-level
note (previously at the struct doc) to make this method's documentation
self-contained.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pest/src/pratt_parser.rs`:
- Around line 315-319: Update the parse() method docs to also state that it will
panic when the provided pairs iterator is empty (the expect call at parse()'s
body will trigger), so the panic conditions list includes "panics if pairs is
empty" in addition to the existing missing mapper and unexpected token cases;
reference the parse() function and the struct-level note (previously at the
struct doc) to make this method's documentation self-contained.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c88bdf10-0a68-45cb-b477-80e21bcf45be

📥 Commits

Reviewing files that changed from the base of the PR and between 2a69a98 and 192e9a3.

📒 Files selected for processing (2)
  • pest/src/position.rs
  • pest/src/pratt_parser.rs

Copy link
Copy Markdown
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

thanks!

@tomtau tomtau merged commit 02c5ad8 into pest-parser:master Apr 19, 2026
10 checks passed
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