From 5b88e9746f2021d868005f2c6b51f71cf97adf11 Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Fri, 20 Sep 2024 20:36:17 +0800 Subject: [PATCH] chore: update nom-rule (#16483) * update nom-rule * fix * fix * fix --- Cargo.lock | 16 +++++----------- src/query/ast/Cargo.toml | 2 +- src/query/ast/src/parser/common.rs | 11 +---------- src/query/ast/src/parser/copy.rs | 3 ++- src/query/ast/src/parser/data_mask.rs | 2 +- src/query/ast/src/parser/dynamic_table.rs | 3 ++- src/query/ast/src/parser/expr.rs | 2 +- src/query/ast/src/parser/query.rs | 2 +- src/query/ast/src/parser/script.rs | 2 +- src/query/ast/src/parser/sequence.rs | 4 +++- src/query/ast/src/parser/stage.rs | 2 +- src/query/ast/src/parser/statement.rs | 2 +- src/query/ast/src/parser/stream.rs | 3 ++- src/query/ast/tests/it/parser.rs | 11 ++--------- 14 files changed, 24 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2388d322e6ba..9ce24f40e271 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3225,7 +3225,7 @@ dependencies = [ "nom", "nom-rule", "ordered-float 4.2.2", - "pratt 0.4.0", + "pratt", "pretty", "pretty_assertions", "recursive", @@ -10766,16 +10766,16 @@ dependencies = [ [[package]] name = "nom-rule" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0f33cd048b8e0f5cd2fc6fd26f4feda8e33b4781673e59fe1406b137600e9d" +checksum = "c72951bd83c76b88d820f03b38b124f981dc2520070d62170da7012d1ce964ab" dependencies = [ "nom", - "pratt 0.3.0", + "pratt", "proc-macro-error 1.0.4", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.58", ] [[package]] @@ -12032,12 +12032,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "pratt" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e31bbc12f7936a7b195790dd6d9b982b66c54f45ff6766decf25c44cac302dce" - [[package]] name = "pratt" version = "0.4.0" diff --git a/src/query/ast/Cargo.toml b/src/query/ast/Cargo.toml index 1f65590fb7c4..3167d7b1e014 100644 --- a/src/query/ast/Cargo.toml +++ b/src/query/ast/Cargo.toml @@ -21,7 +21,7 @@ indent = "0.1.1" itertools = { workspace = true } logos = "0.12.1" nom = "7.1.1" -nom-rule = "0.3.1" +nom-rule = "0.4" ordered-float = { workspace = true } pratt = "0.4.0" pretty = "0.11.3" diff --git a/src/query/ast/src/parser/common.rs b/src/query/ast/src/parser/common.rs index ced6d66f0c2d..7b4abc56b484 100644 --- a/src/query/ast/src/parser/common.rs +++ b/src/query/ast/src/parser/common.rs @@ -19,6 +19,7 @@ use nom::multi::many1; use nom::sequence::terminated; use nom::Offset; use nom::Slice; +use nom_rule::rule; use pratt::PrattError; use pratt::PrattParser; use pratt::Precedence; @@ -36,21 +37,11 @@ use crate::parser::query::with_options; use crate::parser::token::*; use crate::parser::Error; use crate::parser::ErrorKind; -use crate::rule; use crate::Range; use crate::Span; pub type IResult<'a, Output> = nom::IResult, Output, Error<'a>>; -#[macro_export] -macro_rules! rule { - ($($tt:tt)*) => { nom_rule::rule!( - $crate::parser::match_text, - $crate::parser::match_token, - $($tt)*) - } -} - pub fn match_text(text: &'static str) -> impl FnMut(Input) -> IResult<&Token> { move |i| match i.tokens.first().filter(|token| token.text() == text) { Some(token) => Ok((i.slice(1..), token)), diff --git a/src/query/ast/src/parser/copy.rs b/src/query/ast/src/parser/copy.rs index bb327f7004cd..0e28b7ca1744 100644 --- a/src/query/ast/src/parser/copy.rs +++ b/src/query/ast/src/parser/copy.rs @@ -14,6 +14,7 @@ use nom::branch::alt; use nom::combinator::map; +use nom_rule::rule; use super::query::with; use crate::ast::CopyIntoLocationOption; @@ -29,6 +30,7 @@ use crate::parser::common::comma_separated_list1; use crate::parser::common::ident; use crate::parser::common::table_ref; use crate::parser::common::IResult; +use crate::parser::common::*; use crate::parser::expr::literal_bool; use crate::parser::expr::literal_string; use crate::parser::expr::literal_u64; @@ -39,7 +41,6 @@ use crate::parser::statement::hint; use crate::parser::token::TokenKind::COPY; use crate::parser::token::TokenKind::*; use crate::parser::Input; -use crate::rule; pub fn copy_into_table(i: Input) -> IResult { let copy_into_table_source = alt(( diff --git a/src/query/ast/src/parser/data_mask.rs b/src/query/ast/src/parser/data_mask.rs index a876654e84bc..486fb6a9ff08 100644 --- a/src/query/ast/src/parser/data_mask.rs +++ b/src/query/ast/src/parser/data_mask.rs @@ -13,6 +13,7 @@ // limitations under the License. use nom::combinator::map; +use nom_rule::rule; use crate::ast::DataMaskArg; use crate::ast::DataMaskPolicy; @@ -22,7 +23,6 @@ use crate::parser::common::*; use crate::parser::expr::*; use crate::parser::input::Input; use crate::parser::token::*; -use crate::rule; fn data_mask_arg(i: Input) -> IResult { map(rule! { #ident ~ #type_name }, |(arg_name, arg_type)| { diff --git a/src/query/ast/src/parser/dynamic_table.rs b/src/query/ast/src/parser/dynamic_table.rs index d09c2311ae0d..b766bdfeec85 100644 --- a/src/query/ast/src/parser/dynamic_table.rs +++ b/src/query/ast/src/parser/dynamic_table.rs @@ -16,6 +16,7 @@ use nom::branch::alt; use nom::branch::permutation; use nom::combinator::map; use nom::combinator::value; +use nom_rule::rule; use crate::ast::ClusterOption; use crate::ast::ClusterType; @@ -29,6 +30,7 @@ use crate::parser::common::comma_separated_list1; use crate::parser::common::dot_separated_idents_1_to_3; use crate::parser::common::map_res; use crate::parser::common::IResult; +use crate::parser::common::*; use crate::parser::expr::expr; use crate::parser::expr::literal_u64; use crate::parser::query::query; @@ -39,7 +41,6 @@ use crate::parser::statement::table_option; use crate::parser::statement::warehouse_option; use crate::parser::token::TokenKind::*; use crate::parser::Input; -use crate::rule; pub fn dynamic_table(i: Input) -> IResult { rule!( diff --git a/src/query/ast/src/parser/expr.rs b/src/query/ast/src/parser/expr.rs index fa6f7db4cce9..805a5c6c7838 100644 --- a/src/query/ast/src/parser/expr.rs +++ b/src/query/ast/src/parser/expr.rs @@ -19,6 +19,7 @@ use nom::combinator::consumed; use nom::combinator::map; use nom::combinator::value; use nom::error::context; +use nom_rule::rule; use pratt::Affix; use pratt::Associativity; use pratt::PrattParser; @@ -33,7 +34,6 @@ use crate::parser::query::*; use crate::parser::token::*; use crate::parser::Error; use crate::parser::ErrorKind; -use crate::rule; pub fn expr(i: Input) -> IResult { context("expression", subexpr(0))(i) diff --git a/src/query/ast/src/parser/query.rs b/src/query/ast/src/parser/query.rs index ce71ce6ca95d..d59bdd2ecd0d 100644 --- a/src/query/ast/src/parser/query.rs +++ b/src/query/ast/src/parser/query.rs @@ -19,6 +19,7 @@ use nom::combinator::consumed; use nom::combinator::map; use nom::combinator::value; use nom::error::context; +use nom_rule::rule; use pratt::Affix; use pratt::Associativity; use pratt::PrattParser; @@ -36,7 +37,6 @@ use crate::parser::statement::set_table_option; use crate::parser::statement::top_n; use crate::parser::token::*; use crate::parser::ErrorKind; -use crate::rule; pub fn query(i: Input) -> IResult { context( diff --git a/src/query/ast/src/parser/script.rs b/src/query/ast/src/parser/script.rs index c360257b4a86..ca77d3e783db 100644 --- a/src/query/ast/src/parser/script.rs +++ b/src/query/ast/src/parser/script.rs @@ -14,6 +14,7 @@ use nom::combinator::consumed; use nom::combinator::map; +use nom_rule::rule; use crate::ast::*; use crate::parser::common::*; @@ -21,7 +22,6 @@ use crate::parser::expr::*; use crate::parser::input::Input; use crate::parser::statement::*; use crate::parser::token::*; -use crate::rule; pub fn script_block(i: Input) -> IResult { map( diff --git a/src/query/ast/src/parser/sequence.rs b/src/query/ast/src/parser/sequence.rs index 67771f8e9e5f..2cdf3a6de460 100644 --- a/src/query/ast/src/parser/sequence.rs +++ b/src/query/ast/src/parser/sequence.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use nom_rule::rule; + use super::common::ident; use super::expr::literal_string; use super::statement::parse_create_option; @@ -20,9 +22,9 @@ use crate::ast::DropSequenceStmt; use crate::ast::Statement; use crate::parser::common::map_res; use crate::parser::common::IResult; +use crate::parser::common::*; use crate::parser::input::Input; use crate::parser::token::*; -use crate::rule; pub fn sequence(i: Input) -> IResult { rule!( diff --git a/src/query/ast/src/parser/stage.rs b/src/query/ast/src/parser/stage.rs index 07a375fde641..9064abced343 100644 --- a/src/query/ast/src/parser/stage.rs +++ b/src/query/ast/src/parser/stage.rs @@ -16,6 +16,7 @@ use std::collections::BTreeMap; use nom::branch::alt; use nom::combinator::map; +use nom_rule::rule; use crate::ast::FileFormatOptions; use crate::ast::FileFormatValue; @@ -27,7 +28,6 @@ use crate::parser::expr::*; use crate::parser::input::Input; use crate::parser::token::*; use crate::parser::ErrorKind; -use crate::rule; pub fn parameter_to_string(i: Input) -> IResult { let ident_to_string = |i| map_res(ident, |ident| Ok(ident.name))(i); diff --git a/src/query/ast/src/parser/statement.rs b/src/query/ast/src/parser/statement.rs index 428ef7ecf766..0877ac754811 100644 --- a/src/query/ast/src/parser/statement.rs +++ b/src/query/ast/src/parser/statement.rs @@ -21,6 +21,7 @@ use nom::combinator::map; use nom::combinator::not; use nom::combinator::value; use nom::Slice; +use nom_rule::rule; use super::sequence::sequence; use crate::ast::*; @@ -38,7 +39,6 @@ use crate::parser::stream::stream_table; use crate::parser::token::*; use crate::parser::Error; use crate::parser::ErrorKind; -use crate::rule; pub enum ShowGrantOption { PrincipalIdentity(PrincipalIdentity), diff --git a/src/query/ast/src/parser/stream.rs b/src/query/ast/src/parser/stream.rs index 992fc567b3c0..93e42c4ae589 100644 --- a/src/query/ast/src/parser/stream.rs +++ b/src/query/ast/src/parser/stream.rs @@ -13,6 +13,7 @@ // limitations under the License. use nom::combinator::map; +use nom_rule::rule; use crate::ast::CreateStreamStmt; use crate::ast::DescribeStreamStmt; @@ -23,6 +24,7 @@ use crate::parser::common::dot_separated_idents_1_to_2; use crate::parser::common::dot_separated_idents_1_to_3; use crate::parser::common::map_res; use crate::parser::common::IResult; +use crate::parser::common::*; use crate::parser::expr::literal_bool; use crate::parser::expr::literal_string; use crate::parser::query::travel_point; @@ -30,7 +32,6 @@ use crate::parser::statement::parse_create_option; use crate::parser::statement::show_limit; use crate::parser::token::TokenKind::*; use crate::parser::Input; -use crate::rule; pub fn stream_table(i: Input) -> IResult { rule!( diff --git a/src/query/ast/tests/it/parser.rs b/src/query/ast/tests/it/parser.rs index 005a68fb413e..c484eff311df 100644 --- a/src/query/ast/tests/it/parser.rs +++ b/src/query/ast/tests/it/parser.rs @@ -18,22 +18,15 @@ use std::io::Write; use databend_common_ast::ast::quote::ident_needs_quote; use databend_common_ast::ast::quote::QuotedIdent; -use databend_common_ast::parser::display_parser_error; use databend_common_ast::parser::expr::*; -use databend_common_ast::parser::parse_sql; use databend_common_ast::parser::query::*; use databend_common_ast::parser::script::script_block; use databend_common_ast::parser::script::script_stmt; use databend_common_ast::parser::statement::insert_stmt; use databend_common_ast::parser::token::*; -use databend_common_ast::parser::tokenize_sql; -use databend_common_ast::parser::Backtrace; -use databend_common_ast::parser::Dialect; -use databend_common_ast::parser::IResult; -use databend_common_ast::parser::Input; -use databend_common_ast::parser::ParseMode; -use databend_common_ast::rule; +use databend_common_ast::parser::*; use goldenfile::Mint; +use nom_rule::rule; fn run_parser(file: &mut dyn Write, parser: P, src: &str) where