compile_regex

Macro compile_regex 

Source
compile_regex!() { /* proc-macro */ }
Expand description

Compile a regular expression into Rust code.

Generates a struct implementing RegexMatcher. Instances of this struct can match the regular expression that is specified.

Syntax: $attrs type $type<$alphabet_type> = regex. For example:

use scopegraphs::*;

pub enum Alphabet {
    A,
    B,
    C,
}
use Alphabet::*;

compile_regex!(type Machine<Alphabet> = A* B);
assert!(Machine::new().accepts([A, B]));

§Supported Attributes

  • #[graph="$path"] location to put a graphviz dot file representing the generated finite state machine. (only with the dot feature)

§Query Directly

Instead of using compile_regex, you can also use query_regex, which has a simpler syntax and can immediately be used to match a string. This is useful if you want to use a regular expression only once.

use scopegraphs::query_regex;
assert!(query_regex!(Alphabet: A* B).accepts([A, B]));