Skip to content

Commit

Permalink
updated err messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mainak55512 committed Oct 12, 2024
1 parent 7b40a51 commit ed14b6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ fn main() {
let cli = Cli::parse();

let content = if let Some(load) = cli.load.as_deref() {
fs::read_to_string(load).expect("Could't read file content")
match fs::read_to_string(load) {
Ok(val) => val,
Err(_e) => {
println!("Couldn't read content from file");
std::process::exit(1);
}
}
} else {
io::stdin()
.lock()
Expand Down
8 changes: 8 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ fn parse_binary_expr(token_array: &mut VecDeque<Token>) -> ASTNode {

pub fn parse_ast(token_array: &mut VecDeque<Token>) -> ASTNode {
let mut left = parse_binary_expr(token_array);
if token_array.len() > 0 && token_array[0].val != "&&" && token_array[0].val != "||" {
println!("Query is invalid");
std::process::exit(1);
}
while token_array.len() > 0 && (token_array[0].val == "&&" || token_array[0].val == "||") {
let operator = token_array.pop_front().expect("Empty operator").val;
if token_array.len() <= 0 {
println!("Query is invalid");
std::process::exit(1);
}
let right = parse_binary_expr(token_array);
left = ASTNode::BinaryExpr(Box::new(BinaryExpr {
kind: LiteralType::LOGICAL_EXPR,
Expand Down

0 comments on commit ed14b6f

Please sign in to comment.