#regex #lua #parser

lua-pattern

Parser for Lua patterns and conversion to regular expressions

3 releases

0.1.2 Jul 6, 2023
0.1.1 May 24, 2023
0.1.0 May 24, 2023

#2566 in Parser implementations

Download history 1/week @ 2024-01-22 4/week @ 2024-02-19 29/week @ 2024-02-26 3/week @ 2024-03-04 9/week @ 2024-03-11 5/week @ 2024-03-25 56/week @ 2024-04-01

71 downloads per month
Used in 2 crates (via syntastica-query-preproce…)

GPL-3.0-only

44KB
896 lines

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.


lib.rs:

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]");

Dependencies

~0.3–0.8MB
~20K SLoC