Skip to content

Restrict module top-level statements#2728

Merged
plajjan merged 1 commit into
mainfrom
declarative-modules
Apr 16, 2026
Merged

Restrict module top-level statements#2728
plajjan merged 1 commit into
mainfrom
declarative-modules

Conversation

@plajjan

@plajjan plajjan commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

The parser has a consistent statement grammar across module bodies and nestes suites so the syntax remains simple with uniform parsing. However, we do in fact want a somewhat stricter grammar on the module top level.

This change keeps the shared parsing structure and validates parsed module suites afterwards. Only declarations, signatures, and assignments are accepted at the module top level, and top-level assignment names are tracked so rebinding a module constant is rejected early. Explicit module docstrings before imports still work, while stray bare strings in module bodies no longer do.

This makes the parser more restrictive only where the language requires it, without splitting module parsing off into a separate statement grammar.

@plajjan plajjan force-pushed the declarative-modules branch 2 times, most recently from 26f6079 to bfb9a98 Compare April 16, 2026 10:18
The parser has a shared statement grammar across module bodies and
nested suites, but the module top level is meant to define constants
and declarations rather than execute arbitrary code.

This change keeps the shared parser structure and validates parsed
module suites afterwards. Only declarations, signatures, and
assignments are accepted at the module top level, and top-level
assignment names are tracked so rebinding a module constant is
rejected early.
@plajjan plajjan force-pushed the declarative-modules branch from bfb9a98 to 1c0cd76 Compare April 16, 2026 11:34
@plajjan plajjan marked this pull request as ready for review April 16, 2026 18:09
@plajjan plajjan merged commit 2aa06a3 into main Apr 16, 2026
317 of 352 checks passed
@plajjan plajjan deleted the declarative-modules branch April 16, 2026 18:10
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.

1 participant