Struct rhai::ParseState

source ·
pub struct ParseState<'e, 's> {
    pub tokenizer_control: TokenizerControl,
    pub expr_filter: fn(_: &Token) -> bool,
    pub interned_strings: &'s mut StringsInterner,
    pub external_constants: Option<&'e Scope<'e>>,
    pub global: Option<Box<GlobalRuntimeState>>,
    pub stack: Option<Box<Scope<'e>>>,
    pub block_stack_len: usize,
    pub external_vars: Option<Box<SmallVec<[Ident; 5]>>>,
    pub allow_capture: bool,
    pub imports: Option<Box<StaticVec<ImmutableString>>>,
    pub global_imports: Option<Box<StaticVec<ImmutableString>>>,
}
Expand description

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

Fields§

§tokenizer_control: TokenizerControl

Input stream buffer containing the next character to read.

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

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

§interned_strings: &'s mut StringsInterner

Strings interner.

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

External scope with constants.

§global: Option<Box<GlobalRuntimeState>>

Global runtime state.

§stack: Option<Box<Scope<'e>>>

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

§block_stack_len: usize

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

§external_vars: Option<Box<SmallVec<[Ident; 5]>>>

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 will not capture the variable.

All consequent calls to access_var will not be affected.

§imports: Option<Box<StaticVec<ImmutableString>>>

Encapsulates a local stack with imported module names.

§global_imports: Option<Box<StaticVec<ImmutableString>>>

List of globally-imported module names.

Implementations§

source§

impl<'e, 's> ParseState<'e, 's>

source

pub fn new( external_constants: Option<&'e Scope<'_>>, interned_strings: &'s mut StringsInterner, tokenizer_control: TokenizerControl ) -> 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 access_var( &mut self, name: &str, lib: &HashMap<u64, Shared<ScriptFnDef>, StraightHasherBuilder>, pos: Position ) -> (Option<NonZeroUsize>, bool)

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

If the variable is not present in the scope adds it to the list of external variables.

The 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.

Return value: (index, is_func_name)
  • index: None when the variable name is not found in the stack, otherwise the index value.

  • is_func_name: true if the variable is actually the name of a function (in which case it will be converted into a function pointer).

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.

source

pub fn get_interned_string( &mut self, text: impl AsRef<str> + Into<ImmutableString> ) -> ImmutableString

Get an interned string, creating one if it is not yet interned.

source

pub fn get_interned_getter( &mut self, text: impl AsRef<str> + Into<ImmutableString> ) -> ImmutableString

Get an interned property getter, creating one if it is not yet interned.

source

pub fn get_interned_setter( &mut self, text: impl AsRef<str> + Into<ImmutableString> ) -> ImmutableString

Get an interned property setter, creating one if it is not yet interned.

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<'e, 's> !RefUnwindSafe for ParseState<'e, 's>

§

impl<'e, 's> !Send for ParseState<'e, 's>

§

impl<'e, 's> !Sync for ParseState<'e, 's>

§

impl<'e, 's> Unpin for ParseState<'e, 's>

§

impl<'e, 's> !UnwindSafe for ParseState<'e, 's>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.