Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
ryuichiueda committed Jan 16, 2025
1 parent f210f7c commit 8f077e0
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/elements/script.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,9 @@
//SPDX-License-Identifier: BSD-3-Clause

use super::job::Job;
use crate::error::parse;
use crate::error::parse::ParseError;
use crate::{Feeder, ShellCore};
use crate::error;

enum Status{
UnexpectedSymbol(String),
@@ -105,8 +106,8 @@ impl Script {
},
Status::UnexpectedSymbol(s) => {
let _ = core.db.set_param("LINENO", &feeder.lineno.to_string(), None);
let s = format!("Unexpected token: {}", s);
error::print(&s, core);
let e = ParseError::UnexpectedSymbol(s.clone());
parse::print_error(e, core);
core.db.exit_status = 2;
break;
},
13 changes: 13 additions & 0 deletions src/error/parse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//SPDX-FileCopyrightText: 2024 Ryuichi Ueda [email protected]
//SPDX-License-Identifier: BSD-3-Clause

use crate::ShellCore;

#[derive(Debug)]
pub enum ParseError {
UnexpectedSymbol(String),
@@ -17,3 +19,14 @@ impl From<ParseError> for String {
}
}
}

pub fn print_error(e: ParseError, core: &mut ShellCore) {
let name = core.db.get_param("0").unwrap();
let s: String = From::<ParseError>::from(e);
if core.db.flags.contains('i') {
eprintln!("{}: {}", &name, &s);
}else{
let lineno = core.db.get_param("LINENO").unwrap_or("".to_string());
eprintln!("{}: line {}: {}", &name, &lineno, s);
}
}

0 comments on commit 8f077e0

Please sign in to comment.