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

  • 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 PatternObject can occur.
  • 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.
  • 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_regexto-regex
    Try to convert a parsed Lua pattern into a regular expression string.

Type Definitions