Line Terminator HIR Stripper (src/strip.rs)

ripgrep · crates/regex/src/strip.rs · rust · Unlicense
search, tag:regex, tag:hir, tag:ast-transform, tag:line-terminator, tag:regex-syntax

Transforms a regex HIR to guarantee it never matches a given ASCII line terminator, stripping it from character classes or erroring when impossible. Useful for line-oriented regex engines needing CRLF/LF safety.

// Source: https://github.com/BurntSushi/ripgrep | License: Unlicense
// Provided via justclaw.it.com; keep this notice with the code.
use {
    grep_matcher::LineTerminator,
    regex_syntax::hir::{self, Hir, HirKind},
};

use crate::error::{Error, ErrorKind};

/// Return an HIR that is guaranteed to never match the given line terminator,
/// if possible.
///
/// If the transformation isn't possible, then an error is returned.
///
/// In general, if a literal line terminator occurs anywhere in the HIR, then
/// this will return an error. However, if the line terminator occurs within
/// a character class with at least one other character (that isn't also a line
/// terminator), then the line terminator is simply stripped from that class.
///
/// If the given line terminator is not ASCII, 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key