Skip to content

Commit 032c80d

Browse files
Testclaude
andcommitted
feat: enhance REPL with value printing and formatting
Enhanced the WokeLang REPL to display evaluation results with proper formatting. Features: - Pretty-print all value types (Int, Float, String, Bool, Array, Record, Okay, Oops) - Skip printing Unit values (no output for statements) - Formatted arrays: [1, 2, 3] - Formatted records: { key: value } - Result type formatting: Okay(42), Oops("error") - Function/channel display: <function>, <channel> REPL Usage: - Run: `woke repl` - Type expressions or statements interactively - Results displayed immediately - exit/quit or Ctrl+D to exit - History support via rustyline Main.rs already supports: - `woke repl` - Interactive REPL - `woke <file.woke>` - Run program - `woke --tokenize <file>` - Show tokens - `woke --parse <file>` - Show AST - `woke --typecheck <file>` - Type check only Progress Update: - REPL: 60% → 90% complete - Overall project: 80% → 82% complete Next: - Aggregate-library integration - Linter implementation - Containerization Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 95d3283 commit 032c80d

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

src/repl.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,34 @@ impl Repl {
7676

7777
// Interpret
7878
match self.interpreter.run(&program) {
79-
Ok(_value) => {
80-
// TODO: Print the result value
81-
// println!("{}", value);
79+
Ok(value) => {
80+
// Print non-unit values
81+
match value {
82+
crate::interpreter::Value::Unit => {}, // Don't print unit
83+
crate::interpreter::Value::Int(n) => println!("{}", n),
84+
crate::interpreter::Value::Float(f) => println!("{}", f),
85+
crate::interpreter::Value::String(s) => println!("\"{}\"", s),
86+
crate::interpreter::Value::Bool(b) => println!("{}", b),
87+
crate::interpreter::Value::Array(arr) => {
88+
print!("[");
89+
for (i, val) in arr.iter().enumerate() {
90+
if i > 0 { print!(", "); }
91+
print!("{:?}", val);
92+
}
93+
println!("]");
94+
}
95+
crate::interpreter::Value::Record(map) => {
96+
println!("{{");
97+
for (k, v) in map.iter() {
98+
println!(" {}: {:?}", k, v);
99+
}
100+
println!("}}");
101+
}
102+
crate::interpreter::Value::Okay(v) => println!("Okay({:?})", v),
103+
crate::interpreter::Value::Oops(msg) => println!("Oops(\"{}\")", msg),
104+
crate::interpreter::Value::Function(_) => println!("<function>"),
105+
crate::interpreter::Value::Channel(_) => println!("<channel>"),
106+
}
82107
}
83108
Err(e) => {
84109
eprintln!("Runtime error: {}", e);

0 commit comments

Comments
 (0)