- Notifications
You must be signed in to change notification settings - Fork 5
Fix parsing bugs from last pull request #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix parsing bugs from last pull request #65
Conversation
…g mut to context, separating OpI and OpO
Fix priority for VarDec We will need to add a function to dump newlines
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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 relatedtokenize_*
functions. - Extending the
Evaluate
andExecute
traits across AST nodes, wiring upExecutionContext
for runtime execution and error handling. - Adding an integration test harness that loads and runs
.skrb
scripts fromresources/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(), |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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."); |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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."
.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."); |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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."
.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!(), |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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.
_ => 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!(), |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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
.
_ => 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() |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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."
"--- Your program stopped in a unexpected way ---".red() | |
"--- Your program stopped in an unexpected way ---".red() |
Copilot uses AI. Check for mistakes.
skrb assert_eq r a | ||
skrb assert_eq r b | ||
skrb assert_eq r c |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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
.
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.
stdout().flush().unwrap(); | ||
} |
Copilot AI Jul 17, 2025
There was a problem hiding this comment.
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.
stdout().flush().unwrap(); | |
} | |
if let Err(e) = stdout().flush() { | |
eprintln!("Failed to flush stdout: {}", e); | |
} |
Copilot uses AI. Check for mistakes.
No description provided.