Skip to content

Move the keywords module #352

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 5 commits into from
Sep 26, 2021
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
2 changes: 1 addition & 1 deletion src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
mod ansi;
mod generic;
mod hive;
pub mod keywords;
mod mssql;
mod mysql;
mod postgresql;
Expand All @@ -31,6 +30,7 @@ pub use self::mysql::MySqlDialect;
pub use self::postgresql::PostgreSqlDialect;
pub use self::snowflake::SnowflakeDialect;
pub use self::sqlite::SQLiteDialect;
pub use crate::keywords;

/// `dialect_of!(parser is SQLiteDialect | GenericDialect)` evaluates
/// to `true` iff `parser.dialect` is one of the `Dialect`s specified.
Expand Down
29 changes: 14 additions & 15 deletions src/dialect/keywords.rs → src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/// This module defines
/// 1) a list of constants for every keyword that
/// 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
/// parsed as identifiers if the parser decides so. This means that
/// new keywords can be added here without affecting the parse result.
///
/// As a matter of fact, most of these keywords are not used at all
/// and could be removed.
/// 3) a `RESERVED_FOR_TABLE_ALIAS` array with keywords reserved in a
/// "table alias" context.
//! This module defines
//! 1) a list of constants for every keyword that
//! 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
//! parsed as identifiers if the parser decides so. This means that
//! new keywords can be added here without affecting the parse result.
//!
//! As a matter of fact, most of these keywords are not used at all
//! and could be removed.
//! 3) a `RESERVED_FOR_TABLE_ALIAS` array with keywords reserved in a
//! "table alias" context.

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -59,9 +60,7 @@ macro_rules! define_keywords {
pub const ALL_KEYWORDS: &[&str] = &[
$($ident),*
];

};

}

// The following keywords should be sorted to be able to match using binary search
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern crate alloc;
pub mod ast;
#[macro_use]
pub mod dialect;
pub mod keywords;
pub mod parser;
pub mod tokenizer;

Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use core::fmt;
use log::debug;

use crate::ast::*;
use crate::dialect::keywords::Keyword;
use crate::dialect::*;
use crate::keywords::{self, Keyword};
use crate::tokenizer::*;

#[derive(Debug, Clone, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use core::str::Chars;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crate::dialect::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX};
use crate::dialect::Dialect;
use crate::dialect::SnowflakeDialect;
use crate::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX};

/// SQL Token enumeration
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
3 changes: 2 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use test_utils::{all_dialects, expr_from_projection, join, number, only, table,

use matches::assert_matches;
use sqlparser::ast::*;
use sqlparser::dialect::{keywords::ALL_KEYWORDS, GenericDialect, SQLiteDialect};
use sqlparser::dialect::{GenericDialect, SQLiteDialect};
use sqlparser::keywords::ALL_KEYWORDS;
use sqlparser::parser::{Parser, ParserError};

#[test]
Expand Down