Skip to content

Commit c9f8a44

Browse files
authored
Move the keywords module (#352)
* Move the keywords mod from dialect mod into the root of library Signed-off-by: koushiro <[email protected]> * re-export keywords from dialect for backwards compatiblity Signed-off-by: koushiro <[email protected]>
1 parent 3dd89ac commit c9f8a44

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

src/dialect/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
mod ansi;
1414
mod generic;
1515
mod hive;
16-
pub mod keywords;
1716
mod mssql;
1817
mod mysql;
1918
mod postgresql;
@@ -31,6 +30,7 @@ pub use self::mysql::MySqlDialect;
3130
pub use self::postgresql::PostgreSqlDialect;
3231
pub use self::snowflake::SnowflakeDialect;
3332
pub use self::sqlite::SQLiteDialect;
33+
pub use crate::keywords;
3434

3535
/// `dialect_of!(parser is SQLiteDialect | GenericDialect)` evaluates
3636
/// to `true` iff `parser.dialect` is one of the `Dialect`s specified.

src/dialect/keywords.rs renamed to src/keywords.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
/// This module defines
14-
/// 1) a list of constants for every keyword that
15-
/// can appear in [Word::keyword]:
16-
/// pub const KEYWORD = "KEYWORD"
17-
/// 2) an `ALL_KEYWORDS` array with every keyword in it
18-
/// This is not a list of *reserved* keywords: some of these can be
19-
/// parsed as identifiers if the parser decides so. This means that
20-
/// new keywords can be added here without affecting the parse result.
21-
///
22-
/// As a matter of fact, most of these keywords are not used at all
23-
/// and could be removed.
24-
/// 3) a `RESERVED_FOR_TABLE_ALIAS` array with keywords reserved in a
25-
/// "table alias" context.
13+
//! This module defines
14+
//! 1) a list of constants for every keyword that
15+
//! can appear in [Word::keyword]:
16+
//! pub const KEYWORD = "KEYWORD"
17+
//! 2) an `ALL_KEYWORDS` array with every keyword in it
18+
//! This is not a list of *reserved* keywords: some of these can be
19+
//! parsed as identifiers if the parser decides so. This means that
20+
//! new keywords can be added here without affecting the parse result.
21+
//!
22+
//! As a matter of fact, most of these keywords are not used at all
23+
//! and could be removed.
24+
//! 3) a `RESERVED_FOR_TABLE_ALIAS` array with keywords reserved in a
25+
//! "table alias" context.
26+
2627
#[cfg(feature = "serde")]
2728
use serde::{Deserialize, Serialize};
2829

@@ -59,9 +60,7 @@ macro_rules! define_keywords {
5960
pub const ALL_KEYWORDS: &[&str] = &[
6061
$($ident),*
6162
];
62-
6363
};
64-
6564
}
6665

6766
// The following keywords should be sorted to be able to match using binary search

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern crate alloc;
4242
pub mod ast;
4343
#[macro_use]
4444
pub mod dialect;
45+
pub mod keywords;
4546
pub mod parser;
4647
pub mod tokenizer;
4748

src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use core::fmt;
2525
use log::debug;
2626

2727
use crate::ast::*;
28-
use crate::dialect::keywords::Keyword;
2928
use crate::dialect::*;
29+
use crate::keywords::{self, Keyword};
3030
use crate::tokenizer::*;
3131

3232
#[derive(Debug, Clone, PartialEq)]

src/tokenizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ use core::str::Chars;
3131
#[cfg(feature = "serde")]
3232
use serde::{Deserialize, Serialize};
3333

34-
use crate::dialect::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX};
3534
use crate::dialect::Dialect;
3635
use crate::dialect::SnowflakeDialect;
36+
use crate::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX};
3737

3838
/// SQL Token enumeration
3939
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

tests/sqlparser_common.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use test_utils::{all_dialects, expr_from_projection, join, number, only, table,
2424

2525
use matches::assert_matches;
2626
use sqlparser::ast::*;
27-
use sqlparser::dialect::{keywords::ALL_KEYWORDS, GenericDialect, SQLiteDialect};
27+
use sqlparser::dialect::{GenericDialect, SQLiteDialect};
28+
use sqlparser::keywords::ALL_KEYWORDS;
2829
use sqlparser::parser::{Parser, ParserError};
2930

3031
#[test]

0 commit comments

Comments
 (0)