Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jan 7, 2026

This PR introduces a new internal utils crate to centralize shared utility logic and replaces the heavy regex dependency with a lightweight, custom implementation. These changes significantly reduce compilation times and the final binary size by eliminating the overhead of the regex engine for simple string operations.

Key Changes

1. New utils Crate

Created a dedicated workspace member for project-wide utilities:

  • utils/src/colorex.rs: Centralized terminal color formatting logic, moving it into a controlled internal module.
  • utils/src/formatx.rs: Implemented a lightweight count_placeholders function to handle Wave's format string validation logic ({} counting).
  • Workspace Integration: Updated the root Cargo.toml to include utils and configured dependencies across all crates.

2. Dependency Optimization

  • Regex Removal: Successfully removed the regex crate from front/parser/Cargo.toml.
  • Logic Migration: Replaced the regex::Regex based placeholder counting in front/parser/src/parser/io.rs with the more efficient utils::formatx::count_placeholders. This eliminates the need to compile the entire regex engine just for bracket counting.

3. Project-Wide Integration

  • Error Reporting: Updated front/error to use utils::colorex for colored diagnostic output.
  • CLI & Core: Refactored src/main.rs and src/lib.rs to consume color utilities from the new utils crate, ensuring a consistent UI across the compiler.

Benefits

  • Faster Compile Times: Removing the complex regex macro and engine reduces total build time significantly.
  • Smaller Binary Size: By using a simple character-scanning algorithm for placeholders instead of a regex DFA/NFA, the footprint of the compiler is reduced.
  • Maintainability: Shared logic (colors, formatting) is now in a single location, preventing duplication across front/error, front/parser, and the main CLI.

Create a new `utils` crate to centralize utility functions and remove
the heavy `regex` dependency, replacing it with a custom lightweight
placeholder parser. Also integrates the `colorex` module.

Changes:
- **New Crate `utils`**:
  - Added `utils/src/colorex.rs`: Custom color formatting logic (moved from `colorex` crate or inline).
  - Added `utils/src/formatx.rs`: Implements `count_placeholders` to replace regex usage for `{}` counting.
  - Updated workspace `Cargo.toml` to include `utils`.
- **Dependency Removal**:
  - Removed `regex` from `front/parser/Cargo.toml`.
  - Replaced `regex::Regex` usage in `front/parser/src/parser/io.rs` with `utils::formatx::count_placeholders`.
- **Integration**:
  - Updated `front/error/Cargo.toml` and `Cargo.toml` to depend on `utils`.
  - Updated `src/main.rs`, `src/lib.rs`, and `front/error/src/error.rs` to use `utils::colorex`.
- **Cleanup**:
  - Removed placeholder `lib.rs` content in `utils`.

This change significantly reduces compilation time and binary size by
eliminating the regex engine dependency.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Jan 7, 2026
@LunaStev LunaStev added this to Wave Jan 7, 2026
@LunaStev LunaStev merged commit 53151ee into wavefnd:master Jan 7, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this to Done in Wave Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant