Skip to content

Make the std API inventory scanner respect nested comments and character literals #993

Closed

Description

@LunaStev

Problem

The API inventory generator uses regular expressions that stop a block comment at its first */ and do not recognize character literals. Valid source can therefore publish declarations that are still inside a comment or crash documentation generation on a public character constant.

Starting point: declarations. This is distinct from the contributor-owned Rust formatting helper PR #969; do not change that helper.

Reproduction

Audited canonical master 540728c2eb6cc12f5c69c3fb3fdb96e07ba059a4 on Linux amd64 with a checkout-built Wave 0.0.1-alpha-dev, matching checkout std, Rust 1.89.0 and LLVM 21.1.8. The compiler accepts this source with wavec check:

/* outer /* inner */
pub fun ghost() {}
*/
pub const C: char = '{';
pub fun real() {}
fun main() {}

Call the real Python scanner on its pieces:

from tools.document_std import declarations
print(list(declarations('/* outer /* inner */\npub fun ghost() {}\n*/\npub fun real() {}\n')))
print(list(declarations("pub const C: char = '{';\npub fun real() {}\n")))

The first returns both ghost and real, although ghost is commented out. The second raises ValueError: unterminated public const declaration because the character literal's brace changes scanner nesting.

Scope

Make this small declaration scanner lexically aware of supported nested block comments, strings, escaped character literals and delimiters. Preserve original declaration line numbers, target attributes, signatures and private-import exclusions. No compiler/frontend redesign or repository-wide reformat is required.

Completion criteria

  • Commented public-looking text never appears as API.
  • Character literals containing braces, semicolons, quotes and escapes do not change declaration boundaries.
  • Focused Python fixtures cover nested comments and source-line preservation; the real generated inventory stays deterministic and --check passes after regeneration.

Activity

  1. added
    bug
    good first issue
    on Oct 24, 2026
  2. hiyouwhatsapp commented on Oct 26, 2026

    @hiyouwhatsapp
    Contributor

    I put up #1053 for this

    The scanner now keeps nested comments out of the API list and skips quoted characters when looking for declaration boundaries
    Added tests for escaped chars and source lines too

  3. added a commit that references this issue on Oct 26, 2026
    3f7bf1c
  4. added a commit that references this issue on Nov 13, 2026
    7e484c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions