Skip to content

feat: implement module system foundation (parser + resolver)#2

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/implement-module-system
Draft

feat: implement module system foundation (parser + resolver)#2
Copilot wants to merge 6 commits intomainfrom
copilot/implement-module-system

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 16, 2025

Implements Phases 1-2 of the Shortcake module system per docs/MODULES.md: parser extensions and module resolution infrastructure.

Parser Extensions

  • mod keyword: New token type, AST node (mod_decl), and parsing logic
  • AST support: mod_info struct (module_name, file_path, is_main) with proper memory management
  • Import paths: Existing dotted path support (utils.math) works with new module system

Module Resolver

New src/module_resolver.zig provides:

  • Path resolution: utils.mathutils/math.sho
  • Search paths: Multi-directory module lookup
  • Circular imports: DFS-based detection (direct and indirect cycles)
  • Module cache: Avoid redundant parsing
  • Dependency tracking: Import graph for validation
var resolver = ModuleResolver.init(allocator);
try resolver.addSearchPath("/project/modules");
const file_path = try resolver.resolveModule("utils.math");  // → /project/modules/utils/math.sho

// Circular import detection
try resolver.addDependency("a", "b");
try resolver.addDependency("b", "a");
const circular = try resolver.detectCircularImports("a", &stack);  // → true

Example Module

mod

fn add(a: i32, b: i32): i32 = a + b
mod

import utils.math

fn main() do
  result = utils.math.add(5, 3)
end

Changes

  • src/parser.zig: parseModDecl(), mod_kw token recognition
  • src/ast.zig: mod_decl node type, setModInfo() helper
  • src/module_resolver.zig: New (370 lines)
  • test/test_module_parsing.zig: New - parser tests
  • test/test_module_resolver.zig: New - 10+ resolver tests
  • build.zig: Module registration

Next: Symbol resolution (import tracking, cross-module references)

Total: ~930 lines (implementation + tests)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/igorgue/shortcake/git/blobs/b609b3bc9890080ef4b7c1b1932209f194dc061e
    • Triggering command: `python3 -c
      import urllib.request
      import json
      import base64

url = 'REDACTED'
req = urllib.request.Request(url)
req.add_header('Accept', 'application/vnd.github.v3+json')

with urllib.request.urlopen(req) as response:
data = json.loads(response.read())
content = base64.b64decode(data['content']).decode('utf-8')
print(content)` (http block)

  • ziglang.org
    • Triggering command: wget -q REDACTED (dns block)
    • Triggering command: curl -sL REDACTED (dns block)
    • Triggering command: wget REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Module System v0</issue_title>
<issue_description>Implement the module system in Shortcake. Following the plan from docs/MODULES.md</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits November 16, 2025 18:37
Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Add mod_kw token type to TokenType enum
- Add mod keyword recognition in getKeywordType (length 3, 'm')
- Add mod_decl node type to AST NodeType enum
- Add mod_info struct to AST extra union with module_name, file_path, is_main fields
- Implement setModInfo helper method for setting module information
- Add mod_decl cleanup in deinit for proper memory management
- Implement parseModDecl function to parse module declarations
- Add module parsing to parseDeclaration dispatch
- Create test_module_parsing.zig with basic module parsing tests
- Register module parsing tests in build.zig

Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Add tests for dotted import paths (utils.math)
- Add tests for aliased imports (import X as Y)
- Add tests for selective imports (from X import a, b)
- Create simple module system example with utils.sho and main.sho
- Add expected output for module example
- Create MODULE_STATUS.md to track implementation progress

Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
…rt detection

- Create src/module_resolver.zig with ModuleResolver struct
- Implement module name to file path conversion (utils.math → utils/math.sho)
- Add search path management for module discovery
- Implement circular import detection using DFS algorithm
- Add module name extraction from file paths
- Create loaded modules cache to avoid redundant parsing
- Track import dependency graph for validation
- Add comprehensive tests for all resolver functionality
- Register module_resolver module in build.zig
- Create test_module_resolver.zig with 10+ test cases
- Update MODULE_STATUS.md - Phase 2 complete!

Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Create MODULE_IMPLEMENTATION_SUMMARY.md documenting all changes
- Detail Phases 1 & 2 implementation (parser + module resolver)
- Document design decisions and architecture
- List all files changed/added with line counts
- Provide usage examples and next steps
- Include testing strategy and coverage details
- Document compatibility and performance considerations

Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement module system in Shortcake feat: implement module system foundation (parser + resolver) Nov 16, 2025
Copilot AI requested a review from igorgue November 16, 2025 18:52
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.

Module System v0

2 participants