Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<'a> {
Show 13 fields pub lang: &'a Language, pub a: Arena, pub st: Stack, pub lexer: Lexer<'a>, pub finished: u32, pub accept_count: u32, pub limits: Limits, pub steps: u64, pub step_limit: u64, pub aborted: bool, pub live_after: usize, pub live_st_after: usize, pub scanner: Option<Box<dyn Scanner>>, /* private fields */
}

Fields§

§lang: &'a Language§a: Arena§st: Stack§lexer: Lexer<'a>§finished: u32§accept_count: u32§limits: Limits§steps: u64§step_limit: u64§aborted: bool§live_after: usize§live_st_after: usize§scanner: Option<Box<dyn Scanner>>

Implementations§

Source§

impl Parser<'_>

Source

pub fn maybe_compact(&mut self)

只能在没有悬空节点编号的时刻调用(主循环两轮之间)。

Source

pub fn compact_stack(&mut self)

回收不可达的栈节点,子树编号不变。基节点(0 号)始终保留。

Source

pub fn compact_arena(&mut self)

回收不可达的子树;活的占九成以上就不重建。

Source§

impl<'a> Parser<'a>

Source

pub fn try_new( lang: &'a Language, input: &'a [u8], limits: Limits, ) -> Option<Parser<'a>>

Source

pub fn new(lang: &'a Language, input: &'a [u8], limits: Limits) -> Parser<'a>

Source

pub fn check_timeout_now(&mut self) -> bool

立即核对协作式时间预算(仅用于低频检查点)。

Source

pub fn over_budget(&mut self) -> bool

超出任何一项资源上限就标记中止。

Source

pub fn shift(&mut self, version: usize, state: u16, lookahead: u32, extra: bool)

Source

pub fn select_tree(&mut self, left: u32, right: u32) -> bool

官方 ts_parser__select_tree:true 表示选右边。

Source

pub fn reduce( &mut self, version: usize, symbol: u16, count: u16, dprec: i16, prod: u16, is_fragile: bool, end_of_extra: bool, ) -> Option<usize>

Source

pub fn accept(&mut self, version: usize, lookahead: u32)

Source

pub fn advance(&mut self, version: usize) -> bool

官方 ts_parser__advance:返回 false 表示超出资源上限。

Source

pub fn run(&mut self)

主循环。成功后根节点在 self.finished(可能是 NONE)。

Source§

impl Parser<'_>

Source

pub fn recover(&mut self, version: usize, lookahead: u32)

Source

pub fn handle_error(&mut self, version: usize, lookahead: u32)

Source

pub fn condense_stack(&mut self) -> u32

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Parser<'a>

§

impl<'a> !Send for Parser<'a>

§

impl<'a> !Sync for Parser<'a>

§

impl<'a> !UnwindSafe for Parser<'a>

§

impl<'a> Forget for Parser<'a>

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> Move for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.