Function safe_regex_compiler::parser::parse
source · pub fn parse(regex: &[u8]) -> Result<FinalNode, String>
Expand description
Parses regex
as a regular expression.
Returns a FinalNode
which is the root of the
abstract syntax tree
(AST) of the expression.
§Errors
On error, returns a string explaining the problem.
§Examples
use safe_regex_compiler::parser::parse;
use safe_regex_compiler::parser::FinalNode;
assert_eq!(
Ok(FinalNode::Byte(b'a')), parse(br"a")
);
assert_eq!(
Ok(FinalNode::Alt(vec![
FinalNode::Byte(b'a'),
FinalNode::Byte(b'b'),
FinalNode::Byte(b'c'),
])),
parse(br"a|b|c"),
);
assert_eq!(
Err("missing closing `)`".to_string()),
parse(br"(a"),
);
See FinalNode
variants for more examples.