mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-23 19:24:19 +01:00
vendor sqlite3-parser (lemon-rs)
This commit is contained in:
42
vendored/sqlite3-parser/examples/sql_cmds.rs
Normal file
42
vendored/sqlite3-parser/examples/sql_cmds.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use fallible_iterator::FallibleIterator;
|
||||
use std::env;
|
||||
use std::fs::read;
|
||||
use std::panic;
|
||||
|
||||
#[cfg(not(feature = "YYNOERRORRECOVERY"))]
|
||||
use sqlite3_parser::lexer::sql::Error;
|
||||
use sqlite3_parser::lexer::sql::Parser;
|
||||
|
||||
/// Parse specified files and print all commands.
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
let args = env::args();
|
||||
for arg in args.skip(1) {
|
||||
println!("{arg}");
|
||||
let result = panic::catch_unwind(|| {
|
||||
let input = read(arg.clone()).unwrap();
|
||||
let mut parser = Parser::new(input.as_ref());
|
||||
loop {
|
||||
match parser.next() {
|
||||
Ok(None) => break,
|
||||
Err(err) => {
|
||||
eprintln!("Err: {err} in {arg}");
|
||||
#[cfg(feature = "YYNOERRORRECOVERY")]
|
||||
break;
|
||||
#[cfg(not(feature = "YYNOERRORRECOVERY"))]
|
||||
if let Error::ParserError(..) = err {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(Some(cmd)) => {
|
||||
println!("{cmd}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if let Err(e) = result {
|
||||
eprintln!("Panic: {e:?} in {arg}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user