Skip to content

Update comments after the renaming done in PR #105 #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ let sql = "SELECT a, b, 123, myfunc(b) \
WHERE a > b AND b < 100 \
ORDER BY a DESC, b";

let dialect = GenericSqlDialect{}; // or AnsiSqlDialect, or your own dialect ...
let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...

let ast = Parser::parse_sql(&dialect,sql.to_string()).unwrap();
let ast = Parser::parse_sql(&dialect, sql.to_string()).unwrap();

println!("AST: {:?}", ast);
```

This outputs

```rust
AST: [SQLSelect(SQLQuery { ctes: [], body: Select(SQLSelect { distinct: false, projection: [UnnamedExpression(SQLIdentifier("a")), UnnamedExpression(SQLIdentifier("b")), UnnamedExpression(SQLValue(Long(123))), UnnamedExpression(SQLFunction { name: SQLObjectName(["myfunc"]), args: [SQLIdentifier("b")], over: None })], relation: Some(Table { name: SQLObjectName(["table_1"]), alias: None }), joins: [], selection: Some(SQLBinaryExpr { left: SQLBinaryExpr { left: SQLIdentifier("a"), op: Gt, right: SQLIdentifier("b") }, op: And, right: SQLBinaryExpr { left: SQLIdentifier("b"), op: Lt, right: SQLValue(Long(100)) } }), group_by: None, having: None }), order_by: Some([SQLOrderByExpr { expr: SQLIdentifier("a"), asc: Some(false) }, SQLOrderByExpr { expr: SQLIdentifier("b"), asc: None }]), limit: None })]
AST: [Query(Query { ctes: [], body: Select(Select { distinct: false, projection: [UnnamedExpr(Identifier("a")), UnnamedExpr(Identifier("b")), UnnamedExpr(Value(Long(123))), UnnamedExpr(Function(Function { name: ObjectName(["myfunc"]), args: [Identifier("b")], over: None, distinct: false }))], from: [TableWithJoins { relation: Table { name: ObjectName(["table_1"]), alias: None, args: [], with_hints: [] }, joins: [] }], selection: Some(BinaryOp { left: BinaryOp { left: Identifier("a"), op: Gt, right: Identifier("b") }, op: And, right: BinaryOp { left: Identifier("b"), op: Lt, right: Value(Long(100)) } }), group_by: [], having: None }), order_by: [OrderByExpr { expr: Identifier("a"), asc: Some(false) }, OrderByExpr { expr: Identifier("b"), asc: None }], limit: None, offset: None, fetch: None })]
```

## Design
Expand Down
4 changes: 2 additions & 2 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! AST types specific to CREATE/ALTER variants of `SQLStatement`
//! AST types specific to CREATE/ALTER variants of [Statement]
//! (commonly referred to as Data Definition Language, or DDL)
use super::{DataType, Expr, Ident, ObjectName};

/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
/// An `ALTER TABLE` (`Statement::AlterTable`) operation
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AlterTableOperation {
/// `ADD <table_constraint>`
Expand Down
16 changes: 8 additions & 8 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ pub enum Expr {
/// Identifier e.g. table name or column name
Identifier(Ident),
/// Unqualified wildcard (`*`). SQL allows this in limited contexts, such as:
/// - right after `SELECT` (which is represented as a [SQLSelectItem::Wildcard] instead)
/// - right after `SELECT` (which is represented as a [SelectItem::Wildcard] instead)
/// - or as part of an aggregate function, e.g. `COUNT(*)`,
///
/// ...but we currently also accept it in contexts where it doesn't make
/// sense, such as `* + *`
Wildcard,
/// Qualified wildcard, e.g. `alias.*` or `schema.table.*`.
/// (Same caveats apply to SQLQualifiedWildcard as to SQLWildcard.)
/// (Same caveats apply to `QualifiedWildcard` as to `Wildcard`.)
QualifiedWildcard(Vec<Ident>),
/// Multi-part identifier, e.g. `table_alias.column` or `schema.table.col`
CompoundIdentifier(Vec<Ident>),
Expand Down Expand Up @@ -115,7 +115,7 @@ pub enum Expr {
},
/// Nested expression e.g. `(foo > bar)` or `(1)`
Nested(Box<Expr>),
/// SQLValue
/// A literal value, such as string, number, date or NULL
Value(Value),
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
Expand Down Expand Up @@ -320,12 +320,12 @@ impl FromStr for WindowFrameUnits {

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WindowFrameBound {
/// "CURRENT ROW"
/// `CURRENT ROW`
CurrentRow,
/// "<N> PRECEDING" or "UNBOUNDED PRECEDING"
/// `<N> PRECEDING` or `UNBOUNDED PRECEDING`
Preceding(Option<u64>),
/// "<N> FOLLOWING" or "UNBOUNDED FOLLOWING". This can only appear in
/// SQLWindowFrame::end_bound.
/// `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`. This can only appear in
/// [WindowFrame::end_bound].
Following(Option<u64>),
}

Expand Down Expand Up @@ -610,7 +610,7 @@ impl ToString for Assignment {
}
}

/// SQL function
/// A function call
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Function {
pub name: ObjectName,
Expand Down
2 changes: 1 addition & 1 deletion src/dialect/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

///! This module defines
/// 1) a list of constants for every keyword that
/// can appear in SQLWord::keyword:
/// can appear in [Word::keyword]:
/// pub const KEYWORD = "KEYWORD"
/// 2) an `ALL_KEYWORDS` array with every keyword in it
/// This is not a list of *reserved* keywords: some of these can be
Expand Down
2 changes: 1 addition & 1 deletion src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait Dialect: Debug {
/// implementation, accepting "double quoted" ids is both ANSI-compliant
/// and appropriate for most dialects (with the notable exception of
/// MySQL, MS SQL, and sqlite). You can accept one of characters listed
/// in `SQLWord::matching_end_quote()` here
/// in `Word::matching_end_quote` here
fn is_delimited_identifier_start(&self, ch: char) -> bool {
ch == '"'
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
//!
//! Example code:
//!
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parsed SQL into an Abstract
//! Syntax Tree (AST).
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parse SQL
//! into an Abstract Syntax Tree (AST).
//!
//! ```
//! use sqlparser::dialect::GenericDialect;
//! use sqlparser::parser::Parser;
//!
//! let dialect = GenericDialect {}; // or AnsiSqlDialect
//! let dialect = GenericDialect {}; // or AnsiDialect
//!
//! let sql = "SELECT a, b, 123, myfunc(b) \
//! FROM table_1 \
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl Parser {
}
_ => Ok(Expr::Identifier(w.as_ident())),
},
}, // End of Token::SQLWord
}, // End of Token::Word
Token::Mult => Ok(Expr::Wildcard),
tok @ Token::Minus | tok @ Token::Plus => {
let op = if tok == Token::Plus {
Expand Down Expand Up @@ -1697,7 +1697,7 @@ impl Parser {
// ^ ^ ^ ^
// | | | |
// | | | |
// | | | (4) belongs to a SQLSetExpr::Query inside the subquery
// | | | (4) belongs to a SetExpr::Query inside the subquery
// | | (3) starts a derived table (subquery)
// | (2) starts a nested join
// (1) an additional set of parens around a nested join
Expand Down Expand Up @@ -1882,7 +1882,7 @@ impl Parser {
Ok(projections)
}

/// Parse a comma-delimited list of SQL ORDER BY expressions
/// Parse a comma-delimited list of ORDER BY expressions
pub fn parse_order_by_expr_list(&mut self) -> Result<Vec<OrderByExpr>, ParserError> {
let mut expr_list: Vec<OrderByExpr> = vec![];
loop {
Expand Down
10 changes: 5 additions & 5 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ impl TestedDialects {
only_statement
}

/// Ensures that `sql` parses as a single SQLStatement, and is not modified
/// Ensures that `sql` parses as a single [Statement], and is not modified
/// after a serialization round-trip.
pub fn verified_stmt(&self, query: &str) -> Statement {
self.one_statement_parses_to(query, query)
}

/// Ensures that `sql` parses as a single SQLQuery, and is not modified
/// Ensures that `sql` parses as a single [Query], and is not modified
/// after a serialization round-trip.
pub fn verified_query(&self, sql: &str) -> Query {
match self.verified_stmt(sql) {
Statement::Query(query) => *query,
_ => panic!("Expected SQLQuery"),
_ => panic!("Expected Query"),
}
}

/// Ensures that `sql` parses as a single SQLSelect, and is not modified
/// Ensures that `sql` parses as a single [Select], and is not modified
/// after a serialization round-trip.
pub fn verified_only_select(&self, query: &str) -> Select {
match self.verified_query(query).body {
SetExpr::Select(s) => *s,
_ => panic!("Expected SQLSetExpr::Select"),
_ => panic!("Expected SetExpr::Select"),
}
}

Expand Down