#![forbid(unsafe_code)]
mod compiler;
mod executor;
mod flags;
mod group_name;
mod opcode;
pub use compiler::{
CompileError, CompileErrorKind, CompileErrorSource, CompiledRegExp, ValidatedProgram,
};
pub use executor::{
ExecError, ProgramError, RegExpMatch, execute, execute_latin1_with_interrupt,
execute_with_interrupt,
};
pub use flags::RegExpFlags;
pub use group_name::GroupName;
pub use opcode::{CharacterRange, Instruction};
pub mod unicode;
pub fn compile(pattern: &[u16], flags: &[u16]) -> Result<CompiledRegExp, CompileError> {
compiler::compile_units(pattern, flags)
}
#[must_use]
pub fn javascript_compile_error_message(error: &CompileError) -> &str {
if error.source() == CompileErrorSource::Flags {
return "invalid regular expression flags";
}
match error.message() {
"unexpected end of pattern" | "unterminated character class" | "trailing backslash" => {
"unexpected end"
}
"unterminated group" => "expecting ')'",
"unexpected closing parenthesis" => "extraneous characters at the end",
"invalid group specifier" => "invalid group",
"regular expression syntax error" => "syntax error",
"invalid quantifier target" => "nothing to repeat",
"invalid control escape"
| "invalid hexadecimal escape"
| "invalid Unicode escape"
| "invalid identity escape" => "invalid escape sequence in regular expression",
message => message,
}
}