-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
39 lines (32 loc) · 917 Bytes
/
main.rs
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
mod lazy_reader;
mod lexer;
mod parser;
mod query;
mod parts;
use std::fs::File;
use clap::Parser;
use lazy_reader::LazyReader;
use lexer::Lexer;
#[derive(clap::Parser, Debug)]
#[command(author, version, about)]
struct Args {
/// Path to file and its name: ./some/dirs/filename.xml
#[arg(short, long)]
filename: String,
/// Query format: node_name>sub_node>sub_node1
/// | node_name>sub_node>sub_node1:attr[name]
/// | node_name>sub_node>sub_node1:text
#[arg(short, long)]
query: String,
}
fn main() {
let args = Args::parse();
let Ok(file) = File::open(&args.filename) else {
panic!("fail to open the file");
};
let lr = LazyReader::new(Box::new(file), 32);
let Some(mut p) = parser::Parser::new(Lexer::new(lr).parse().as_slice()) else {
panic!("parser init failed")
};
query::Query::from(&args.query).search(&p.parse().nodes, 0);
}