Skip to content

Commit 23e2b18

Browse files
gzsomborms705
authored andcommitted
Upgrade to nom 6, fix errors
1 parent e99fa43 commit 23e2b18

6 files changed

Lines changed: 35 additions & 35 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ license = "MIT"
1414
[dependencies]
1515
serde = "1.0"
1616
serde_derive = "1.0"
17-
nom = "5.0.1"
17+
nom = "6"
1818

1919
[dev-dependencies]
2020
pretty_assertions = "0.5.1"

src/arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn arithmetic(i: &[u8]) -> IResult<&[u8], Arithmetic> {
185185
match res.1 {
186186
ArithmeticItem::Base(ArithmeticBase::Column(_))
187187
| ArithmeticItem::Base(ArithmeticBase::Scalar(_)) => {
188-
Err(Error((i, nom::error::ErrorKind::Tag)))
188+
Err(Error(nom::error::Error::new(i, nom::error::ErrorKind::Tag)))
189189
} // no operator
190190
ArithmeticItem::Base(ArithmeticBase::Bracketed(expr)) => Ok((res.0, *expr)),
191191
ArithmeticItem::Expr(expr) => Ok((res.0, *expr)),
@@ -463,6 +463,6 @@ mod tests {
463463
let qs = "56";
464464
let res = arithmetic(qs.as_bytes());
465465
assert!(res.is_err());
466-
assert_eq!(nom::Err::Error((qs.as_bytes(), ErrorKind::Tag)), res.err().unwrap());
466+
assert_eq!(nom::Err::Error(nom::error::Error::new(qs.as_bytes(), ErrorKind::Tag)), res.err().unwrap());
467467
}
468468
}

src/common.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use nom::branch::alt;
22
use nom::character::complete::{alphanumeric1, digit1, line_ending, multispace0, multispace1};
33
use nom::character::is_alphanumeric;
44
use nom::combinator::{map, not, peek};
5-
use nom::{IResult, InputLength};
5+
use nom::{IResult, InputLength, Parser};
66
use std::fmt::{self, Display};
77
use std::str;
88
use std::str::FromStr;
@@ -14,7 +14,7 @@ use keywords::{escape_if_keyword, sql_keyword};
1414
use nom::bytes::complete::{is_not, tag, tag_no_case, take, take_until, take_while1};
1515
use nom::combinator::opt;
1616
use nom::error::{ErrorKind, ParseError};
17-
use nom::multi::{fold_many0, many0, many1, separated_list};
17+
use nom::multi::{fold_many0, many0, many1, separated_list0};
1818
use nom::sequence::{delimited, pair, preceded, separated_pair, terminated, tuple};
1919
use table::Table;
2020

@@ -371,24 +371,24 @@ fn len_as_u16(len: &[u8]) -> u16 {
371371
}
372372

373373
pub(crate) fn opt_delimited<I: Clone, O1, O2, O3, E: ParseError<I>, F, G, H>(
374-
first: F,
375-
second: G,
376-
third: H,
377-
) -> impl Fn(I) -> IResult<I, O2, E>
374+
mut first: F,
375+
mut second: G,
376+
mut third: H,
377+
) -> impl FnMut(I) -> IResult<I, O2, E>
378378
where
379-
F: Fn(I) -> IResult<I, O1, E>,
380-
G: Fn(I) -> IResult<I, O2, E>,
381-
H: Fn(I) -> IResult<I, O3, E>,
379+
F: Parser<I, O1, E>,
380+
G: Parser<I, O2, E>,
381+
H: Parser<I, O3, E>,
382382
{
383383
move |input: I| {
384-
let first_ = &first;
385-
let second_ = &second;
386-
let third_ = &third;
387-
388384
let inp = input.clone();
389-
match second(input) {
385+
match second.parse(input) {
390386
Ok((i, o)) => Ok((i, o)),
391-
_ => delimited(first_, second_, third_)(inp),
387+
_ => {
388+
let (inp, _) = first.parse(inp)?;
389+
let (inp, o2) = second.parse(inp)?;
390+
third.parse(inp).map(|(i, _)| (i, o2))
391+
},
392392
}
393393
}
394394
}
@@ -695,7 +695,7 @@ pub fn column_function(i: &[u8]) -> IResult<&[u8], FunctionExpression> {
695695
FunctionExpression::GroupConcat(FunctionArgument::Column(col.clone()), sep)
696696
},
697697
),
698-
map(tuple((sql_identifier, multispace0, tag("("), separated_list(tag(","), delimited(multispace0, function_argument_parser, multispace0)), tag(")"))), |tuple| {
698+
map(tuple((sql_identifier, multispace0, tag("("), separated_list0(tag(","), delimited(multispace0, function_argument_parser, multispace0)), tag(")"))), |tuple| {
699699
let (name, _, _, arguments, _) = tuple;
700700
FunctionExpression::Generic(
701701
str::from_utf8(name).unwrap().to_string(),

src/compound_select.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,17 @@ mod tests {
185185
assert!(&res.is_err());
186186
assert_eq!(
187187
res.unwrap_err(),
188-
nom::Err::Error((");".as_bytes(), nom::error::ErrorKind::Tag))
188+
nom::Err::Error(nom::error::Error::new(");".as_bytes(), nom::error::ErrorKind::Tag))
189189
);
190190
assert!(&res2.is_err());
191191
assert_eq!(
192192
res2.unwrap_err(),
193-
nom::Err::Error((";".as_bytes(), nom::error::ErrorKind::Tag))
193+
nom::Err::Error(nom::error::Error::new(";".as_bytes(), nom::error::ErrorKind::Tag))
194194
);
195195
assert!(&res3.is_err());
196196
assert_eq!(
197197
res3.unwrap_err(),
198-
nom::Err::Error((
198+
nom::Err::Error(nom::error::Error::new(
199199
") UNION (SELECT id, stars from Rating;".as_bytes(),
200200
nom::error::ErrorKind::Tag
201201
))

src/create_table_options.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use common::{integer_literal, sql_identifier, string_literal, ws_sep_comma, ws_s
44
use nom::branch::alt;
55
use nom::bytes::complete::{tag, tag_no_case};
66
use nom::combinator::{map, opt};
7-
use nom::multi::separated_list;
7+
use nom::multi::separated_list0;
88
use nom::sequence::tuple;
99
use nom::IResult;
1010

1111
pub fn table_options(i: &[u8]) -> IResult<&[u8], ()> {
1212
// TODO: make the create options accessible
1313
map(
14-
separated_list(table_options_separator, create_option),
14+
separated_list0(table_options_separator, create_option),
1515
|_| (),
1616
)(i)
1717
}
@@ -39,12 +39,12 @@ fn create_option(i: &[u8]) -> IResult<&[u8], ()> {
3939
/// Helper to parse equals-separated create option pairs.
4040
/// Throws away the create option and value
4141
pub fn create_option_equals_pair<'a, I, O1, O2, F, G>(
42-
first: F,
43-
second: G,
44-
) -> impl Fn(I) -> IResult<I, ()>
42+
mut first: F,
43+
mut second: G,
44+
) -> impl FnMut(I) -> IResult<I, ()>
4545
where
46-
F: Fn(I) -> IResult<I, O1>,
47-
G: Fn(I) -> IResult<I, O2>,
46+
F: FnMut(I) -> IResult<I, O1>,
47+
G: FnMut(I) -> IResult<I, O2>,
4848
I: nom::InputTakeAtPosition + nom::InputTake + nom::Compare<&'a str>,
4949
<I as nom::InputTakeAtPosition>::Item: nom::AsChar + Clone,
5050
{

src/select.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ mod tests {
528528

529529
let res1 = selection(qstring1.as_bytes());
530530
assert_eq!(
531-
res1.clone().unwrap().1,
531+
res1.unwrap().1,
532532
SelectStatement {
533533
tables: vec![Table {
534534
name: String::from("PaperTag"),
@@ -549,7 +549,7 @@ mod tests {
549549

550550
let res1 = selection(qstring1.as_bytes());
551551
assert_eq!(
552-
res1.clone().unwrap().1,
552+
res1.unwrap().1,
553553
SelectStatement {
554554
tables: vec![Table {
555555
name: String::from("PaperTag"),
@@ -571,7 +571,7 @@ mod tests {
571571

572572
let res1 = selection(qstring1.as_bytes());
573573
assert_eq!(
574-
res1.clone().unwrap().1,
574+
res1.unwrap().1,
575575
SelectStatement {
576576
tables: vec![Table::from("PaperTag")],
577577
fields: vec![FieldDefinitionExpression::Col(Column {
@@ -585,7 +585,7 @@ mod tests {
585585
);
586586
let res2 = selection(qstring2.as_bytes());
587587
assert_eq!(
588-
res2.clone().unwrap().1,
588+
res2.unwrap().1,
589589
SelectStatement {
590590
tables: vec![Table::from("PaperTag")],
591591
fields: vec![FieldDefinitionExpression::Col(Column {
@@ -606,7 +606,7 @@ mod tests {
606606

607607
let res1 = selection(qstring1.as_bytes());
608608
assert_eq!(
609-
res1.clone().unwrap().1,
609+
res1.unwrap().1,
610610
SelectStatement {
611611
tables: vec![Table::from("PaperTag")],
612612
fields: vec![FieldDefinitionExpression::Col(Column {
@@ -620,7 +620,7 @@ mod tests {
620620
);
621621
let res2 = selection(qstring2.as_bytes());
622622
assert_eq!(
623-
res2.clone().unwrap().1,
623+
res2.unwrap().1,
624624
SelectStatement {
625625
tables: vec![Table::from("PaperTag")],
626626
fields: vec![FieldDefinitionExpression::Col(Column {

0 commit comments

Comments
 (0)