Skip to main content

RegExpLiteral

Struct RegExpLiteral 

Source
#[repr(C)]
pub struct RegExpLiteral<'gc> { pub metadata: NodeMetadata<'gc>, pub pattern: Cell<NodeLabel>, pub flags: Cell<NodeLabel>, }
Expand description

The RegExpLiteral AST node.

Fields§

§metadata: NodeMetadata<'gc>

Source range, debug location, paren count, and node id.

§pattern: Cell<NodeLabel>

ESTree pattern property.

§flags: Cell<NodeLabel>

ESTree flags property.

Implementations§

Source§

impl<'gc> RegExpLiteral<'gc>

Source

pub fn new( metadata: NodeMetadata<'gc>, pattern: NodeLabel, flags: NodeLabel, ) -> Self

Build RegExpLiteral from its metadata and ESTree.def fields.

Source

pub fn pattern_str<'a>(&self, gc: &'a GCLock<'_, '_>) -> &'a str

The pattern label as UTF-8 text.

Label fields hold identifier names, operators, keyword-like kinds and raw source spans. An identifier cannot contain an unpaired surrogate — the lexer rejects one with a dedicated diagnostic — and the remaining labels are literal source text, so in practice the bytes are already valid UTF-8 and this borrows them directly, allocating nothing.

A label that is nevertheless unrepresentable, which realistically means a hand-built AST rather than a parsed one, has each unpaired surrogate rendered as a single U+FFFD instead of being reported. Only an unpaired surrogate is affected: a WTF-8 surrogate pair is folded back into the character it encodes, so a "😀" label comes out intact.

Use GCLock::bytes for the exact bytes, or GCLock::try_bytes_str to detect the substitution. The returned &str borrows from gc, not from self.

Source

pub fn flags_str<'a>(&self, gc: &'a GCLock<'_, '_>) -> &'a str

The flags label as UTF-8 text.

Label fields hold identifier names, operators, keyword-like kinds and raw source spans. An identifier cannot contain an unpaired surrogate — the lexer rejects one with a dedicated diagnostic — and the remaining labels are literal source text, so in practice the bytes are already valid UTF-8 and this borrows them directly, allocating nothing.

A label that is nevertheless unrepresentable, which realistically means a hand-built AST rather than a parsed one, has each unpaired surrogate rendered as a single U+FFFD instead of being reported. Only an unpaired surrogate is affected: a WTF-8 surrogate pair is folded back into the character it encodes, so a "😀" label comes out intact.

Use GCLock::bytes for the exact bytes, or GCLock::try_bytes_str to detect the substitution. The returned &str borrows from gc, not from self.

Trait Implementations§

Source§

impl<'gc> Debug for RegExpLiteral<'gc>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'gc> !Freeze for RegExpLiteral<'gc>

§

impl<'gc> !RefUnwindSafe for RegExpLiteral<'gc>

§

impl<'gc> !Send for RegExpLiteral<'gc>

§

impl<'gc> !Sync for RegExpLiteral<'gc>

§

impl<'gc> !UnwindSafe for RegExpLiteral<'gc>

§

impl<'gc> Unpin for RegExpLiteral<'gc>

§

impl<'gc> UnsafeUnpin for RegExpLiteral<'gc>

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