From 3f90dafa3c4875cb33f404392552edc2381e6bf7 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 16 Feb 2023 11:21:53 +0100 Subject: [PATCH] Remove now unused the pattern combinator --- Cargo.lock | 3 --- helix-parsec/Cargo.toml | 1 - helix-parsec/src/lib.rs | 28 ---------------------------- 3 files changed, 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index affc6bd9..eec2a976 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1152,9 +1152,6 @@ dependencies = [ [[package]] name = "helix-parsec" version = "0.6.0" -dependencies = [ - "regex", -] [[package]] name = "helix-term" diff --git a/helix-parsec/Cargo.toml b/helix-parsec/Cargo.toml index 562df8dd..505a4247 100644 --- a/helix-parsec/Cargo.toml +++ b/helix-parsec/Cargo.toml @@ -11,4 +11,3 @@ homepage = "https://helix-editor.com" include = ["src/**/*", "README.md"] [dependencies] -regex = "1" diff --git a/helix-parsec/src/lib.rs b/helix-parsec/src/lib.rs index bfa981e5..e09814b8 100644 --- a/helix-parsec/src/lib.rs +++ b/helix-parsec/src/lib.rs @@ -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