Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Feb 17, 2024
1 parent 87993c2 commit b3a0f71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
34 changes: 24 additions & 10 deletions src/parser/parse_from_text/link_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::parser::link_url::LinkDestination;
use nom::{
branch::alt,
bytes::complete::{tag, take, take_while, take_while1, take_while_m_n},

Check warning on line 8 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `peek`, `take`, `verify`

warning: unused imports: `peek`, `take`, `verify` --> src/parser/parse_from_text/link_element.rs:8:28 | 8 | bytes::complete::{tag, take, take_while, take_while1, take_while_m_n}, | ^^^^ 9 | character::complete::{char, u8}, 10 | combinator::{opt, peek, recognize, verify}, | ^^^^ ^^^^^^
character::{
is_alphabetic as is_alpha,
complete::{char, u8}
},
character::complete::{char, u8},
combinator::{opt, peek, recognize, verify},
multi::{count, many0, many_m_n},
sequence::{delimited, preceded, tuple},
Expand All @@ -19,12 +16,16 @@ use std::ops::RangeInclusive;

// Link syntax here is according to RFC 3986 & 3987 --Farooq

fn is_alpha(c: char) -> bool{
c.is_alphabetic()
}

fn is_hex_digit(c: char) -> bool {
c.is_ascii_hexdigit()
}

fn is_digit(c: char) -> bool {
c.is_digit()
c.is_digit(10)
}

// These ranges have been extracted from RFC3987, Page 8.
Expand Down Expand Up @@ -96,11 +97,16 @@ fn h16(input: &str) -> IResult<&str, &str> {
}

fn ls32(input: &str) -> IResult<&str, &str> {
alt((tuple((h16, char(':'), h16)), ipv4))(input)
let result = recognize(tuple((h16, char(':'), h16)))(input);
if result.is_err() {
ipv4(input)
} else {
result
}
}

fn h16_and_period(input: &str) -> IResult<&str, &str> {
tuple((h16, char(':')))(input)
recognize(tuple((h16, char(':'))))(input)
}

fn double_period(input: &str) -> IResult<&str, &str> {
Expand Down Expand Up @@ -157,12 +163,12 @@ fn is_ipvfuture_last(c: char) -> bool {
}

fn ipvfuture(input: &str) -> IResult<&str, &str> {
tuple((
recognize(tuple((
char('v'),
take_while_m_n(1, 1, is_hex_digit),
char('.'),
take_while_m_n(1, 1, is_ipvfuture_last),
))(input)
)))(input)
}

fn ip_literal(input: &str) -> IResult<&str, &str> {
Expand Down Expand Up @@ -213,7 +219,7 @@ fn ihier_part(input: &str) -> IResult<&str, (&str, &str, &str, &str, bool)> {
))),
))), // ipath-absolute
recognize(tuple((
take_while1(is_ipchar),
take_while_ipchar,
many0(tuple((char('/'), take_while(is_ipchar)))),

Check failure on line 223 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

cannot find value `is_ipchar` in this scope

Check failure on line 223 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_ipchar` in this scope

error[E0425]: cannot find value `is_ipchar` in this scope --> src/parser/parse_from_text/link_element.rs:223:48 | 52 | fn is_ucschar(c: char) -> bool { | ------------------------------ similarly named function `is_ucschar` defined here ... 223 | many0(tuple((char('/'), take_while(is_ipchar)))), | ^^^^^^^^^ help: a function with a similar name exists: `is_ucschar`
))), // ipath_rootless
)))(input)?;
Expand All @@ -225,6 +231,14 @@ fn is_ipchar_not_pct_encoded(c: char) -> bool {
is_iunreserved(c) || is_sub_delim(c) || matches!(c, ':' | '@')
}

fn take_while_ipchar(input: &str) -> IResult<&str, &str> {
many0(alt((take_while(is_ipchar_not_pct_encoded), take_while(is_pct_encoded)))(input)

Check failure on line 235 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rust doc comments

mismatched closing delimiter: `}`

Check failure on line 235 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

mismatched closing delimiter: `}`

Check failure on line 235 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

mismatched closing delimiter: `}`

Check failure on line 235 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

mismatched closing delimiter: `}`

Check failure on line 235 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

expected a `std::ops::FnMut<(_,)>` closure, found `std::result::Result<(&str, &str), nom::Err<_>>`

error[E0277]: expected a `std::ops::FnMut<(_,)>` closure, found `std::result::Result<(&str, &str), nom::Err<_>>` --> src/parser/parse_from_text/link_element.rs:235:11 | 235 | many0(alt((take_while(is_ipchar_not_pct_encoded), take_while(is_pct_encoded)))(input) | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnMut<(_,)>` closure, found `std::result::Result<(&str, &str), nom::Err<_>>` | | | required by a bound introduced by this call | = help: the trait `std::ops::FnMut<(_,)>` is not implemented for `std::result::Result<(&str, &str), nom::Err<_>>` = help: the following other types implement trait `nom::Parser<I, O, E>`: <nom::And<F, G> as nom::Parser<I, (O1, O2), E>> <nom::AndThen<F, G, O1> as nom::Parser<I, O2, E>> <nom::FlatMap<F, G, O1> as nom::Parser<I, O2, E>> <nom::Into<F, O1, O2, E1, E2> as nom::Parser<I, O2, E2>> <nom::Map<F, G, O1> as nom::Parser<I, O2, E>> <nom::Or<F, G> as nom::Parser<I, O, E>> <std::boxed::Box<(dyn nom::Parser<I, O, E> + 'a)> as nom::Parser<I, O, E>> = note: required because of the requirements on the impl of `nom::Parser<_, _, _>` for `std::result::Result<(&str, &str), nom::Err<_>>` note: required by a bound in `nom::multi::many0` --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/multi/mod.rs:56:6 | 56 | F: Parser<I, O, E>, | ^^^^^^^^^^^^^^^ required by this bound in `nom::multi::many0`

Check failure on line 235 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

type mismatch resolving `<&str as nom::InputTakeAtPosition>::Item == [char; 3]`

error[E0271]: type mismatch resolving `<&str as nom::InputTakeAtPosition>::Item == [char; 3]` --> src/parser/parse_from_text/link_element.rs:235:55 | 235 | many0(alt((take_while(is_ipchar_not_pct_encoded), take_while(is_pct_encoded)))(input) | ^^^^^^^^^^ expected `char`, found array `[char; 3]`
}

Check failure on line 236 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> src/parser/parse_from_text/link_element.rs:235:5 | 234 | fn take_while_ipchar(input: &str) -> IResult<&str, &str> { | ------------------- expected `std::result::Result<(&str, &str), nom::Err<nom::error::Error<&str>>>` because of return type 235 | / many0(alt((take_while(is_ipchar_not_pct_encoded), take_while(is_pct_encoded)))(input) 236 | | } | |_^ expected enum `std::result::Result`, found opaque type | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/multi/mod.rs:53:39 | 53 | pub fn many0<I, O, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, Vec<O>, E> | -------------------------------------- the found opaque type | = note: expected enum `std::result::Result<(&str, &str), nom::Err<nom::error::Error<&str>>>` found opaque type `impl FnMut(_) -> std::result::Result<(_, std::vec::Vec<_>), nom::Err<_>>`

fn is_pct_encoded(c: [char; 3]) -> bool {
c[0] == '%' && is_hex_digit(c[1]) && is_hex_digit(c[2])
}

const IPRIVATE_RANGES: [RangeInclusive<u32>; 3] =
[0xe000..=0xf8ff, 0xf0000..=0xffffd, 0x100000..=0x10fffd];

Expand Down
4 changes: 2 additions & 2 deletions src/parser/parse_from_text/markdown_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub(crate) fn delimited_link(input: &str) -> IResult<&str, Element, CustomError<
}
let (rest, link) = match link(content) {
Ok((rest, link)) => (rest, link),
Err(nom::Err(err)) => {
return Err(Error(CustomError::Nom(err.input, err.code)));
Err(nom::Err::Error(err)) => {
return Err(nom::Err::Error(CustomError::Nom(err.input, err.code)));
}
}

Check failure on line 106 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

expected `;`, found keyword `if`
if !rest.is_empty() {
Expand Down

0 comments on commit b3a0f71

Please sign in to comment.