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>
impl<'e, 's> ParseState<'e, 's>
sourcepub fn new(
external_constants: Option<&'e Scope<'_>>,
interned_strings: &'s mut StringsInterner,
tokenizer_control: TokenizerControl
) -> Self
pub fn new( external_constants: Option<&'e Scope<'_>>, interned_strings: &'s mut StringsInterner, tokenizer_control: TokenizerControl ) -> Self
Create a new ParseState
.
sourcepub fn find_var(&self, name: &str) -> (usize, bool)
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.
sourcepub fn access_var(
&mut self,
name: &str,
lib: &HashMap<u64, Shared<ScriptFnDef>, StraightHasherBuilder>,
pos: Position
) -> (Option<NonZeroUsize>, bool)
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 thestack
, 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).
sourcepub fn find_module(&self, name: &str) -> Option<NonZeroUsize>
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
.
sourcepub fn get_interned_string(
&mut self,
text: impl AsRef<str> + Into<ImmutableString>
) -> ImmutableString
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.
sourcepub fn get_interned_getter(
&mut self,
text: impl AsRef<str> + Into<ImmutableString>
) -> ImmutableString
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.
sourcepub fn get_interned_setter(
&mut self,
text: impl AsRef<str> + Into<ImmutableString>
) -> ImmutableString
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.