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

source

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.

source

pub fn parse(&mut self, pattern: &str) -> Result<Ast, Error>

Parse the regular expression into an abstract syntax tree.

source

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.

source

fn reset(&self)

Reset the internal state of a parser.

This is called at the beginning of every parse. This prevents the parser from running with inconsistent state (say, if a previous invocation returned an error and the parser is reused).

Trait Implementations§

source§

impl Clone for Parser

source§

fn clone(&self) -> Parser

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Parser

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Parser

§

impl !RefUnwindSafe for Parser

§

impl Send for Parser

§

impl !Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.