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>
impl<'program, 'reader, 'thread, 'parselet> Context<'program, 'reader, 'thread, 'parselet>
pub fn new( thread: &'thread mut Thread<'program, 'reader>, parselet: &'parselet Parselet, depth: usize, stack: Vec<Capture>, ) -> Self
sourcepub fn push(&self, value: RefValue) -> Result<Accept, Reject>
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().
pub fn load(&mut self, index: usize) -> Result<Accept, Reject>
sourcepub fn frame0_mut(&mut self) -> &mut Frame
pub fn frame0_mut(&mut self) -> &mut Frame
Return mutable top-level frame
sourcepub fn get_capture(&mut self, pos: usize) -> Option<Capture>
pub fn get_capture(&mut self, pos: usize) -> Option<Capture>
Return a capture by index as RefValue.
sourcepub fn get_capture_by_name(&mut self, name: &str) -> Option<Capture>
pub fn get_capture_by_name(&mut self, name: &str) -> Option<Capture>
Return a capture by name as RefValue.
sourcepub fn set_capture(&mut self, pos: usize, value: RefValue)
pub fn set_capture(&mut self, pos: usize, value: RefValue)
Set a capture to a RefValue by index.
sourcepub fn set_capture_by_name(&mut self, name: &str, value: RefValue)
pub fn set_capture_by_name(&mut self, name: &str, value: RefValue)
Set a capture to a RefValue by name.
sourcepub fn collect(
&mut self,
capture_start: usize,
copy: bool,
sequence: bool,
debug: bool,
) -> Capture
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more