Struct tokay::vm::Context

source ·
pub struct Context<'program, 'reader, 'thread, 'parselet> {
    pub thread: &'thread mut Thread<'program, 'reader>,
    pub parselet: &'parselet Parselet,
    pub reader_start: Offset,
    pub depth: usize,
    pub debug: u8,
    pub stack: Vec<Capture>,
    pub frames: Vec<Frame>,
    pub frame: Frame,
    pub loops: Vec<Loop>,
    pub source_offset: Option<Offset>,
    /* private fields */
}
Expand description

Contexts represent stack frames for parselet calls.

Within the context, most operations regarding capture storing and loading is performed.

Fields§

§thread: &'thread mut Thread<'program, 'reader>§parselet: &'parselet Parselet§reader_start: Offset§depth: usize§debug: u8§stack: Vec<Capture>§frames: Vec<Frame>§frame: Frame§loops: Vec<Loop>§source_offset: Option<Offset>

Implementations§

source§

impl<'program, 'reader, 'thread, 'parselet> Context<'program, 'reader, 'thread, 'parselet>

source

pub fn new( thread: &'thread mut Thread<'program, 'reader>, parselet: &'parselet Parselet, depth: usize, stack: Vec<Capture>, ) -> Self

source

pub fn log(&self, msg: &str)

Print debug output with context depth indention

source

pub fn push(&self, value: RefValue) -> Result<Accept, Reject>

Shortcut for an Ok(Accept::Push) with the given value. To push a value immediatelly, use context.thread.stack.push().

source

pub fn pop(&mut self) -> RefValue

Pop value off the stack.

source

pub fn peek(&mut self) -> RefValue

Peek top value of stack.

source

pub fn load(&mut self, index: usize) -> Result<Accept, Reject>

source

pub fn frame0(&self) -> &Frame

Return top-level frame

source

pub fn frame0_mut(&mut self) -> &mut Frame

Return mutable top-level frame

source

pub fn get_capture(&mut self, pos: usize) -> Option<Capture>

Return a capture by index as RefValue.

source

pub fn get_capture_by_name(&mut self, name: &str) -> Option<Capture>

Return a capture by name as RefValue.

source

pub fn set_capture(&mut self, pos: usize, value: RefValue)

Set a capture to a RefValue by index.

source

pub fn set_capture_by_name(&mut self, name: &str, value: RefValue)

Set a capture to a RefValue by name.

source

pub fn collect( &mut self, capture_start: usize, copy: bool, sequence: bool, debug: bool, ) -> Capture

Collect captures from a capture_start and turn them either into a dict or list object capture.

Any items with a severity of at least 1 are being collected, but higher severities always win.

  • Results of a collection (either list or dict) inherit the highest collected severity
  • Token severity:
    • 0: Whitespace
    • 1: Touch
    • 5: Match, character-class, parselet
    • 10: Defined value

This function is internally used for automatic AST construction and value inheriting.

source

pub fn drain(&mut self, n: usize) -> Vec<RefValue>

Drains n items off the stack into a vector of values

source

pub fn run(&mut self, main: bool) -> Result<Accept, Reject>

Run the current context with the associated parselet

Auto Trait Implementations§

§

impl<'program, 'reader, 'thread, 'parselet> Freeze for Context<'program, 'reader, 'thread, 'parselet>

§

impl<'program, 'reader, 'thread, 'parselet> !RefUnwindSafe for Context<'program, 'reader, 'thread, 'parselet>

§

impl<'program, 'reader, 'thread, 'parselet> !Send for Context<'program, 'reader, 'thread, 'parselet>

§

impl<'program, 'reader, 'thread, 'parselet> !Sync for Context<'program, 'reader, 'thread, 'parselet>

§

impl<'program, 'reader, 'thread, 'parselet> Unpin for Context<'program, 'reader, 'thread, 'parselet>

§

impl<'program, 'reader, 'thread, 'parselet> !UnwindSafe for Context<'program, 'reader, 'thread, 'parselet>

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

§

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.