Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jan 4, 2026

This PR performs a major refactoring of the parsing logic by decomposing the monolithic parser.rs and the auxiliary type_system.rs into a well-structured directory of specialized submodules. This change significantly improves the maintainability and navigability of the frontend logic.

Key Changes

1. Parser Modularization

The parser has been split into the following submodules within front/parser/src/parser/:

  • asm.rs: Logic for parsing inline assembly blocks (asm { ... }).
  • control.rs: Handles control flow structures including if, while, and for loops.
  • decl.rs: Consolidates variable and constant declarations (const, let, mut, var).
  • expr.rs: Manages expression-related parsing such as function calls and grouped parentheses.
  • functions.rs: Handles function definitions, parameter lists, and body extraction.
  • io.rs: Logic for I/O statements including print, println, and input.
  • items.rs: Parsing for top-level items such as import, proto, and struct.
  • stmt.rs: Generic statement handling, including assignments and block parsing ({ ... }).
  • types.rs: Consolidated type parsing logic (moved from the now-deleted type_system.rs).
  • parse.rs: The primary entry point containing the main parse() function.

2. Cleanup & Integration

  • Type System Consolidation: Removed front/parser/src/parser/type_system.rs and integrated its logic into parser/types.rs to keep type-related parsing logic in one place.
  • Import Optimization: Updated mod.rs to export the new module structure and refactored imports across the wavec crate (specifically in main.rs and runner.rs) to resolve warnings and ensure compatibility with the new structure.
  • Standardization: No functional logic was altered during this move; the IR and AST produced remain identical to the previous version.

Impact

  • Maintainability: Large-scale changes to specific language features (e.g., adding a new loop type) can now be done within a single, focused file.
  • Readability: Reduces the "wall of code" effect previously found in the 1500+ line parser.rs.
  • Compile Times: Modular files can potentially benefit from incremental compilation improvements.

Split the large `parser.rs` file into logical submodules within
`front/parser/src/parser/` to improve code structure and maintainability.

Changes:
- **New Module Structure**:
  - `asm.rs`: `parse_asm_block`
  - `control.rs`: `parse_if`, `parse_while`, `parse_for`
  - `decl.rs`: `parse_variable_decl`, `parse_const`, `parse_let`, `parse_var`
  - `expr.rs`: `parse_function_call`, `parse_parentheses`
  - `functions.rs`: `parse_function`, `parse_parameters`, `extract_body`
  - `io.rs`: `parse_println`, `parse_print`, `parse_input`
  - `items.rs`: `parse_import`, `parse_proto`, `parse_struct`
  - `stmt.rs`: `parse_assignment`, `parse_block`, `parse_statement`
  - `types.rs`: Type parsing logic moved from `type_system.rs` (`parse_type`, `parse_type_from_token`, etc.)
  - `parse.rs`: Main `parse()` entry point and module declarations.
- **Cleanup**:
  - Removed `type_system.rs` (logic moved to `types.rs`).
  - Updated `mod.rs` to expose the new structure.
  - Fixed imports across the crate to point to new module locations.
  - Resolved unused import warnings in `main.rs` and `runner.rs`.

This refactoring decouples parser components, making it easier to navigate
and extend individual language features.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Jan 4, 2026
@LunaStev LunaStev merged commit e90aba9 into wavefnd:master Jan 4, 2026
2 checks passed
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