Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better support for empty patterns #677

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions regex-syntax/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ impl Hir {
info.set_any_anchored_start(false);
info.set_any_anchored_end(false);
info.set_match_empty(true);
info.set_literal(true);
info.set_alternation_literal(true);
info.set_literal(false);
info.set_alternation_literal(false);
Hir { kind: HirKind::Empty, info: info }
}

Expand Down Expand Up @@ -671,8 +671,8 @@ impl Hir {
/// true when this HIR expression is either itself a `Literal` or a
/// concatenation of only `Literal`s.
///
/// For example, `f` and `foo` are literals, but `f+`, `(foo)`, `foo()`
/// are not (even though that contain sub-expressions that are literals).
/// For example, `f` and `foo` are literals, but `f+`, `(foo)`, `foo()`,
/// `` are not (even though that contain sub-expressions that are literals).
pub fn is_literal(&self) -> bool {
self.info.is_literal()
}
Expand All @@ -682,8 +682,8 @@ impl Hir {
/// true when this HIR expression is either itself a `Literal` or a
/// concatenation of only `Literal`s or an alternation of only `Literal`s.
///
/// For example, `f`, `foo`, `a|b|c`, and `foo|bar|baz` are alternaiton
/// literals, but `f+`, `(foo)`, `foo()`
/// For example, `f`, `foo`, `a|b|c`, and `foo|bar|baz` are alternation
/// literals, but `f+`, `(foo)`, `foo()`, ``
/// are not (even though that contain sub-expressions that are literals).
pub fn is_alternation_literal(&self) -> bool {
self.info.is_alternation_literal()
Expand Down
4 changes: 2 additions & 2 deletions regex-syntax/src/hir/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3105,13 +3105,13 @@ mod tests {
#[test]
fn analysis_is_literal() {
// Positive examples.
assert!(t(r"").is_literal());
assert!(t(r"a").is_literal());
assert!(t(r"ab").is_literal());
assert!(t(r"abc").is_literal());
assert!(t(r"(?m)abc").is_literal());

// Negative examples.
assert!(!t(r"").is_literal());
assert!(!t(r"^").is_literal());
assert!(!t(r"a|b").is_literal());
assert!(!t(r"(a)").is_literal());
Expand All @@ -3124,7 +3124,6 @@ mod tests {
#[test]
fn analysis_is_alternation_literal() {
// Positive examples.
assert!(t(r"").is_alternation_literal());
assert!(t(r"a").is_alternation_literal());
assert!(t(r"ab").is_alternation_literal());
assert!(t(r"abc").is_alternation_literal());
Expand All @@ -3135,6 +3134,7 @@ mod tests {
assert!(t(r"foo|bar|baz").is_alternation_literal());

// Negative examples.
assert!(!t(r"").is_alternation_literal());
assert!(!t(r"^").is_alternation_literal());
assert!(!t(r"(a)").is_alternation_literal());
assert!(!t(r"a+").is_alternation_literal());
Expand Down
Loading