Skip to content

Commit d80a65b

Browse files
committed
Began creation of parser module
1 parent 2df8900 commit d80a65b

File tree

5 files changed

+253
-4
lines changed

5 files changed

+253
-4
lines changed

Cargo.lock

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ categories = [
2828

2929

3030
[dependencies]
31+
sqlparser = "0.59.0"
3132

3233

3334
[lints.rust]
@@ -51,4 +52,4 @@ expect_used = "deny"
5152
pedantic = { level = "deny", priority = -1 }
5253
cargo = { level = "deny", priority = -1 }
5354
nursery = { level = "deny", priority = -1 }
54-
multiple_crate_versions = "allow"
55+
multiple_crate_versions = "allow"

src/files.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ impl SqlFilesList {
3737
/// # Parameters
3838
///
3939
/// - `path`: any type that implements [`AsRef<Path>`].
40-
/// - `deny_list`: optional list of path-like strings representing files to exclude.
40+
/// - `deny_list`: optional list of path-like strings representing files to
41+
/// exclude.
4142
///
4243
/// # Errors
4344
///

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
//! main file. for testing. shouldn't be part of crate
22
use std::{error::Error, path::Path};
33

4-
pub mod files;
4+
use sqlparser::{dialect::GenericDialect, parser::Parser};
55

6+
pub mod files;
7+
pub mod parser;
68
fn main() -> Result<(), Box<dyn Error>> {
79
let path: &Path = Path::new("/home/alex/Projects/sql-docs/sql_files/");
810

911
let sql_file_set = files::SqlFileSet::new(path, None)?;
1012

1113
for sql in sql_file_set.iter() {
12-
println!("{sql:?}");
14+
let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...
15+
16+
let ast = Parser::parse_sql(&dialect, sql.content()).unwrap();
17+
18+
println!("AST: {ast:?}");
1319
}
1420

1521
Ok(())

src/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Module for parsing the SQL and then using the resulting AST to walk back and
2+
//! check for comments
3+
use std::path::PathBuf;
4+
5+
use sqlparser::{ast::Statement, dialect::GenericDialect, parser::Parser};
6+
7+
use crate::files::{SqlFile, SqlFileSet};
8+
9+
/// A single SQL file plus all [`Statement`].
10+
pub struct ParsedSqlFile {
11+
file: SqlFile,
12+
statements: Vec<Statement>,
13+
}

0 commit comments

Comments
 (0)