Merge pull request #126 from nickolay/pr/renames-comments

Update comments after the renaming done in PR #105
This commit is contained in:
Nickolay Ponomarev 2019-07-01 04:56:18 +03:00 committed by GitHub
commit b6538592da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 26 deletions

View file

@ -20,7 +20,7 @@ let sql = "SELECT a, b, 123, myfunc(b) \
WHERE a > b AND b < 100 \ WHERE a > b AND b < 100 \
ORDER BY a DESC, b"; 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();
@ -30,7 +30,7 @@ println!("AST: {:?}", ast);
This outputs This outputs
```rust ```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 ## Design

View file

@ -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) //! (commonly referred to as Data Definition Language, or DDL)
use super::{DataType, Expr, Ident, ObjectName}; use super::{DataType, Expr, Ident, ObjectName};
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation /// An `ALTER TABLE` (`Statement::AlterTable`) operation
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AlterTableOperation { pub enum AlterTableOperation {
/// `ADD <table_constraint>` /// `ADD <table_constraint>`

View file

@ -57,14 +57,14 @@ pub enum Expr {
/// Identifier e.g. table name or column name /// Identifier e.g. table name or column name
Identifier(Ident), Identifier(Ident),
/// Unqualified wildcard (`*`). SQL allows this in limited contexts, such as: /// 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(*)`, /// - or as part of an aggregate function, e.g. `COUNT(*)`,
/// ///
/// ...but we currently also accept it in contexts where it doesn't make /// ...but we currently also accept it in contexts where it doesn't make
/// sense, such as `* + *` /// sense, such as `* + *`
Wildcard, Wildcard,
/// Qualified wildcard, e.g. `alias.*` or `schema.table.*`. /// 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>), QualifiedWildcard(Vec<Ident>),
/// Multi-part identifier, e.g. `table_alias.column` or `schema.table.col` /// Multi-part identifier, e.g. `table_alias.column` or `schema.table.col`
CompoundIdentifier(Vec<Ident>), CompoundIdentifier(Vec<Ident>),
@ -115,7 +115,7 @@ pub enum Expr {
}, },
/// Nested expression e.g. `(foo > bar)` or `(1)` /// Nested expression e.g. `(foo > bar)` or `(1)`
Nested(Box<Expr>), Nested(Box<Expr>),
/// SQLValue /// A literal value, such as string, number, date or NULL
Value(Value), Value(Value),
/// Scalar function call e.g. `LEFT(foo, 5)` /// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function), Function(Function),
@ -320,12 +320,12 @@ impl FromStr for WindowFrameUnits {
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WindowFrameBound { pub enum WindowFrameBound {
/// "CURRENT ROW" /// `CURRENT ROW`
CurrentRow, CurrentRow,
/// "<N> PRECEDING" or "UNBOUNDED PRECEDING" /// `<N> PRECEDING` or `UNBOUNDED PRECEDING`
Preceding(Option<u64>), Preceding(Option<u64>),
/// "<N> FOLLOWING" or "UNBOUNDED FOLLOWING". This can only appear in /// `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`. This can only appear in
/// SQLWindowFrame::end_bound. /// [WindowFrame::end_bound].
Following(Option<u64>), Following(Option<u64>),
} }
@ -610,7 +610,7 @@ impl ToString for Assignment {
} }
} }
/// SQL function /// A function call
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Function { pub struct Function {
pub name: ObjectName, pub name: ObjectName,

View file

@ -12,7 +12,7 @@
///! This module defines ///! This module defines
/// 1) a list of constants for every keyword that /// 1) a list of constants for every keyword that
/// can appear in SQLWord::keyword: /// can appear in [Word::keyword]:
/// pub const KEYWORD = "KEYWORD" /// pub const KEYWORD = "KEYWORD"
/// 2) an `ALL_KEYWORDS` array with every keyword in it /// 2) an `ALL_KEYWORDS` array with every keyword in it
/// This is not a list of *reserved* keywords: some of these can be /// This is not a list of *reserved* keywords: some of these can be

View file

@ -28,7 +28,7 @@ pub trait Dialect: Debug {
/// implementation, accepting "double quoted" ids is both ANSI-compliant /// implementation, accepting "double quoted" ids is both ANSI-compliant
/// and appropriate for most dialects (with the notable exception of /// and appropriate for most dialects (with the notable exception of
/// MySQL, MS SQL, and sqlite). You can accept one of characters listed /// 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 { fn is_delimited_identifier_start(&self, ch: char) -> bool {
ch == '"' ch == '"'
} }

View file

@ -14,14 +14,14 @@
//! //!
//! Example code: //! Example code:
//! //!
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parsed SQL into an Abstract //! This crate provides an ANSI:SQL 2011 lexer and parser that can parse SQL
//! Syntax Tree (AST). //! into an Abstract Syntax Tree (AST).
//! //!
//! ``` //! ```
//! use sqlparser::dialect::GenericDialect; //! use sqlparser::dialect::GenericDialect;
//! use sqlparser::parser::Parser; //! use sqlparser::parser::Parser;
//! //!
//! let dialect = GenericDialect {}; // or AnsiSqlDialect //! let dialect = GenericDialect {}; // or AnsiDialect
//! //!
//! let sql = "SELECT a, b, 123, myfunc(b) \ //! let sql = "SELECT a, b, 123, myfunc(b) \
//! FROM table_1 \ //! FROM table_1 \

View file

@ -225,7 +225,7 @@ impl Parser {
} }
_ => Ok(Expr::Identifier(w.as_ident())), _ => Ok(Expr::Identifier(w.as_ident())),
}, },
}, // End of Token::SQLWord }, // End of Token::Word
Token::Mult => Ok(Expr::Wildcard), Token::Mult => Ok(Expr::Wildcard),
tok @ Token::Minus | tok @ Token::Plus => { tok @ Token::Minus | tok @ Token::Plus => {
let op = if tok == Token::Plus { let op = if tok == Token::Plus {
@ -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) // | | (3) starts a derived table (subquery)
// | (2) starts a nested join // | (2) starts a nested join
// (1) an additional set of parens around a nested join // (1) an additional set of parens around a nested join
@ -1882,7 +1882,7 @@ impl Parser {
Ok(projections) 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> { pub fn parse_order_by_expr_list(&mut self) -> Result<Vec<OrderByExpr>, ParserError> {
let mut expr_list: Vec<OrderByExpr> = vec![]; let mut expr_list: Vec<OrderByExpr> = vec![];
loop { loop {

View file

@ -77,27 +77,27 @@ impl TestedDialects {
only_statement 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. /// after a serialization round-trip.
pub fn verified_stmt(&self, query: &str) -> Statement { pub fn verified_stmt(&self, query: &str) -> Statement {
self.one_statement_parses_to(query, query) 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. /// after a serialization round-trip.
pub fn verified_query(&self, sql: &str) -> Query { pub fn verified_query(&self, sql: &str) -> Query {
match self.verified_stmt(sql) { match self.verified_stmt(sql) {
Statement::Query(query) => *query, 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. /// after a serialization round-trip.
pub fn verified_only_select(&self, query: &str) -> Select { pub fn verified_only_select(&self, query: &str) -> Select {
match self.verified_query(query).body { match self.verified_query(query).body {
SetExpr::Select(s) => *s, SetExpr::Select(s) => *s,
_ => panic!("Expected SQLSetExpr::Select"), _ => panic!("Expected SetExpr::Select"),
} }
} }