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>
impl<'a, 't, 'f> ParseState<'a, 't, 'f>
sourcepub 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
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
.
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 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
.