The macro system and #![imports] syntax just landed, paving the way for more complex multi-file programs and new attribute-driven function features in Cx. The recent commit (cda45f7) merged as PR #17, introduced these key changes, complete with nine new matrix tests (t65-t73) all passing. This marks a big step, as the total matrix tests jumped from 63 to 72.
What shipped
Key changes affected 8 source files and brought in 9 additional test files. In total, 22 files changed, with +210 and -13 lines. Here's the breakdown:
Lexer changes. Introduced two new tokens: MacroInnerOpen (#![) and MacroOuterOpen (#[). The existing PunctBracketClose token now serves as the closing delimiter for both.
Import block parsing. A new ImportDecl AST node with alias, path, and position arrives alongside a Stmt::ImportBlock variant. This allows the parser to handle the #![imports] block properly:
#![imports]
math: use "std/math"
player: use "./player"
import_decl and import_block combinators now parse these alias-colon-use-path structures within the block.
Import semantic validation. The system now catches duplicate aliases and enforces path restrictions, allowing only ./ (relative) and std/ (stdlib) paths. This is strictly syntax validation for now; actual file loading and resolution aren't implemented yet. Syntax first, resolution next.
Outer macro parsing. Added CxMacro enum to the AST with six variants. Each outer macro, whether simple #[name] or #[name(args)], is parsed by the single_outer_macro combinator. A new macros: Vec field now sits under Stmt::FuncDef.
Outer macro semantic validation. Enforcement rules in place:
- No return types for
#[test]functions. -
#[reactive]and#[cfg]produce locked "reserved, post-v0.1" errors. - Unknown macro names are immediately rejected.
-
#[test],#[inline], and#[deprecated]tags are allowed on functions.
Matrix tests. Comprehensive testing covers all macro and import behavior:
- t65: Basic imports parsing in block
- t66: Standard library paths imported with
std/ - t67:
#[test]attribute in functional context - t68: Using
#[deprecated]attribute - t69-t73: Various rejection and validation scenarios (expected fail tests)
Design decisions
Import syntax, not resolution. #![imports] parsing and validation exist, catching any mishaps, like duplicate aliases or invalid paths. But without file loading, multi-file programs can't yet run. Validation leads, resolution follows.
Structured outer macros. Only six outer macro types exist. No extension yet in Cx 0.1, with #[reactive] and #[cfg] specifically reserved for later.
Test capabilities are building up. Parsing and validation happen for #[test], but no runner operates yet. Likewise, std/ paths parse, but resolution lags. These elements are inching toward a full Cx test system, piece by piece.
Roadmap movement
Must Ship tasks now check off #![import] block parsing. Macro and Import syntax's sprint status recently turned Done. Syntax implementation is complete, pushing module resolution into Active, though heavier work on file operations and detection remains.
We face two tough blockers: effective multi-file import functionality and fully functioning test runner development. The syntax aspect is rolling, but multi-file execution isn't yet seamless.
What's next
Tackling module resolution tops the list. Ensuring use "./player" brings actual player.cx file content to the importer is essential, involving public symbol resolution and accessibility.
The processes around the test runner and assert support are very close on the heels. Parsing of #[test] is there, and implementing assert(cond) and assert_eq(a, b) next, alongside cx test, would clear this blocker.
Generic structs Phase 3 and backend IR Phase 6 remain queued behind macros and imports work, ready to move once the immediate priorities settle.
Nine new tests now mean 72/72 pass, from a previous 63/63. Zero backward steps.
Follow the Cx language project:
- Website: cx-lang.com
- GitHub: github.com/COMMENTERTHE9/Cx_lang
- Dev.to: dev.to/commenterthe9
- Bluesky: thecomment.bsky.social
- Twitter/X: @commenterthe9
Originally published at https://cx-lang.com/blog/2026-03-24
Top comments (0)