third_party/rust/lalrpop-snap/src/lexer/re/mod.rs
author David Teller <dteller@mozilla.com>
Wed, 04 Apr 2018 14:14:26 +0200
changeset 412088 a97cccaa866a0fbd5721842ad8d8e862cd26ea65
permissions -rw-r--r--
Bug 1437004 - Vendored Rust dependencies;r=froydnj MozReview-Commit-ID: Grf1bKIx2iT

//! A parser and representation of regular expressions.

use regex_syntax::{self, Error, Expr};

#[cfg(test)]
mod test;

pub type Regex = Expr;
pub type RegexError = Error;

/// Convert a string literal into a parsed regular expression.
pub fn parse_literal(s: &str) -> Regex {
    match parse_regex(&regex_syntax::escape(s)) {
        Ok(v) => v,
        Err(_) => panic!("failed to parse literal regular expression"),
    }
}

/// Parse a regular expression like `a+` etc.
pub fn parse_regex(s: &str) -> Result<Regex, RegexError> {
    let expr = try!(Expr::parse(s));
    Ok(expr)
}