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

better support for empty patterns #677

wants to merge 4 commits into from

Commits on May 11, 2020

  1. Configuration menu
    Copy the full SHA
    dc9378b View commit details
    Browse the repository at this point in the history
  2. hir: make is_alternation_literal say false on Empty

    To avoid this assertion in tests when empty alternations are allowed:
    
       internal error: entered unreachable code: expected literal or concat, got Hir { kind: Empty, info: HirInfo { bools: 1795 } }', src/exec.rs:1568:18
    
    The code in exec.rs relies on the documented invariant for is_alternation_literal:
    
            /// ... This is only
            /// true when this HIR expression is either itself a `Literal` or a
            /// concatenation of only `Literal`s or an alternation of only `Literal`s.
    v-gb committed May 11, 2020
    Configuration menu
    Copy the full SHA
    89f4a3a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    bd63e7f View commit details
    Browse the repository at this point in the history
  4. compile: support empty patterns better

    Some were rejected explicitly with this "alternations cannot currently
    contain empty sub-expressions" error. Some were causing alternations
    to be compiled into automaton matching a different regex.
    
    The root of the issue is that the compilation of the Empty pattern
    returns Patch { entry: self.insts.len(), .. }, that is it claims its
    entry point is the next instruction. This only works if the next
    instruction is unconditionally executed, which is not true for
    alternations.
    
    So we return None instead, and let the callers decide how to handle an
    empty regex.
    v-gb committed May 11, 2020
    Configuration menu
    Copy the full SHA
    1c50848 View commit details
    Browse the repository at this point in the history