Available on crate feature
grammar_mutator
only.Expand description
Grammar-based mutators and related utilties.
This module provides a grammar-based impl Mutator<AST>
which generates an abstract syntax
tree satisfying a grammar, created through grammar_based_ast_mutator
. The resulting mutator can be
transformed into a Mutator<(AST, String)>
, where the second element of the tuple is the string corresponding
to the abstract syntax tree, by calling .with_string()
.
To specify a grammar, you should use the following functions:
regex
to create a grammar from a regular expression (only supported on crate featureregex_grammar
)literal
for a grammar that matches a single characterliteral_ranges
for a grammar matching a single character within a specified rangesliteral_ranges
for a grammar matching a single character within any of multiple rangesalternation
for a grammar matching any of a list of grammar rulesconcatenation
matching multiple grammar rules one after the otherrepetition
matching a grammar rule multiple timesrecursive
andrecurse
to create recursive grammar rules Examples:
use fuzzcheck::mutators::grammar::{alternation, concatenation, literal, literal_range, recurse, recursive, regex, repetition};
let rule = repetition(
concatenation([
alternation([
regex("hello[0-9]"),
regex("world[0-9]?")
]),
literal(' '),
]),
1..5
);
/* “rule” matches/generates:
hello1
hello2 hello6 world
world8 hello5 world7 world world
...
*/
let rule = recursive(|rule| {
alternation([
concatenation([
regex(r"\(|\["),
recurse(rule),
regex(r"\)|\]"),
]),
literal_range('a' ..= 'z')
])
});
/* rule matches/generates:
(([a)))
(([[d))])
z
...
*/
Structs
A mutator created by grammar_based_ast_mutator