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 — Provide try_to_regex for converting a parsed pattern to a regex
  • docs — 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.
PatternObject
A single object of a Lua pattern.
Quantifier
A quantifier, specifying the amount of times the leading PatternObject can occur.
SetPatternObject
An entry of a set.
ToRegexErrorto-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 Errors.

Functions§

parse
Parse the given input string as a Lua pattern.
try_to_regexto-regex
Try to convert a parsed Lua pattern into a regular expression string.

Type Aliases§

Pattern
A list of PatternObjects, representing an entire Lua pattern.
Result
The default result type. The error variant is Error.