Skip to content

Conversation

Alexiscomete
Copy link
Member

No description provided.

@Alexiscomete Alexiscomete requested review from Rignchen and Copilot July 17, 2025 15:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes parsing bugs from the last pull request and refactors core tokenization, AST evaluation, and execution logic. Key changes include:

  • Introducing a CharsIterator to enhance the tokenization process and updating all related tokenize_* functions.
  • Extending the Evaluate and Execute traits across AST nodes, wiring up ExecutionContext for runtime execution and error handling.
  • Adding an integration test harness that loads and runs .skrb scripts from resources/test_programs.

Reviewed Changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/utils.rs Updated clear implementation with ANSI codes and improved comments
src/tokens.rs Replaced raw Chars use with CharsIterator for tokenization
src/parse/nodes/vars.rs Added Evaluate impl for Vd and refactored variable parsing
src/parse/nodes/operations.rs Enhanced Evaluate implementations and expanded GraphDisplay
src/main.rs Refactored main into execute, added colorized output and flags
src/tests/programs/from_files.rs New file-based integration tests for .skrb scripts
resources/test_programs/operations.skrb Added operation tests, but includes a typo in the native call prefix
let mut current_ch = file_ch.next();
// let mut operator2 = false;
let mut file_ch = CharsIterator {
file: &mut file.chars(),
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing &mut file.chars() borrows a temporary iterator and will not compile or behave correctly. Consider changing CharsIterator.file to own the Chars iterator directly (e.g., file: Chars<'a>) and pass file: file.chars().

Copilot uses AI. Check for mistakes.

.evaluate(&mut context)
.expect("Should be evaluated without error.")
.as_int(&context)
.expect("Should be an integi.");
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the error message: "integi" should be "integer."

Suggested change
.expect("Should be an integi.");
.expect("Should be an integer.");

Copilot uses AI. Check for mistakes.

.evaluate(&mut context)
.unwrap()
.as_int(&context)
.expect("Should be an integi.");
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message has a typo: "integi" should be "integer."

Suggested change
.expect("Should be an integi.");
.expect("Should be an integer.");

Copilot uses AI. Check for mistakes.

fn evaluate(&self, operation_context: &mut OperationContext) -> OperationO {
match self {
Self::Vd(vd) => vd.evaluate(operation_context),
_ => todo!(),
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using todo!() for all non-Vd variants will panic at runtime if you parse GlobalVar, PrivateVar, or ConstVar. Implement evaluation for those variants or handle them explicitly.

Suggested change
_ => todo!(),
Self::GlobalVar(global_var) => {
// Implement evaluation logic for GlobalVar or return a meaningful error
global_var.evaluate(operation_context)
}
Self::PrivateVar(private_var) => {
// Implement evaluation logic for PrivateVar or return a meaningful error
private_var.evaluate(operation_context)
}
Self::ConstVar(const_var) => {
// Implement evaluation logic for ConstVar or return a meaningful error
const_var.evaluate(operation_context)
}

Copilot uses AI. Check for mistakes.

ValueBase::Int(value) => *value,
ValueBase::Int(value) => Ok(InternalInt::new_boxed(*value)),
ValueBase::Bool(value) => Ok(InternalIoi::new_boxed(*value)),
_ => todo!(),
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Evaluate implementation for ValueBase does not handle Float and String variants and will panic. Add cases for ValueBase::Float and ValueBase::String.

Suggested change
_ => todo!(),
ValueBase::Float(value) => Ok(InternalInt::new_boxed(*value as i64)), // Assuming conversion to integer for compatibility
ValueBase::String(value) => Ok(InternalIoi::new_boxed(value.clone())), // Assuming InternalIoi supports strings

Copilot uses AI. Check for mistakes.

err.show();
panic!(
"{}",
"--- Your program stopped in a unexpected way ---".red()
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar fix: it should read "in an unexpected way" instead of "in a unexpected way."

Suggested change
"--- Your program stopped in a unexpected way ---".red()
"--- Your program stopped in an unexpected way ---".red()

Copilot uses AI. Check for mistakes.

Comment on lines 14 to 16
skrb assert_eq r a
skrb assert_eq r b
skrb assert_eq r c
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native call prefix should be skr_app (as in other tests), not skrb. Update lines to skr_app assert_eq r a.

Suggested change
skrb assert_eq r a
skrb assert_eq r b
skrb assert_eq r c
skr_app assert_eq r a
skr_app assert_eq r b
skr_app assert_eq r c

Copilot uses AI. Check for mistakes.

Comment on lines +15 to +16
stdout().flush().unwrap();
}
Copy link

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Calling unwrap() on flush() can panic in I/O errors. Consider propagating or handling the error instead of unwrapping.

Suggested change
stdout().flush().unwrap();
}
if let Err(e) = stdout().flush() {
eprintln!("Failed to flush stdout: {}", e);
}

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant