pub struct ParserState {
pub rule_id: i32,
pub sequence_id: i32,
pub element_id: i32,
pub rule_start_pos: i32,
pub budget_deadline: i32,
pub sub_element_id: i32,
pub repeat_count: i32,
pub partial_codepoint: i32,
pub active_temperature_rule_id: i32,
pub char_budget_deadline: i32,
}Expand description
One Earley item: a position within a rule’s FSM plus the input position it began at.
Fields§
§rule_id: i32The rule’s id (-1 for an IR-path lookahead state).
sequence_id: i32The rule body (or lookahead sequence) expression id.
element_id: i32The current FSM node (or element index in an IR sequence).
rule_start_pos: i32The input position the rule started at, or Self::NO_PREV_INPUT_POS for the root.
budget_deadline: i32The last token index this state’s derivation may consume, from the token budget
(Rule::max_tokens) of the rule it is inside; -1 means unlimited.
sub_element_id: i32The id of the sub element in the current element of the sequence.
repeat_count: i32The number of times the element is repeated (for repeat edges).
partial_codepoint: i32Partial codepoint accumulated during UTF-8 decoding for character classes.
active_temperature_rule_id: i32The innermost active rule that specifies a sampling temperature, or -1.
char_budget_deadline: i32The absolute input codepoint position at which the active character budget expires;
-1 means unlimited.
Implementations§
Source§impl ParserState
impl ParserState
Sourcepub const NO_PREV_INPUT_POS: i32 = -1
pub const NO_PREV_INPUT_POS: i32 = -1
A rule_start_pos meaning the state is the root of the parsing stack.
Sourcepub fn new(
rule_id: i32,
sequence_id: i32,
element_id: i32,
rule_start_pos: i32,
) -> Self
pub fn new( rule_id: i32, sequence_id: i32, element_id: i32, rule_start_pos: i32, ) -> Self
Creates a state at element_id of sequence_id with no budgets, sub element, repeat
count, partial codepoint, or temperature rule.
Sourcepub fn at_element(&self, element_id: i32) -> Self
pub fn at_element(&self, element_id: i32) -> Self
The same occurrence moved to element_id, with the sub element, repeat count, and
partial codepoint reset (budgets and the temperature rule are inherited).
Sourcepub fn at_element_with_repeat(&self, element_id: i32, repeat_count: i32) -> Self
pub fn at_element_with_repeat(&self, element_id: i32, repeat_count: i32) -> Self
Like Self::at_element, keeping repeat_count.
Sourcepub fn cache_key(&self) -> ParserStateCacheKey
pub fn cache_key(&self) -> ParserStateCacheKey
The adaptive token-mask cache key of this state.
Sourcepub fn serialize_member_array(&self) -> [i32; 10]
pub fn serialize_member_array(&self) -> [i32; 10]
Serializes as the C++ XGRAMMAR_MEMBER_ARRAY order.
Sourcepub fn from_member_array(values: &[i32]) -> Option<Self>
pub fn from_member_array(values: &[i32]) -> Option<Self>
Deserializes a member array produced by Self::serialize_member_array.
Returns None unless values contains exactly ten integers.
Trait Implementations§
Source§impl Clone for ParserState
impl Clone for ParserState
impl Copy for ParserState
Source§impl Debug for ParserState
impl Debug for ParserState
Source§impl Display for ParserState
impl Display for ParserState
impl Eq for ParserState
Source§impl Hash for ParserState
impl Hash for ParserState
Source§impl Ord for ParserState
impl Ord for ParserState
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ParserState
impl PartialEq for ParserState
Source§impl PartialOrd for ParserState
impl PartialOrd for ParserState
impl StructuralPartialEq for ParserState
Auto Trait Implementations§
impl Freeze for ParserState
impl RefUnwindSafe for ParserState
impl Send for ParserState
impl Sync for ParserState
impl Unpin for ParserState
impl UnsafeUnpin for ParserState
impl UnwindSafe for ParserState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more