-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathparse.rs
More file actions
39 lines (35 loc) · 1.25 KB
/
parse.rs
File metadata and controls
39 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//SPDX-FileCopyrightText: 2024 Ryuichi Ueda ryuichiueda@gmail.com
//SPDX-License-Identifier: BSD-3-Clause
use crate::ShellCore;
use super::input::InputError;
#[derive(Debug, Clone)]
pub enum ParseError {
UnexpectedSymbol(String),
Input(InputError),
WrongAlias(String),
Regex(String),
}
//expected for conditional expression
impl From<&ParseError> for String {
fn from(e: &ParseError) -> String {
match e {
//ParseError::UnexpectedSymbol(s) => format!("Unexpected token: {}", s),
ParseError::UnexpectedSymbol(s) => format!("syntax error near unexpected token: {}", s),
ParseError::Input(e) => From::from(e),
ParseError::WrongAlias(msg) => format!("Something wrong alias: {}", msg),
ParseError::Regex(msg) => format!("regex error: {}", msg),
}
}
}
impl ParseError {
pub fn print(&self, core: &mut ShellCore) {
let name = core.db.get_param("0").unwrap();
let s: String = From::<&ParseError>::from(self);
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);
}
}
}