Struct rhai::ParseState

source ·
pub struct ParseState<'a, 't, 'f> {
    pub input: &'t mut Peekable<TokenIterator<'a>>,
    pub tokenizer_control: TokenizerControl,
    pub lib: &'f mut HashMap<u64, Shared<ScriptFuncDef>, StraightHasherBuilder>,
    pub expr_filter: fn(_: &Token) -> bool,
    pub external_constants: Option<&'a Scope<'a>>,
    pub global: Option<Box<GlobalRuntimeState>>,
    pub stack: Scope<'a>,
    pub frame_pointer: usize,
    pub external_vars: ThinVec<Ident>,
    pub allow_capture: bool,
    pub imports: ThinVec<ImmutableString>,
    pub global_imports: ThinVec<ImmutableString>,
}
Expand description

(internals) A type that encapsulates the current state of the parser. Exported under the internals feature only.

Fields§

§input: &'t mut Peekable<TokenIterator<'a>>

Stream of input tokens.

§tokenizer_control: TokenizerControl

Tokenizer control interface.

§lib: &'f mut HashMap<u64, Shared<ScriptFuncDef>, StraightHasherBuilder>

Script-defined functions.

§expr_filter: fn(_: &Token) -> bool

Controls whether parsing of an expression should stop given the next token.

§external_constants: Option<&'a Scope<'a>>

External scope with constants.

§global: Option<Box<GlobalRuntimeState>>

Global runtime state.

§stack: Scope<'a>

Encapsulates a local stack with variable names to simulate an actual runtime scope.

§frame_pointer: usize

Size of the local variables stack upon entry of the current block scope.

§external_vars: ThinVec<Ident>

Tracks a list of external variables (variables that are not explicitly declared in the scope).

§allow_capture: bool

An indicator that, when set to false, disables variable capturing into externals one single time up until the nearest consumed Identifier token.

If set to false the next call to [access_var][ParseState::access_var] will not capture the variable.

All consequent calls to [access_var][ParseState::access_var] will not be affected.

§imports: ThinVec<ImmutableString>

Encapsulates a local stack with imported module names.

§global_imports: ThinVec<ImmutableString>

List of globally-imported module names.

Implementations§

source§

impl<'a, 't, 'f> ParseState<'a, 't, 'f>

source

pub fn new( external_constants: Option<&'a Scope<'_>>, input: &'t mut Peekable<TokenIterator<'a>>, tokenizer_control: TokenizerControl, lib: &'f mut HashMap<u64, Shared<ScriptFuncDef>, StraightHasherBuilder> ) -> Self

Create a new ParseState.

source

pub fn find_var(&self, name: &str) -> (usize, bool)

Find explicitly declared variable by name in the ParseState, searching in reverse order.

The first return value is the offset to be deducted from ParseState::stack::len(), i.e. the top element of ParseState’s variables stack is offset 1.

If the variable is not present in the scope, the first return value is zero.

The second return value indicates whether the barrier has been hit before finding the variable.

source

pub fn find_module(&self, name: &str) -> Option<NonZeroUsize>

Find a module by name in the ParseState, searching in reverse.

Returns the offset to be deducted from Stack::len, i.e. the top element of the ParseState is offset 1.

Returns None when the variable name is not found in the ParseState.

§Panics

Panics when called under no_module.

Trait Implementations§

source§

impl Debug for ParseState<'_, '_, '_>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 't, 'f> Freeze for ParseState<'a, 't, 'f>

§

impl<'a, 't, 'f> !RefUnwindSafe for ParseState<'a, 't, 'f>

§

impl<'a, 't, 'f> !Send for ParseState<'a, 't, 'f>

§

impl<'a, 't, 'f> !Sync for ParseState<'a, 't, 'f>

§

impl<'a, 't, 'f> Unpin for ParseState<'a, 't, 'f>

§

impl<'a, 't, 'f> !UnwindSafe for ParseState<'a, 't, 'f>

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.