Struct regex_syntax::ast::parse::Parser
source · pub struct Parser {
pos: Cell<Position>,
capture_index: Cell<u32>,
nest_limit: u32,
octal: bool,
initial_ignore_whitespace: bool,
empty_min_range: bool,
ignore_whitespace: Cell<bool>,
comments: RefCell<Vec<Comment>>,
stack_group: RefCell<Vec<GroupState>>,
stack_class: RefCell<Vec<ClassState>>,
capture_names: RefCell<Vec<CaptureName>>,
scratch: RefCell<String>,
}
Expand description
A regular expression parser.
This parses a string representation of a regular expression into an abstract syntax tree. The size of the tree is proportional to the length of the regular expression pattern.
A Parser
can be configured in more detail via a ParserBuilder
.
Fields§
§pos: Cell<Position>
The current position of the parser.
capture_index: Cell<u32>
The current capture index.
nest_limit: u32
The maximum number of open parens/brackets allowed. If the parser exceeds this number, then an error is returned.
octal: bool
Whether to support octal syntax or not. When false
, the parser will
return an error helpfully pointing out that backreferences are not
supported.
initial_ignore_whitespace: bool
The initial setting for ignore_whitespace
as provided by
ParserBuilder
. It is used when resetting the parser’s state.
empty_min_range: bool
Whether the parser supports {,n}
repetitions as an equivalent to
{0,n}.
ignore_whitespace: Cell<bool>
Whether whitespace should be ignored. When enabled, comments are also permitted.
comments: RefCell<Vec<Comment>>
A list of comments, in order of appearance.
stack_group: RefCell<Vec<GroupState>>
A stack of grouped sub-expressions, including alternations.
stack_class: RefCell<Vec<ClassState>>
A stack of nested character classes. This is only non-empty when parsing a class.
capture_names: RefCell<Vec<CaptureName>>
A sorted sequence of capture names. This is used to detect duplicate capture names and report an error if one is detected.
scratch: RefCell<String>
A scratch buffer used in various places. Mostly this is used to accumulate relevant characters from parts of a pattern.
Implementations§
source§impl Parser
impl Parser
sourcepub fn new() -> Parser
pub fn new() -> Parser
Create a new parser with a default configuration.
The parser can be run with either the parse
or parse_with_comments
methods. The parse methods return an abstract syntax tree.
To set configuration options on the parser, use ParserBuilder
.
sourcepub fn parse(&mut self, pattern: &str) -> Result<Ast, Error>
pub fn parse(&mut self, pattern: &str) -> Result<Ast, Error>
Parse the regular expression into an abstract syntax tree.
sourcepub fn parse_with_comments(
&mut self,
pattern: &str,
) -> Result<WithComments, Error>
pub fn parse_with_comments( &mut self, pattern: &str, ) -> Result<WithComments, Error>
Parse the regular expression and return an abstract syntax tree with all of the comments found in the pattern.