Sitelet https://github.com/starkware-libs/cairo/pull/10107
Skip to content

fix(parser): treat //// as a regular comment, not a doc comment. - #10107

Merged
orizi merged 1 commit into
mainfrom
orizi/06-16-fix_parser_treat___as_a_regular_comment_not_a_doc_comment
Jun 16, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-16-fix_parser_treat___as_a_regular_comment_not_a_doc_comment

Conversation

@orizi

@orizi orizi commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix the lexer so that //// (four or more slashes) is classified as a regular TokenSingleLineComment rather than a TokenSingleLineDocComment. Previously, any line starting with /// was treated as a doc comment, including ////, ////, etc. Now, only exactly /// (where the fourth character is not /) is recognized as a doc comment, aligning the lexer with cairo-lang-doc's behavior of discarding doc comments whose content begins with /.

A test is added to verify that // regular, /// doc, //! inner, ////, and ///// are each classified into the correct token kinds.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

cairo-lang-doc already discards any doc comment whose content starts with /, meaning //// was never treated as a real doc comment at the documentation-generation level. However, the lexer was still emitting TokenSingleLineDocComment for ////, creating an inconsistency between the lexer's token classification and how the doc tooling actually interprets those tokens.


What was the behavior or documentation before?

Any comment beginning with /// — including ////, /////, etc. — was lexed as TokenSingleLineDocComment.


What is the behavior or documentation after?

Only /// where the fourth character is not / is lexed as TokenSingleLineDocComment. Four or more consecutive slashes produce a plain TokenSingleLineComment, consistent with cairo-lang-doc.


Related issue or discussion (if any)

N/A


Additional context

The guard self.peek_nth(3) != Some('/') is added to the Some('/') match arm in match_trivium_single_line_comment, and a dedicated test test_doc_comment_classification covers all relevant cases.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi marked this pull request as ready for review June 16, 2026 07:43
@cursor

cursor Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Narrow lexer trivia classification fix with a dedicated test; no auth, data, or broad parser behavior changes beyond ////+ comment lines.

Overview
Fixes a lexer/doc tooling mismatch: lines with four or more leading slashes (////, /////, …) are now TokenSingleLineComment instead of TokenSingleLineDocComment.

In match_trivium_single_line_comment, the /// arm only applies when the fourth character is not another / (peek_nth(3) != Some('/')), so exactly /// stays a doc comment while //! inner docs are unchanged.

Adds test_doc_comment_classification to assert trivia kinds for //, ///, //!, ////, and /////, aligned with cairo-lang-doc ignoring doc comments whose content starts with /.

Reviewed by Cursor Bugbot for commit 4fc0ccf. Bugbot is set up for automated code reviews on this repo. Configure here.

@eytan-starkware eytan-starkware 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.

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@orizi
orizi added this pull request to the merge queue Jun 16, 2026
Merged via the queue into main with commit 493a32b Jun 16, 2026
55 checks passed
@orizi
orizi deleted the orizi/06-16-fix_parser_treat___as_a_regular_comment_not_a_doc_comment branch June 16, 2026 11:00
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.

3 participants