Skip to content

Commit

Permalink
chore: update nom-rule (#16483)
Browse files Browse the repository at this point in the history
* update nom-rule

* fix

* fix

* fix
  • Loading branch information
andylokandy authored Sep 20, 2024
1 parent dffe40f commit 5b88e97
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 41 deletions.
16 changes: 5 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/query/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 1 addition & 10 deletions src/query/ast/src/parser/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Input<'a>, 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)),
Expand Down
3 changes: 2 additions & 1 deletion src/query/ast/src/parser/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use nom::branch::alt;
use nom::combinator::map;
use nom_rule::rule;

use super::query::with;
use crate::ast::CopyIntoLocationOption;
Expand All @@ -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;
Expand All @@ -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<Statement> {
let copy_into_table_source = alt((
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/data_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use nom::combinator::map;
use nom_rule::rule;

use crate::ast::DataMaskArg;
use crate::ast::DataMaskPolicy;
Expand All @@ -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<DataMaskArg> {
map(rule! { #ident ~ #type_name }, |(arg_name, arg_type)| {
Expand Down
3 changes: 2 additions & 1 deletion src/query/ast/src/parser/dynamic_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<Statement> {
rule!(
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Expr> {
context("expression", subexpr(0))(i)
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Query> {
context(
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

use nom::combinator::consumed;
use nom::combinator::map;
use nom_rule::rule;

use crate::ast::*;
use crate::parser::common::*;
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<ScriptBlock> {
map(
Expand Down
4 changes: 3 additions & 1 deletion src/query/ast/src/parser/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Statement> {
rule!(
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> {
let ident_to_string = |i| map_res(ident, |ident| Ok(ident.name))(i);
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/query/ast/src/parser/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use nom::combinator::map;
use nom_rule::rule;

use crate::ast::CreateStreamStmt;
use crate::ast::DescribeStreamStmt;
Expand All @@ -23,14 +24,14 @@ 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;
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<Statement> {
rule!(
Expand Down
11 changes: 2 additions & 9 deletions src/query/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P, O>(file: &mut dyn Write, parser: P, src: &str)
where
Expand Down

0 comments on commit 5b88e97

Please sign in to comment.