Struct regex_syntax::hir::translate::TranslatorI

source ·
struct TranslatorI<'t, 'p> {
    trans: &'t Translator,
    pattern: &'p str,
}
Expand description

The internal implementation of a translator.

This type is responsible for carrying around the original pattern string, which is not tied to the internal state of a translator.

A TranslatorI exists for the time it takes to translate a single Ast.

Fields§

§trans: &'t Translator§pattern: &'p str

Implementations§

source§

impl<'t, 'p> TranslatorI<'t, 'p>

source

fn new(trans: &'t Translator, pattern: &'p str) -> TranslatorI<'t, 'p>

Build a new internal translator.

source

fn trans(&self) -> &Translator

Return a reference to the underlying translator.

source

fn push(&self, frame: HirFrame)

Push the given frame on to the call stack.

source

fn push_char(&self, ch: char)

Push the given literal char on to the call stack.

If the top-most element of the stack is a literal, then the char is appended to the end of that literal. Otherwise, a new literal containing just the given char is pushed to the top of the stack.

source

fn push_byte(&self, byte: u8)

Push the given literal byte on to the call stack.

If the top-most element of the stack is a literal, then the byte is appended to the end of that literal. Otherwise, a new literal containing just the given byte is pushed to the top of the stack.

source

fn pop(&self) -> Option<HirFrame>

Pop the top of the call stack. If the call stack is empty, return None.

source

fn pop_concat_expr(&self) -> Option<Hir>

Pop an HIR expression from the top of the stack for a concatenation.

This returns None if the stack is empty or when a concat frame is seen. Otherwise, it panics if it could not find an HIR expression.

source

fn pop_alt_expr(&self) -> Option<Hir>

Pop an HIR expression from the top of the stack for an alternation.

This returns None if the stack is empty or when an alternation frame is seen. Otherwise, it panics if it could not find an HIR expression.

source

fn error(&self, span: Span, kind: ErrorKind) -> Error

Create a new error with the given span and error type.

source

fn flags(&self) -> Flags

Return a copy of the active flags.

source

fn set_flags(&self, ast_flags: &Flags) -> Flags

Set the flags of this translator from the flags set in the given AST. Then, return the old flags.

source

fn ast_literal_to_scalar( &self, lit: &Literal, ) -> Result<Either<char, u8>, Error>

Convert an Ast literal to its scalar representation.

When Unicode mode is enabled, then this always succeeds and returns a char (Unicode scalar value).

When Unicode mode is disabled, then a char will still be returned whenever possible. A byte is returned only when invalid UTF-8 is allowed and when the byte is not ASCII. Otherwise, a non-ASCII byte will result in an error when invalid UTF-8 is not allowed.

source

fn case_fold_char(&self, span: Span, c: char) -> Result<Option<Hir>, Error>

source

fn hir_dot(&self, span: Span) -> Result<Hir, Error>

source

fn hir_assertion(&self, asst: &Assertion) -> Result<Hir, Error>

source

fn hir_capture(&self, group: &Group, expr: Hir) -> Hir

source

fn hir_repetition(&self, rep: &Repetition, expr: Hir) -> Hir

source

fn hir_unicode_class( &self, ast_class: &ClassUnicode, ) -> Result<ClassUnicode, Error>

source

fn hir_ascii_unicode_class( &self, ast: &ClassAscii, ) -> Result<ClassUnicode, Error>

source

fn hir_ascii_byte_class(&self, ast: &ClassAscii) -> Result<ClassBytes, Error>

source

fn hir_perl_unicode_class( &self, ast_class: &ClassPerl, ) -> Result<ClassUnicode, Error>

source

fn hir_perl_byte_class( &self, ast_class: &ClassPerl, ) -> Result<ClassBytes, Error>

source

fn convert_unicode_class_error( &self, span: &Span, result: Result<ClassUnicode, Error>, ) -> Result<ClassUnicode, Error>

Converts the given Unicode specific error to an HIR translation error.

The span given should approximate the position at which an error would occur.

source

fn unicode_fold_and_negate( &self, span: &Span, negated: bool, class: &mut ClassUnicode, ) -> Result<(), Error>

source

fn bytes_fold_and_negate( &self, span: &Span, negated: bool, class: &mut ClassBytes, ) -> Result<(), Error>

source

fn class_literal_byte(&self, ast: &Literal) -> Result<u8, Error>

Return a scalar byte value suitable for use as a literal in a byte character class.

Trait Implementations§

source§

impl<'t, 'p> Clone for TranslatorI<'t, 'p>

source§

fn clone(&self) -> TranslatorI<'t, 'p>

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<'t, 'p> Debug for TranslatorI<'t, 'p>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'t, 'p> Visitor for TranslatorI<'t, 'p>

§

type Output = Hir

The result of visiting an AST.
§

type Err = Error

An error that visiting an AST might return.
source§

fn finish(self) -> Result<Hir, Error>

All implementors of Visitor must provide a finish method, which yields the result of visiting the AST or an error.
source§

fn visit_pre(&mut self, ast: &Ast) -> Result<(), Error>

This method is called on an Ast before descending into child Ast nodes.
source§

fn visit_post(&mut self, ast: &Ast) -> Result<(), Error>

This method is called on an Ast after descending all of its child Ast nodes.
source§

fn visit_alternation_in(&mut self) -> Result<(), Error>

This method is called between child nodes of an Alternation.
source§

fn visit_class_set_item_pre(&mut self, ast: &ClassSetItem) -> Result<(), Error>

This method is called on every ClassSetItem before descending into child nodes.
source§

fn visit_class_set_item_post(&mut self, ast: &ClassSetItem) -> Result<(), Error>

This method is called on every ClassSetItem after descending into child nodes.
source§

fn visit_class_set_binary_op_pre( &mut self, _op: &ClassSetBinaryOp, ) -> Result<(), Error>

This method is called on every ClassSetBinaryOp before descending into child nodes.
source§

fn visit_class_set_binary_op_in( &mut self, _op: &ClassSetBinaryOp, ) -> Result<(), Error>

This method is called between the left hand and right hand child nodes of a ClassSetBinaryOp.
source§

fn visit_class_set_binary_op_post( &mut self, op: &ClassSetBinaryOp, ) -> Result<(), Error>

This method is called on every ClassSetBinaryOp after descending into child nodes.
source§

fn start(&mut self)

This method is called before beginning traversal of the AST.
source§

fn visit_concat_in(&mut self) -> Result<(), Self::Err>

This method is called between child nodes of a concatenation.

Auto Trait Implementations§

§

impl<'t, 'p> Freeze for TranslatorI<'t, 'p>

§

impl<'t, 'p> !RefUnwindSafe for TranslatorI<'t, 'p>

§

impl<'t, 'p> !Send for TranslatorI<'t, 'p>

§

impl<'t, 'p> !Sync for TranslatorI<'t, 'p>

§

impl<'t, 'p> Unpin for TranslatorI<'t, 'p>

§

impl<'t, 'p> !UnwindSafe for TranslatorI<'t, 'p>

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> 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,

§

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>,

§

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>,

§

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.