mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-30 19:09:46 +03:00
Remove now unused the pattern combinator
This commit is contained in:
parent
e973b71c83
commit
3f90dafa3c
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -1152,9 +1152,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "helix-parsec"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "helix-term"
|
||||
|
@ -11,4 +11,3 @@ homepage = "https://helix-editor.com"
|
||||
include = ["src/**/*", "README.md"]
|
||||
|
||||
[dependencies]
|
||||
regex = "1"
|
||||
|
@ -3,8 +3,6 @@
|
||||
//! This module provides parsers and parser combinators which can be used
|
||||
//! together to build parsers by functional composition.
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
// This module implements parser combinators following https://bodil.lol/parser-combinators/.
|
||||
// `sym` (trait implementation for `&'static str`), `map`, `pred` (filter), `one_or_more`,
|
||||
// `zero_or_more`, as well as the `Parser` trait originate mostly from that post.
|
||||
@ -104,32 +102,6 @@ pub fn token<'a>(literal: &'static str) -> impl Parser<'a, Output = &'a str> {
|
||||
literal
|
||||
}
|
||||
|
||||
/// A parser which matches the pattern described by the given regular expression.
|
||||
///
|
||||
/// The pattern must match from the beginning of the input as if the regular expression
|
||||
/// included the `^` anchor. Using a `^` anchor in the regular expression is
|
||||
/// recommended in order to reduce any work done by the regex on non-matching input.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use helix_parsec::{pattern, Parser};
|
||||
/// use regex::Regex;
|
||||
/// let regex = Regex::new(r"Hello, \w+!").unwrap();
|
||||
/// let parser = pattern(®ex);
|
||||
/// assert_eq!(Ok(("", "Hello, world!")), parser.parse("Hello, world!"));
|
||||
/// assert_eq!(Err("Hey, you!"), parser.parse("Hey, you!"));
|
||||
/// assert_eq!(Err("Oh Hello, world!"), parser.parse("Oh Hello, world!"));
|
||||
/// ```
|
||||
pub fn pattern<'a>(regex: &'a Regex) -> impl Parser<'a, Output = &'a str> {
|
||||
move |input: &'a str| match regex.find(input) {
|
||||
Some(match_) if match_.start() == 0 => {
|
||||
Ok((&input[match_.end()..], &input[0..match_.end()]))
|
||||
}
|
||||
_ => Err(input),
|
||||
}
|
||||
}
|
||||
|
||||
/// A parser which matches all values until the specified pattern is found.
|
||||
///
|
||||
/// If the pattern is not found, this parser does not match. The input up to the
|
||||
|
Loading…
Reference in New Issue
Block a user