Crate lua_pattern
source ·Expand description
lua-pattern
Parser for Lua patterns and conversion to regular expressions.
This crate provides a basic parser for Lua patterns, and, with the to-regex
feature enabled, conversion to standard regular expressions as usable by the
regex or
fancy-regex crate.
Usage
- Lua patterns can be parsed to a tree with
parse. - Parsed patterns can be converted to regex strings with
try_to_regex.
For example:
use lua_pattern::{Class, PatternObject};
let tree = lua_pattern::parse("%l").unwrap();
assert_eq!(tree, [PatternObject::Class(Class::Lowercase)]);
#[cfg(feature = "to-regex")]
assert_eq!(lua_pattern::try_to_regex(&tree, false, false).unwrap(), "[a-z]");Features
-
to-regex— Providetry_to_regexfor converting a parsed pattern to a regex -
docs— Meant to be enabled when building docs
Enums
- A character class, matching any character contained in the class.
- The crate’s main error type.
- A single object of a Lua pattern.
- A quantifier, specifying the amount of times the leading
PatternObjectcan occur. - An entry of a set.
- ToRegexError
to-regexThe error type for errors that can occur during conversion to regular expressions. Seetry_to_regexfor more information. - A token as used by the internal lexer. Exposed to the public API for use in
Errors.
Functions
- Parse the given input string as a Lua pattern.
- try_to_regex
to-regexTry to convert a parsed Lua pattern into a regular expression string.
Type Definitions
- A list of
PatternObjects, representing an entire Lua pattern. - The default result type. The error variant is
Error.