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>
impl<'t, 'p> TranslatorI<'t, 'p>
sourcefn new(trans: &'t Translator, pattern: &'p str) -> TranslatorI<'t, 'p>
fn new(trans: &'t Translator, pattern: &'p str) -> TranslatorI<'t, 'p>
Build a new internal translator.
sourcefn trans(&self) -> &Translator
fn trans(&self) -> &Translator
Return a reference to the underlying translator.
sourcefn push_char(&self, ch: char)
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.
sourcefn push_byte(&self, byte: u8)
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.
sourcefn pop(&self) -> Option<HirFrame>
fn pop(&self) -> Option<HirFrame>
Pop the top of the call stack. If the call stack is empty, return None.
sourcefn pop_concat_expr(&self) -> Option<Hir>
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.
sourcefn pop_alt_expr(&self) -> Option<Hir>
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.
sourcefn error(&self, span: Span, kind: ErrorKind) -> Error
fn error(&self, span: Span, kind: ErrorKind) -> Error
Create a new error with the given span and error type.
sourcefn set_flags(&self, ast_flags: &Flags) -> Flags
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.
sourcefn ast_literal_to_scalar(
&self,
lit: &Literal,
) -> Result<Either<char, u8>, Error>
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.
fn case_fold_char(&self, span: Span, c: char) -> Result<Option<Hir>, Error>
fn hir_dot(&self, span: Span) -> Result<Hir, Error>
fn hir_assertion(&self, asst: &Assertion) -> Result<Hir, Error>
fn hir_capture(&self, group: &Group, expr: Hir) -> Hir
fn hir_repetition(&self, rep: &Repetition, expr: Hir) -> Hir
fn hir_unicode_class( &self, ast_class: &ClassUnicode, ) -> Result<ClassUnicode, Error>
fn hir_ascii_unicode_class( &self, ast: &ClassAscii, ) -> Result<ClassUnicode, Error>
fn hir_ascii_byte_class(&self, ast: &ClassAscii) -> Result<ClassBytes, Error>
fn hir_perl_unicode_class( &self, ast_class: &ClassPerl, ) -> Result<ClassUnicode, Error>
fn hir_perl_byte_class( &self, ast_class: &ClassPerl, ) -> Result<ClassBytes, Error>
sourcefn convert_unicode_class_error(
&self,
span: &Span,
result: Result<ClassUnicode, Error>,
) -> Result<ClassUnicode, Error>
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.
fn unicode_fold_and_negate( &self, span: &Span, negated: bool, class: &mut ClassUnicode, ) -> Result<(), Error>
fn bytes_fold_and_negate( &self, span: &Span, negated: bool, class: &mut ClassBytes, ) -> Result<(), Error>
Trait Implementations§
source§impl<'t, 'p> Clone for TranslatorI<'t, 'p>
impl<'t, 'p> Clone for TranslatorI<'t, 'p>
source§fn clone(&self) -> TranslatorI<'t, 'p>
fn clone(&self) -> TranslatorI<'t, 'p>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'t, 'p> Debug for TranslatorI<'t, 'p>
impl<'t, 'p> Debug for TranslatorI<'t, 'p>
source§impl<'t, 'p> Visitor for TranslatorI<'t, 'p>
impl<'t, 'p> Visitor for TranslatorI<'t, 'p>
source§fn finish(self) -> Result<Hir, Error>
fn finish(self) -> Result<Hir, Error>
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>
fn visit_pre(&mut self, ast: &Ast) -> Result<(), Error>
Ast
before descending into child Ast
nodes.source§fn visit_post(&mut self, ast: &Ast) -> Result<(), Error>
fn visit_post(&mut self, ast: &Ast) -> Result<(), Error>
Ast
after descending all of its child
Ast
nodes.source§fn visit_alternation_in(&mut self) -> Result<(), Error>
fn visit_alternation_in(&mut self) -> Result<(), Error>
Alternation
.source§fn visit_class_set_item_pre(&mut self, ast: &ClassSetItem) -> Result<(), Error>
fn visit_class_set_item_pre(&mut self, ast: &ClassSetItem) -> Result<(), Error>
ClassSetItem
before descending into child nodes.source§fn visit_class_set_item_post(&mut self, ast: &ClassSetItem) -> Result<(), Error>
fn visit_class_set_item_post(&mut self, ast: &ClassSetItem) -> Result<(), Error>
ClassSetItem
after descending into child nodes.source§fn visit_class_set_binary_op_pre(
&mut self,
_op: &ClassSetBinaryOp,
) -> Result<(), Error>
fn visit_class_set_binary_op_pre( &mut self, _op: &ClassSetBinaryOp, ) -> Result<(), Error>
ClassSetBinaryOp
before descending into
child nodes.source§fn visit_class_set_binary_op_in(
&mut self,
_op: &ClassSetBinaryOp,
) -> Result<(), Error>
fn visit_class_set_binary_op_in( &mut self, _op: &ClassSetBinaryOp, ) -> Result<(), Error>
ClassSetBinaryOp
.source§fn visit_class_set_binary_op_post(
&mut self,
op: &ClassSetBinaryOp,
) -> Result<(), Error>
fn visit_class_set_binary_op_post( &mut self, op: &ClassSetBinaryOp, ) -> Result<(), Error>
ClassSetBinaryOp
after descending into child
nodes.