Skip to content

Commit

Permalink
Fix empty lines bug
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Mar 25, 2024
1 parent ef2a63d commit 08ff3c0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/bin/rhai-dbg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ fn print_current_source(

/// Pretty-print error.
fn print_error(input: &str, mut err: EvalAltResult) {
let lines: Vec<_> = input.trim().lines().collect();
// Do not use `line` because it "eats" the last empty line if the script ends with a newline.
let lines: Vec<_> = input.split('\n').collect();
let pos = err.take_position();

let line_no = if lines.len() > 1 {
Expand Down
3 changes: 2 additions & 1 deletion src/bin/rhai-repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const HISTORY_FILE: &str = ".rhai-repl-history";

/// Pretty-print error.
fn print_error(input: &str, mut err: EvalAltResult) {
let lines: Vec<_> = input.lines().collect();
// Do not use `line` because it "eats" the last empty line if the script ends with a newline.
let lines: Vec<_> = input.split('\n').collect();
let pos = err.take_position();

let line_no = if lines.len() > 1 {
Expand Down
3 changes: 2 additions & 1 deletion src/bin/rhai-run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ fn eprint_error(input: &str, mut err: EvalAltResult) {
eprintln!();
}

let lines: Vec<_> = input.lines().collect();
// Do not use `line` because it "eats" the last empty line if the script ends with a newline.
let lines: Vec<_> = input.split('\n').collect();

// Print error
let pos = err.take_position();
Expand Down

0 comments on commit 08ff3c0

Please sign in to comment.