pub struct Regexp<'ctx> { /* private fields */ }
Expand description
Ast
node representing a regular expression.
use z3::ast;
use z3::{Config, Context, Solver, SatResult};
let cfg = Config::new();
let ctx = &Context::new(&cfg);
let solver = Solver::new(&ctx);
let s = ast::String::new_const(ctx, "s");
// the regexp representing foo[a-c]*
let a = ast::Regexp::concat(ctx, &[
&ast::Regexp::literal(ctx, "foo"),
&ast::Regexp::range(ctx, &'a', &'c').star()
]);
// the regexp representing [a-z]+
let b = ast::Regexp::range(ctx, &'a', &'z').plus();
// intersection of a and b is non-empty
let intersect = ast::Regexp::intersect(ctx, &[&a, &b]);
solver.assert(&s.regex_matches(&intersect));
assert!(solver.check() == SatResult::Sat);
Implementations§
Source§impl<'ctx> Regexp<'ctx>
impl<'ctx> Regexp<'ctx>
Sourcepub fn literal(ctx: &'ctx Context, s: &str) -> Self
pub fn literal(ctx: &'ctx Context, s: &str) -> Self
Creates a regular expression that recognizes the string given as parameter
Sourcepub fn range(ctx: &'ctx Context, lo: &char, hi: &char) -> Self
pub fn range(ctx: &'ctx Context, lo: &char, hi: &char) -> Self
Creates a regular expression that recognizes a character in the specified range (e.g.
[a-z]
)
Sourcepub fn loop(&self, lo: u32, hi: u32) -> Self
pub fn loop(&self, lo: u32, hi: u32) -> Self
Creates a regular expression that recognizes this regular expression lo
to hi
times (e.g. a{2,3}
)
Sourcepub fn power(&self, n: u32) -> Self
pub fn power(&self, n: u32) -> Self
Creates a regular expression that recognizes this regular expression n number of times Requires Z3 4.8.15 or later.
Sourcepub fn full(ctx: &'ctx Context) -> Self
pub fn full(ctx: &'ctx Context) -> Self
Creates a regular expression that recognizes all sequences
Sourcepub fn allchar(ctx: &'ctx Context) -> Self
pub fn allchar(ctx: &'ctx Context) -> Self
Creates a regular expression that accepts all singleton sequences of the characters Requires Z3 4.8.13 or later.
Sourcepub fn empty(ctx: &'ctx Context) -> Self
pub fn empty(ctx: &'ctx Context) -> Self
Creates a regular expression that doesn’t recognize any sequences
Sourcepub fn plus(&self) -> Self
pub fn plus(&self) -> Self
Creates a regular expression that recognizes this regular expression one or more times (e.g. a+
)
Sourcepub fn star(&self) -> Self
pub fn star(&self) -> Self
Creates a regular expression that recognizes this regular expression any number of times
(Kleene star, e.g. a*
)
Sourcepub fn complement(&self) -> Self
pub fn complement(&self) -> Self
Creates a regular expression that recognizes any sequence that this regular expression doesn’t
Sourcepub fn option(&self) -> Self
pub fn option(&self) -> Self
Creates a regular expression that optionally accepts this regular expression (e.g. a?
)
Sourcepub fn diff(&self, other: &Self) -> Self
pub fn diff(&self, other: &Self) -> Self
Creates a difference regular expression Requires Z3 4.8.14 or later.
Sourcepub fn concat(ctx: &'ctx Context, values: &[impl Borrow<Self>]) -> Self
pub fn concat(ctx: &'ctx Context, values: &[impl Borrow<Self>]) -> Self
Concatenates regular expressions
Trait Implementations§
Source§impl<'ctx> Ast<'ctx> for Regexp<'ctx>
impl<'ctx> Ast<'ctx> for Regexp<'ctx>
fn get_ctx(&self) -> &'ctx Context
fn get_z3_ast(&self) -> Z3_ast
Source§fn _safe_eq(&self, other: &Self) -> Result<Bool<'ctx>, SortDiffers<'ctx>>where
Self: Sized,
fn _safe_eq(&self, other: &Self) -> Result<Bool<'ctx>, SortDiffers<'ctx>>where
Self: Sized,
Ast
with another Ast
, and get a Result. Errors if the sort does not
match for the two values.Source§fn distinct(ctx: &'ctx Context, values: &[impl Borrow<Self>]) -> Bool<'ctx>where
Self: Sized,
fn distinct(ctx: &'ctx Context, values: &[impl Borrow<Self>]) -> Bool<'ctx>where
Self: Sized,
Source§fn simplify(&self) -> Selfwhere
Self: Sized,
fn simplify(&self) -> Selfwhere
Self: Sized,
Ast
. Returns a new Ast
which is equivalent,
but simplified using algebraic simplification rules, such as
constant propagation.Source§fn substitute<T: Ast<'ctx>>(&self, substitutions: &[(&T, &T)]) -> Selfwhere
Self: Sized,
fn substitute<T: Ast<'ctx>>(&self, substitutions: &[(&T, &T)]) -> Selfwhere
Self: Sized,
Ast
. The slice substitutions
contains a
list of pairs with a “from” Ast
that will be substituted by a “to” Ast
.Source§fn num_children(&self) -> usize
fn num_children(&self) -> usize
Ast
. Read more