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_regex
for converting a parsed pattern to a regexdocs
— Meant to be enabled when building docs
Enums§
- Class
- A character class, matching any character contained in the class.
- Error
- The crate’s main error type.
- Pattern
Object - A single object of a Lua pattern.
- Quantifier
- A quantifier, specifying the amount of times the leading
PatternObject
can occur. - SetPattern
Object - An entry of a set.
- ToRegex
Error to-regex
- The error type for errors that can occur during conversion to regular expressions.
See
try_to_regex
for more information. - Token
- A token as used by the internal lexer. Exposed to the public API for use in
Error
s.
Functions§
- parse
- Parse the given input string as a Lua pattern.
- try_
to_ regex to-regex
- Try to convert a parsed Lua pattern into a regular expression string.
Type Aliases§
- Pattern
- A list of
PatternObject
s, representing an entire Lua pattern. - Result
- The default result type. The error variant is
Error
.