Skip to content

Commit

Permalink
Make sql_cmd example parse args
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Mar 16, 2024
1 parent a7cd0c1 commit 230dd8b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions examples/sql_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use std::env;

use fallible_iterator::FallibleIterator;
use sqlite3_parser::lexer::sql::Parser;

/// Parse a string.
/// Parse args.
// RUST_LOG=sqlite3Parser=debug
fn main() {
env_logger::init();
let arg = "PRAGMA parser_trace=ON;";
let mut parser = Parser::new(arg.as_bytes());
loop {
match parser.next() {
Ok(None) => break,
Err(err) => {
eprintln!("Err: {err} in {arg}");
break;
}
Ok(Some(cmd)) => {
println!("{cmd}");
let args = env::args();
for arg in args.skip(1) {
let mut parser = Parser::new(arg.as_bytes());
loop {
match parser.next() {
Ok(None) => break,
Err(err) => {
eprintln!("Err: {err} in {arg}");
break;
}
Ok(Some(cmd)) => {
println!("{cmd}");
}
}
}
}
Expand Down

0 comments on commit 230dd8b

Please sign in to comment.