Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Feb 10, 2024
1 parent fbb2652 commit cf90786
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 60 deletions.
6 changes: 3 additions & 3 deletions src/parser/parse_from_text/find_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ enum FindRangeResult<'a> {
///
/// - `ranges` a refernce to a slice of `RangeInclusive<u32>`
fn find_range_for_char<'a>(code: u32, ranges: &[RangeInclusive<u32>]) -> FindRangeResult<'a> {
let index = HASHTAG_CONTENT_CHAR_RANGES.binary_search_by_key(&code, |range| *range.start());
let index = ranges.binary_search_by_key(&code, |range| *range.start());
match index {
Ok(_) => FindRangeResult::WasOnRangeStart,
Err(index) => match index {
0 => FindRangeResult::Range(&HASHTAG_CONTENT_CHAR_RANGES[0]),
0 => FindRangeResult::Range(&ranges[0]),
// Since `index` can never be 0, `index - 1` will never overflow. Furthermore, the
// maximum value which the binary search function returns is `NUMBER_OF_RANGES`.
// Therefore, `index - 1` will never panic if we index the array with it.
#[allow(clippy::integer_arithmetic, clippy::indexing_slicing)]
index => FindRangeResult::Range(&HASHTAG_CONTENT_CHAR_RANGES[index - 1]),
index => FindRangeResult::Range(&ranges[index - 1]),
},
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/parser/parse_from_text/hashtag_content_char_ranges.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::ops::RangeInclusive;
use crate::parser::parse_from_text::find_range::is_in_one_of_ranges;

const NUMBER_OF_RANGES: usize = 850;

/*
Expand Down Expand Up @@ -873,7 +876,7 @@ pub(crate) fn hashtag_content_char(c: char) -> bool {
} else if matches!(c, '+' | '-' | '_') {
true
} else {
is_in_one_of_ranges(c, &[HASHTAG_CONTENT_CHAR_RANGES])
is_in_one_of_ranges(c, &HASHTAG_CONTENT_CHAR_RANGES[..])
}
}

Expand Down
117 changes: 63 additions & 54 deletions src/parser/parse_from_text/link_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ use nom::{
bytes::{
complete::{tag, take, take_while1, take_while},

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

View workflow job for this annotation

GitHub Actions / clippy

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

warning: unused imports: `peek`, `take_while1`, `take`, `verify` --> src/parser/parse_from_text/link_element.rs:7:25 | 7 | complete::{tag, take, take_while1, take_while}, | ^^^^ ^^^^^^^^^^^ ... 10 | combinator::{peek, recognize, verify}, | ^^^^ ^^^^^^
},
character::{is_digit, is_alphabetic as is_alpha, is_hex_digit, char},
character::{is_alphabetic as is_alpha, char},

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

View workflow job for this annotation

GitHub Actions / Rust doc comments

unresolved import `nom::character::char`

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

View workflow job for this annotation

GitHub Actions / clippy

unresolved import `nom::character::char`

error[E0432]: unresolved import `nom::character::char` --> src/parser/parse_from_text/link_element.rs:9:44 | 9 | character::{is_alphabetic as is_alpha, char}, | ^^^^ no `char` in `character`

Check failure on line 9 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)

unresolved import `nom::character::char`
combinator::{peek, recognize, verify},
sequence::{tuple, preceded},
multi::{many_m_n, count},
AsChar, IResult,

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `AsChar`

warning: unused import: `AsChar` --> src/parser/parse_from_text/link_element.rs:13:5 | 13 | AsChar, IResult, | ^^^^^^
};
use super::base_parsers::*;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `super::base_parsers::*`

warning: unused import: `super::base_parsers::*` --> src/parser/parse_from_text/link_element.rs:15:5 | 15 | use super::base_parsers::*; | ^^^^^^^^^^^^^^^^^^^^^^

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


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

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

// These ranges have been extracted from RFC3987, Page 8.
const ucschar_ranges: [RangeInclusive<u32>, _] = [
const ucschar_ranges: [RangeInclusive<u32>; 17] = [
0xa0..=0xd7ff,
0xF900..=0xFDCF,
0xFDF0..=0xFFEF,
Expand Down Expand Up @@ -74,49 +82,49 @@ fn is_ipv4(c: char) -> bool {
}

fn ipv4(input: &str) -> IResult<&str, &str> {
let (input, possible_ipv4) = tuple(
let (input, ipv4_) = recognize(tuple((
complete::u8,

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

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `complete`

error[E0433]: failed to resolve: use of undeclared crate or module `complete` --> src/parser/parse_from_text/link_element.rs:86:9 | 86 | complete::u8, | ^^^^^^^^ use of undeclared crate or module `complete`

Check failure on line 86 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)

failed to resolve: use of undeclared crate or module `complete`
char('.'),
complete::u8,

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

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `complete`

error[E0433]: failed to resolve: use of undeclared crate or module `complete` --> src/parser/parse_from_text/link_element.rs:88:9 | 88 | complete::u8, | ^^^^^^^^ use of undeclared crate or module `complete`

Check failure on line 88 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)

failed to resolve: use of undeclared crate or module `complete`
char('.'),
complete::u8,

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

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `complete`

error[E0433]: failed to resolve: use of undeclared crate or module `complete` --> src/parser/parse_from_text/link_element.rs:90:9 | 90 | complete::u8, | ^^^^^^^^ use of undeclared crate or module `complete`

Check failure on line 90 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)

failed to resolve: use of undeclared crate or module `complete`
char('.'),
complete::u8

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

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `complete`

error[E0433]: failed to resolve: use of undeclared crate or module `complete` --> src/parser/parse_from_text/link_element.rs:92:9 | 92 | complete::u8 | ^^^^^^^^ use of undeclared crate or module `complete`

Check failure on line 92 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)

failed to resolve: use of undeclared crate or module `complete`
)(input);
// This might be an IPv4
let inner_pair = separated_pair(take_while1(is_digit), char('.'), take_while1(is_digit));
let ((part0, part1), (part2, part3)) = separated_pair(inner_pair, char('.'), inner_pair)(input)?;
part0.parse::<u8>()?;
part1.parse::<u8>()?;
part2.parse::<u8>()?;
part3.parse::<u8>()?;
Ok((input, possible_ipv4))
)))(input)?;
Ok((input, ipv4_))
}

fn is_ireg_name(c: char) -> bool {
is_iunreserved(c) || is_pct_encoded(c) || is_sub_delims(c)

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `is_sub_delims` in this scope

error[E0425]: cannot find function `is_sub_delims` in this scope --> src/parser/parse_from_text/link_element.rs:98:47 | 69 | fn is_sub_delim(c: char) -> bool { | -------------------------------- similarly named function `is_sub_delim` defined here ... 98 | is_iunreserved(c) || is_pct_encoded(c) || is_sub_delims(c) | ^^^^^^^^^^^^^ help: a function with a similar name exists: `is_sub_delim`

Check failure on line 98 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 function `is_sub_delims` in this scope
}

fn h16(input: &str) -> IResult<&str, &str> {
take_while_m_n(1, 4, is_hex_digit)
take_while_m_n(1, 4, is_hex_digit)(input)

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `take_while_m_n` in this scope

error[E0425]: cannot find function `take_while_m_n` in this scope --> src/parser/parse_from_text/link_element.rs:102:5 | 102 | take_while_m_n(1, 4, is_hex_digit)(input) | ^^^^^^^^^^^^^^ | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/bytes/complete.rs:183:1 | 183 | / pub fn take_while<F, Input, Error: ParseError<Input>>( 184 | | cond: F, 185 | | ) -> impl Fn(Input) -> IResult<Input, Input, Error> 186 | | where 187 | | Input: InputTakeAtPosition, 188 | | F: Fn(<Input as InputTakeAtPosition>::Item) -> bool, | |______________________________________________________- similarly named function `take_while` defined here | help: a function with a similar name exists | 102 | take_while(1, 4, is_hex_digit)(input) | ~~~~~~~~~~ help: consider importing one of these items | 1 | use nom::bytes::complete::take_while_m_n; | 1 | use nom::bytes::streaming::take_while_m_n; |

Check failure on line 102 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 function `take_while_m_n` in this scope
}

fn ls32(input: &str) -> IResult<&str, &str> {
alt(tuple(h16, char(':'), h16), ipv4)
alt((tuple((h16, char(':'), h16)), ipv4))(input)

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `alt` in this scope

error[E0425]: cannot find function `alt` in this scope --> src/parser/parse_from_text/link_element.rs:106:5 | 106 | alt((tuple((h16, char(':'), h16)), ipv4))(input) | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::branch::alt; |

Check failure on line 106 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 function `alt` in this scope
}

fn ipv6(input: &str) -> IResult<&str, &str> {
let h16_and_period = tuple(h16, char(':'));
let double_period = tag("::");
tuple(
take_while_m_n(6, 6, h16_and_period),
alt(ls32, double_period),
take_while(5, 5, h16_and_period),
alt(ls32, opt(h16)),
double_period,
take_while(4, 4, h16_and_period),
alt(ls32, opt(tuple(take_while_m_n(0, 1, h16_and_period)
fn h16_and_period(input: &str) -> IResult<&str, &str> {
tuple((h16, char(':')))(input)
}

fn double_period(input: &str) -> IResult<&str, &str> {
tag("::")(input)
}

fn ipv6(input: &str) -> IResult<&str, &str> {
alt((

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `alt` in this scope

error[E0425]: cannot find function `alt` in this scope --> src/parser/parse_from_text/link_element.rs:118:5 | 118 | alt(( | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::branch::alt; |

Check failure on line 118 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 function `alt` in this scope
recognize(tuple((count(h16_and_period, 6), ls32))),
recognize(tuple((double_period, many_m_n(5, 5, h16_and_period), ls32))),
recognize(tuple((opt(h16), double_period, many_m_n(4, 4, h16_and_period), ls32))),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:121:26 | 121 | recognize(tuple((opt(h16), double_period, many_m_n(4, 4, h16_and_period), ls32))), | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
recognize(tuple((opt(tuple((many_m_n(0, 1, h16_and_period), ))), double_period, count(h16_and_period, 3), ls32))),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:122:26 | 122 | recognize(tuple((opt(tuple((many_m_n(0, 1, h16_and_period), ))), double_period, count(h16_and_period, 3), ls32))), | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
recognize(tuple((opt(tuple((many_m_n(0, 2, h16_and_period), h16))), double_period, count(h16_and_period, 2), ls32))),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:123:26 | 123 | recognize(tuple((opt(tuple((many_m_n(0, 2, h16_and_period), h16))), double_period, count(h16_and_period, 2), ls32))), | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
recognize(tuple((opt(tuple((many_m_n(0, 3, h16_and_period), h16))), double_period, count(h16_and_period, 1), ls32))),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:124:26 | 124 | recognize(tuple((opt(tuple((many_m_n(0, 3, h16_and_period), h16))), double_period, count(h16_and_period, 1), ls32))), | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
recognize(tuple((opt(tuple((many_m_n(0, 4, h16_and_period), h16))), double_period, ls32))),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:125:26 | 125 | recognize(tuple((opt(tuple((many_m_n(0, 4, h16_and_period), h16))), double_period, ls32))), | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
recognize(tuple((opt(tuple((many_m_n(0, 5, h16_and_period), h16))), double_period, h16))),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:126:26 | 126 | recognize(tuple((opt(tuple((many_m_n(0, 5, h16_and_period), h16))), double_period, h16))), | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
recognize(tuple((opt(tuple((many_m_n(0, 6, h16_and_period), h16))), double_period)))))(input)

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:127:26 | 127 | recognize(tuple((opt(tuple((many_m_n(0, 6, h16_and_period), h16))), double_period)))))(input) | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
}


Expand All @@ -125,10 +133,9 @@ fn is_ipvfuture_last(c: char) -> bool {
}

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

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `take_while_m_n` in this scope

error[E0425]: cannot find function `take_while_m_n` in this scope --> src/parser/parse_from_text/link_element.rs:136:70 | 136 | tuple((char('v'), take_while_m_n(1, 1, is_hex_digit), char('.'), take_while_m_n(1, 1, is_ipvfuture_last)))(input) | ^^^^^^^^^^^^^^ | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/bytes/complete.rs:183:1 | 183 | / pub fn take_while<F, Input, Error: ParseError<Input>>( 184 | | cond: F, 185 | | ) -> impl Fn(Input) -> IResult<Input, Input, Error> 186 | | where 187 | | Input: InputTakeAtPosition, 188 | | F: Fn(<Input as InputTakeAtPosition>::Item) -> bool, | |______________________________________________________- similarly named function `take_while` defined here | help: a function with a similar name exists | 136 | tuple((char('v'), take_while_m_n(1, 1, is_hex_digit), char('.'), take_while(1, 1, is_ipvfuture_last)))(input) | ~~~~~~~~~~ help: consider importing one of these items | 1 | use nom::bytes::complete::take_while_m_n; | 1 | use nom::bytes::streaming::take_while_m_n; |

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `take_while_m_n` in this scope

error[E0425]: cannot find function `take_while_m_n` in this scope --> src/parser/parse_from_text/link_element.rs:136:23 | 136 | tuple((char('v'), take_while_m_n(1, 1, is_hex_digit), char('.'), take_while_m_n(1, 1, is_ipvfuture_last)))(input) | ^^^^^^^^^^^^^^ | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/bytes/complete.rs:183:1 | 183 | / pub fn take_while<F, Input, Error: ParseError<Input>>( 184 | | cond: F, 185 | | ) -> impl Fn(Input) -> IResult<Input, Input, Error> 186 | | where 187 | | Input: InputTakeAtPosition, 188 | | F: Fn(<Input as InputTakeAtPosition>::Item) -> bool, | |______________________________________________________- similarly named function `take_while` defined here | help: a function with a similar name exists | 136 | tuple((char('v'), take_while(1, 1, is_hex_digit), char('.'), take_while_m_n(1, 1, is_ipvfuture_last)))(input) | ~~~~~~~~~~ help: consider importing one of these items | 1 | use nom::bytes::complete::take_while_m_n; | 1 | use nom::bytes::streaming::take_while_m_n; |
}


fn ip_literal(input: &str) -> IResult<&str, &str> {
delimited(char('['), alt(ipv6, ipvfuture), char(']'))(input)

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `alt` in this scope

error[E0425]: cannot find function `alt` in this scope --> src/parser/parse_from_text/link_element.rs:140:26 | 140 | delimited(char('['), alt(ipv6, ipvfuture), char(']'))(input) | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::branch::alt; |

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `delimited` in this scope

error[E0425]: cannot find function `delimited` in this scope --> src/parser/parse_from_text/link_element.rs:140:5 | 140 | delimited(char('['), alt(ipv6, ipvfuture), char(']'))(input) | ^^^^^^^^^ not found in this scope | help: consider importing this function | 1 | use nom::sequence::delimited; |
}
Expand All @@ -139,41 +146,42 @@ fn ip_literal(input: &str) -> IResult<&str, &str> {
///
/// Parse host. Returns the rest, the host string and a boolean indicating
/// if it is IPvFuture or IPv6.
fn parse_host(input: &str) -> IResult<&str, &str, bool> {
let (input, host) = ip_literal(input)?;
if host.is_some() {
// It got parsed, then it's an IP Literal meaning
// it's either IPv6 or IPvFuture
Ok((input, host.unwrap(), true))
} else {
let (input, host) = alt((ipv4, take_while(is_ireg_name)))(input)?;
Ok((input, host, false))
fn parse_host(input: &str) -> IResult<&str, (&str, bool)> {
match ip_literal(input) {
Ok((input, host)) => {
// It got parsed, then it's an IP Literal meaning
// it's either IPv6 or IPvFuture
Ok((input, (host, true)))
}
Err(..) => {
let (input, host) = alt((ipv4, take_while(is_ireg_name)))(input)?;

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `alt` in this scope

error[E0425]: cannot find function `alt` in this scope --> src/parser/parse_from_text/link_element.rs:157:33 | 157 | let (input, host) = alt((ipv4, take_while(is_ireg_name)))(input)?; | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::branch::alt; |
Ok((input, (host, false)))
}
}
}

fn iauthority(input: &str) -> IResult<&str, &str, &str, &str, bool> {
let (input, userinfo) = opt(take_while(is_userinfo), char('@'))(input);
let (input, host, is_ipvfuture) = parse_host(input);
let (input, port) = preceded(char(':'), take_while(is_digit))(input);
Ok((input, userinfo, host, port, is_ipv6))
fn iauthority(input: &str) -> IResult<&str, (&str, &str, &str, bool)> {
let (input, userinfo) = opt(take_while(is_userinfo), char('@'))(input)?;

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_userinfo` in this scope

error[E0425]: cannot find value `is_userinfo` in this scope --> src/parser/parse_from_text/link_element.rs:164:44 | 164 | let (input, userinfo) = opt(take_while(is_userinfo), char('@'))(input)?; | ^^^^^^^^^^^ not found in this scope

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:164:29 | 164 | let (input, userinfo) = opt(take_while(is_userinfo), char('@'))(input)?; | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
let (input, (host, is_ipv6_or_future)) = parse_host(input)?;
let (input, port) = preceded(char(':'), take_while(is_digit))(input)?;
Ok((input, (userinfo, host, port, is_ipv6_or_future)))
}

fn ihier_part(input: &str) -> IResult<&str, &str, &str, bool> {
let (input, authority) = preceded(tag("//"), iauthority)(input);
let (input, path) = alt(
fn ihier_part(input: &str) -> IResult<&str, (&str, &str, &str, &str, bool)> {
let (input, (userinfo, host, port, is_ipv6_or_future)) = preceded(tag("//"), iauthority)(input)?;
let (input, path) = opt(alt(

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `alt` in this scope

error[E0425]: cannot find function `alt` in this scope --> src/parser/parse_from_text/link_element.rs:172:29 | 172 | let (input, path) = opt(alt( | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::branch::alt; |

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:172:25 | 172 | let (input, path) = opt(alt( | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
take_while(is_ipath_abempty),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_ipath_abempty` in this scope

error[E0425]: cannot find value `is_ipath_abempty` in this scope --> src/parser/parse_from_text/link_element.rs:173:20 | 173 | take_while(is_ipath_abempty), | ^^^^^^^^^^^^^^^^ not found in this scope
char(''), // ipath-empty
take_while(is_ipath_absolute),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_ipath_absolute` in this scope

error[E0425]: cannot find value `is_ipath_absolute` in this scope --> src/parser/parse_from_text/link_element.rs:174:20 | 174 | take_while(is_ipath_absolute), | ^^^^^^^^^^^^^^^^^ not found in this scope
take_while(is_ipath_rootless)

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_ipath_rootless` in this scope

error[E0425]: cannot find value `is_ipath_rootless` in this scope --> src/parser/parse_from_text/link_element.rs:175:20 | 175 | take_while(is_ipath_rootless) | ^^^^^^^^^^^^^^^^^ not found in this scope
)(input);
Ok((input, authority, path, is_ipvfuture))
))(input)?;
Ok((input, (userinfo, host, port, path, is_ipv6_or_future)))
}

fn is_ipchar(c: char) -> bool {
is_iunreserved(c) || is_pct_encoded(c) || is_sub_delims(c) || matches!(c, ':' | '@')

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `is_sub_delims` in this scope

error[E0425]: cannot find function `is_sub_delims` in this scope --> src/parser/parse_from_text/link_element.rs:181:47 | 69 | fn is_sub_delim(c: char) -> bool { | -------------------------------- similarly named function `is_sub_delim` defined here ... 181 | is_iunreserved(c) || is_pct_encoded(c) || is_sub_delims(c) || matches!(c, ':' | '@') | ^^^^^^^^^^^^^ help: a function with a similar name exists: `is_sub_delim`
}

const IPRIVATE_RANGES: [RangeInclusive<u32>; _] = [
const IPRIVATE_RANGES: [RangeInclusive<u32>; 3] = [
0xe000..=0xf8ff,
0xf0000..=0xffffd,
0x100000..=0x10fffd,
Expand Down Expand Up @@ -211,17 +219,18 @@ fn is_alphanum_or_hyphen_minus(char: char) -> bool {
}
}

fn link(input: &str) -> IResult<&str, Element, CustomError<&str>> {
pub fn link(input: &str) -> IResult<&str, Element> {
let (input, scheme) = scheme(input)?;
let (input, (userinfo, hostport, is_ipvfuture), path) = ihier_part(input)?;
let (input, (userinfo, host, port, path, is_ipv6_or_future)) = ihier_part(input)?;
let (input, query) = opt(preceed(char('?'), take_while(is_query)))(input)?;

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_query` in this scope

error[E0425]: cannot find value `is_query` in this scope --> src/parser/parse_from_text/link_element.rs:225:60 | 195 | fn is_iquery(c: char) -> bool { | ----------------------------- similarly named function `is_iquery` defined here ... 225 | let (input, query) = opt(preceed(char('?'), take_while(is_query)))(input)?; | ^^^^^^^^ help: a function with a similar name exists: `is_iquery`

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `preceed` in this scope

error[E0425]: cannot find function `preceed` in this scope --> src/parser/parse_from_text/link_element.rs:225:30 | 225 | let (input, query) = opt(preceed(char('?'), take_while(is_query)))(input)?; | ^^^^^^^ help: a function with a similar name exists: `preceded` | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/sequence/mod.rs:63:1 | 63 | / pub fn preceded<I, O1, O2, E: ParseError<I>, F, G>( 64 | | mut first: F, 65 | | mut second: G, 66 | | ) -> impl FnMut(I) -> IResult<I, O2, E> 67 | | where 68 | | F: Parser<I, O1, E>, 69 | | G: Parser<I, O2, E>, | |______________________- similarly named function `preceded` defined here

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:225:26 | 225 | let (input, query) = opt(preceed(char('?'), take_while(is_query)))(input)?; | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
let (input, fragment) = opt(preceed(char('#'), take_while(is_ifragment)))(input)?;

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `preceed` in this scope

error[E0425]: cannot find function `preceed` in this scope --> src/parser/parse_from_text/link_element.rs:226:33 | 226 | let (input, fragment) = opt(preceed(char('#'), take_while(is_ifragment)))(input)?; | ^^^^^^^ help: a function with a similar name exists: `preceded` | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/sequence/mod.rs:63:1 | 63 | / pub fn preceded<I, O1, O2, E: ParseError<I>, F, G>( 64 | | mut first: F, 65 | | mut second: G, 66 | | ) -> impl FnMut(I) -> IResult<I, O2, E> 67 | | where 68 | | F: Parser<I, O1, E>, 69 | | G: Parser<I, O2, E>, | |______________________- similarly named function `preceded` defined here

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `opt` in this scope

error[E0425]: cannot find function `opt` in this scope --> src/parser/parse_from_text/link_element.rs:226:29 | 226 | let (input, fragment) = opt(preceed(char('#'), take_while(is_ifragment)))(input)?; | ^^^ not found in this scope | help: consider importing this function | 1 | use nom::combinator::opt; |
Element::Link {
let mut s = format!("{scheme}://{userinfo}@{host}:{port}{path}{query}{fragment}");
Ok((input, Element::Link {
destination: LinkDestination {
target: input,
target: &s,
hostname: Some(hostport),

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

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `hostport` in this scope

error[E0425]: cannot find value `hostport` in this scope --> src/parser/parse_from_text/link_element.rs:231:28 | 231 | hostname: Some(hostport), | ^^^^^^^^ not found in this scope
punycode: ,
punycode: None,
scheme: scheme

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

View workflow job for this annotation

GitHub Actions / clippy

redundant field names in struct initialization

warning: redundant field names in struct initialization --> src/parser/parse_from_text/link_element.rs:233:13 | 233 | scheme: scheme | ^^^^^^^^^^^^^^ help: replace it with: `scheme` | = note: `#[warn(clippy::redundant_field_names)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
}
}
}))
}
4 changes: 3 additions & 1 deletion src/parser/parse_from_text/markdown_elements.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::parser::parse_from_text::text_elements::email_address;

use super::text_elements::{link, parse_text_element};
use crate::parser::link_url::LinkDestination;
use super::text_elements::parse_text_element;
use crate::parser::parse_from_text::link_element::link;
use super::Element;
use super::{base_parsers::*, parse_all};
///! nom parsers for markdown elements
Expand Down
2 changes: 2 additions & 0 deletions src/parser/parse_from_text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod desktop_subset;
pub mod hashtag_content_char_ranges;
mod markdown_elements;
mod text_elements;
mod link_element;
mod find_range;

/// parses text elements such as links and email addresses, excluding markdown
pub(crate) fn parse_only_text(input: &str) -> std::vec::Vec<Element> {
Expand Down
4 changes: 3 additions & 1 deletion src/parser/parse_from_text/text_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::parser::link_url::LinkDestination;

Check warning on line 2 in src/parser/parse_from_text/text_elements.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `crate::parser::link_url::LinkDestination`

warning: unused import: `crate::parser::link_url::LinkDestination` --> src/parser/parse_from_text/text_elements.rs:2:5 | 2 | use crate::parser::link_url::LinkDestination; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

use super::base_parsers::*;
use super::link_element::link;
use super::hashtag_content_char_ranges::hashtag_content_char;
use super::Element;
use crate::nom::{Offset, Slice};
Expand Down Expand Up @@ -98,6 +99,7 @@ fn not_link_part_char(c: char) -> bool {
!matches!(c, ':' | '\n' | '\r' | '\t' | ' ')
}

/*
fn link(input: &str) -> IResult<&str, (), CustomError<&str>> {
let (input, _) = take_while1(link_scheme)(input)?;
}
Expand Down Expand Up @@ -229,7 +231,7 @@ pub(crate) fn link(input: &str) -> IResult<&str, Element, CustomError<&str>> {
Err(nom::Err::Error(CustomError::InvalidLink))
}
}

*/
fn is_allowed_bot_cmd_suggestion_char(char: char) -> bool {
match char {
'@' | '\\' | '_' | '/' | '.' | '-' => true,
Expand Down

0 comments on commit cf90786

Please sign in to comment.