Skip to content

Commit ed25d7b

Browse files
committed
refactor(unilang): Adapt SemanticAnalyzer to new parser and data models
1 parent 49d3ddf commit ed25d7b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

module/move/unilang/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
22
### 2025-06-28 - Increment 6: Implement CLI Argument Parsing and Execution
33
* **Description:** Integrated the `unilang` core into a basic CLI application (`src/bin/unilang_cli.rs`). Implemented a `main` function to initialize `CommandRegistry`, register sample commands, parse command-line arguments, and use `Lexer`, `Parser`, `SemanticAnalyzer`, and `Interpreter` for execution. Handled errors by printing to `stderr` and exiting with a non-zero status code. Corrected `CommandDefinition` and `ArgumentDefinition` `former` usage. Implemented `as_integer` and `as_path` helper methods on `Value` in `src/types.rs`. Updated `CommandRoutine` signatures and return types in `src/bin/unilang_cli.rs` to align with `Result<OutputData, ErrorData>`. Corrected `Parser`, `SemanticAnalyzer`, and `Interpreter` instantiation and usage. Updated `cli_integration_test.rs` to match new `stderr` output format. Removed unused `std::path::PathBuf` import. Addressed Clippy lints (`unnecessary_wraps`, `needless_pass_by_value`, `uninlined_format_args`).
4-
* **Verification:** All tests passed, including `cli_integration_test.rs`, and `cargo clippy -p unilang -- -D warnings` passed.
4+
* **Verification:** All tests passed, including `cli_integration_test.rs`, and `cargo clippy -p unilang -- -D warnings` passed.
5+
* [2025-07-23] fix(unilang): Resolved compilation error in `unilang_cli.rs` by correcting the parser method and argument type.

module/move/unilang/src/semantic.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl< 'a > SemanticAnalyzer< 'a >
171171
let parsed_value = types::parse_value( &raw_value_str, &arg_def.kind )
172172
.map_err( |e| ErrorData {
173173
code : "INVALID_ARGUMENT_TYPE".to_string(),
174-
message : format!( "Invalid value for argument '{}': {}. Expected {:?}.", arg_def.name, e.reason, e.expected_kind ),
174+
message : format!( "Invalid value for argument '{}': {}. Expected {:?}.", arg_def.name, e.reason, arg_def.kind ),
175175
} )?;
176176

177177
for rule in &arg_def.validation_rules
@@ -187,6 +187,18 @@ impl< 'a > SemanticAnalyzer< 'a >
187187
bound_args.insert( arg_def.name.clone(), parsed_value );
188188
}
189189
}
190+
else if arg_def.is_default_arg && arg_def.default_value.is_some()
191+
{
192+
// If it's a default argument and a default value is provided, use it.
193+
let default_value_str = arg_def.default_value.as_ref().unwrap();
194+
eprintln!( "Using default value for argument '{}': '{}' as {:?}", arg_def.name, default_value_str, arg_def.kind );
195+
let parsed_value = types::parse_value( default_value_str, &arg_def.kind )
196+
.map_err( |e| ErrorData {
197+
code : "INVALID_DEFAULT_VALUE_TYPE".to_string(),
198+
message : format!( "Invalid default value for argument '{}': {}. Expected {:?}.", arg_def.name, e.reason, arg_def.kind ),
199+
} )?;
200+
bound_args.insert( arg_def.name.clone(), parsed_value );
201+
}
190202
else if !arg_def.optional
191203
{
192204
// If no value is found and argument is not optional, it's a missing argument error.

module/move/unilang/task/task_plan.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
### Progress
1919
* **Roadmap Milestone:** M3.1 & M3.2
2020
* **Primary Editable Crate:** `module/move/unilang`
21-
* **Overall Progress:** 2/7 increments complete
21+
* **Overall Progress:** 3/7 increments complete
2222
* **Increment Status:**
2323
* ✅ Increment 1: Remove Legacy Components
2424
* ✅ Increment 2: Refactor Core Data Models
2525
* ✅ Increment 3: Fix `unilang_cli` Compilation Error
26-
* Increment 4: Adapt `SemanticAnalyzer` to New Parser & Data Models
26+
* Increment 4: Adapt `SemanticAnalyzer` to New Parser & Data Models
2727
* ⚫ Increment 5: Refactor `unilang_cli` Binary with Correct Parsing
2828
* ⚫ Increment 6: Migrate Integration Tests Incrementally
2929
* ⚫ Increment 7: Finalization
@@ -221,3 +221,4 @@ This section provides the necessary API information for dependencies, as direct
221221
* [Increment 2] Updated `help.rs` to display new fields from `CommandDefinition`.
222222
* [Increment 3] Added a focused debugging increment to fix the `parse_single_str` compilation error in `unilang_cli.rs`.
223223
* [Increment 3] Fixed `parse_single_str` to `parse_single_instruction` and correctly passed the slice to `SemanticAnalyzer::new` in `unilang_cli.rs`.
224+
* [Increment 4] Adapted `SemanticAnalyzer::bind_arguments` to handle `is_default_arg` and `default_value`.

0 commit comments

Comments
 (0)