Skip to content

Pre-Flatten Comment Messages in the Parser Rules - #828

Merged
InsertCreativityHere merged 3 commits into
icerpc:mainfrom
InsertCreativityHere:pre-flatten-comment-messages
Sep 14, 2026
Merged

InsertCreativityHere merged 3 commits into
icerpc:mainfrom
InsertCreativityHere:pre-flatten-comment-messages

Conversation

@InsertCreativityHere

Copy link
Copy Markdown
Member

This PR makes a slight simplification to the grammar rules used to parse doc-comment messages, which I noticed while working on #800.

What's Changed

None - This PR is just an internal simplification of the grammar rules used to parse doc-comments with no side-effects.

@InsertCreativityHere InsertCreativityHere added this to the 0.4.1 milestone Sep 14, 2026
@InsertCreativityHere InsertCreativityHere added easy Good for newcomers slicec Related to the 'slicec' crate labels Sep 14, 2026
}
}

Message = MessageComponent+;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At a grammar level, these two constructs should be equivalent:
(MessageComponent+)? (match 1 more components, but also accept 0 components)
MessageComponent* (match 0 or more components)

But in addition to being a simpler rule, it also simplifies the types.
The 1st expression gives Option<Vec<...>>, whereas the 2nd gives just Vec<...>.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Blank lines can panic, and empty inline messages now produce different AST output.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Simplifies doc-comment parsing by making Message directly nullable and removing nested option flattening.

Changes:

  • Uses empty component vectors for blank message lines.
  • Updates message construction and whitespace sanitization accordingly.
File summaries
File Description
grammar.rs Adapts message sanitization to flattened lines.
grammar.lalrpop Simplifies nullable message grammar rules.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread slicec/src/parsers/comments/grammar.rs Resolved
Comment thread slicec/src/parsers/comments/grammar.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The refactor preserves existing parsing behavior; only minor stale comment wording remains.

Review details

Suppressed comments (1)

slicec/src/parsers/comments/grammar.rs:125

  • The comment implies newline insertion only happens when text is present, while empty lines also receive a newline. Reword it to describe both operations accurately.
            if let Some(MessageComponent::Text(text)) = line.first_mut() {
                text.replace_range(..common_leading_whitespace, "");
            }
            line.push(MessageComponent::Text("\n".to_owned()));
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

// To check the start of the line, we check the first message component.
// It's safe to unwrap because we know the line was non-empty in this block.
match message.first().unwrap() {
match message {
@InsertCreativityHere
InsertCreativityHere merged commit b6e4900 into icerpc:main Sep 14, 2026
6 checks passed
InsertCreativityHere added a commit that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

easy Good for newcomers slicec Related to the 'slicec' crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants