Fix doc comments.
This commit is contained in:
parent
8dc7137913
commit
255af006ee
@ -31,7 +31,7 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LangOptions {
|
impl LangOptions {
|
||||||
/// Create a new [`Options`] with default values.
|
/// Create a new [`LangOptions`] with default values.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::IF_EXPR | Self::SWITCH_EXPR | Self::STMT_EXPR | Self::LOOPING | Self::SHADOW | {
|
Self::IF_EXPR | Self::SWITCH_EXPR | Self::STMT_EXPR | Self::LOOPING | Self::SHADOW | {
|
||||||
|
@ -274,7 +274,7 @@ impl AST {
|
|||||||
pub fn shared_lib(&self) -> &crate::Shared<crate::Module> {
|
pub fn shared_lib(&self) -> &crate::Shared<crate::Module> {
|
||||||
&self.lib
|
&self.lib
|
||||||
}
|
}
|
||||||
/// Get the embedded [module resolver][`ModuleResolver`].
|
/// Get the embedded [module resolver][crate::ModuleResolver].
|
||||||
#[cfg(not(feature = "internals"))]
|
#[cfg(not(feature = "internals"))]
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -297,7 +297,7 @@ impl AST {
|
|||||||
) -> Option<&crate::Shared<crate::module::resolvers::StaticModuleResolver>> {
|
) -> Option<&crate::Shared<crate::module::resolvers::StaticModuleResolver>> {
|
||||||
self.resolver.as_ref()
|
self.resolver.as_ref()
|
||||||
}
|
}
|
||||||
/// Set the embedded [module resolver][`ModuleResolver`].
|
/// Set the embedded [module resolver][crate::ModuleResolver].
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn set_resolver(
|
pub(crate) fn set_resolver(
|
||||||
|
@ -35,7 +35,7 @@ impl From<&Expr> for ChainType {
|
|||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
/// Chain-evaluate a dot/index chain.
|
/// Chain-evaluate a dot/index chain.
|
||||||
/// [`Position`] in [`EvalAltResult`] may be [`NONE`][Position::NONE] and should be set afterwards.
|
/// [`Position`] in [`EvalAltResult`][crate::EvalAltResult] may be [`NONE`][Position::NONE] and should be set afterwards.
|
||||||
fn eval_dot_index_chain_helper(
|
fn eval_dot_index_chain_helper(
|
||||||
&self,
|
&self,
|
||||||
global: &mut GlobalRuntimeState,
|
global: &mut GlobalRuntimeState,
|
||||||
@ -641,9 +641,7 @@ impl Engine {
|
|||||||
.map_err(|err| err.fill_position(op_pos))
|
.map_err(|err| err.fill_position(op_pos))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a chain of indexes and store the results in a [`StaticVec`].
|
/// Evaluate a chain of indexes and store the results in a [`FnArgsVec`].
|
||||||
/// [`StaticVec`] is used to avoid an allocation in the overwhelming cases of
|
|
||||||
/// just a few levels of indexing.
|
|
||||||
fn eval_dot_index_chain_arguments(
|
fn eval_dot_index_chain_arguments(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
@ -804,7 +802,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the value at the indexed position of a base type.
|
/// Get the value at the indexed position of a base type.
|
||||||
/// [`Position`] in [`EvalAltResult`] may be [`NONE`][Position::NONE] and should be set afterwards.
|
/// [`Position`] in [`EvalAltResult`][crate::EvalAltResult] may be [`NONE`][Position::NONE] and should be set afterwards.
|
||||||
fn get_indexed_mut<'t>(
|
fn get_indexed_mut<'t>(
|
||||||
&self,
|
&self,
|
||||||
global: &mut GlobalRuntimeState,
|
global: &mut GlobalRuntimeState,
|
||||||
|
@ -732,7 +732,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate a list of statements with no `this` pointer.
|
/// Evaluate a list of statements with no `this` pointer.
|
||||||
/// This is commonly used to evaluate a list of statements in an [`AST`] or a script function body.
|
/// This is commonly used to evaluate a list of statements in an [`AST`][crate::AST] or a script function body.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn eval_global_statements(
|
pub(crate) fn eval_global_statements(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1924,9 +1924,7 @@ impl Module {
|
|||||||
/// cross-call each other.
|
/// cross-call each other.
|
||||||
///
|
///
|
||||||
/// Functions in the global namespace, plus all functions defined in the [`Module`], are
|
/// Functions in the global namespace, plus all functions defined in the [`Module`], are
|
||||||
/// _merged_ into a _unified_ namespace before each call.
|
/// _merged_ into a _unified_ namespace. Therefore, all functions will be found.
|
||||||
///
|
|
||||||
/// Therefore, all functions will be found.
|
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -1959,16 +1957,14 @@ impl Module {
|
|||||||
/// cross-call each other.
|
/// cross-call each other.
|
||||||
///
|
///
|
||||||
/// Functions in the global namespace, plus all functions defined in the [`Module`], are
|
/// Functions in the global namespace, plus all functions defined in the [`Module`], are
|
||||||
/// _merged_ into a _unified_ namespace before each call.
|
/// _merged_ into a _unified_ namespace. Therefore, all functions will be found.
|
||||||
///
|
|
||||||
/// Therefore, all functions will be found.
|
|
||||||
///
|
///
|
||||||
/// # WARNING - Low Level API
|
/// # WARNING - Low Level API
|
||||||
///
|
///
|
||||||
/// This function is very low level.
|
/// This function is very low level.
|
||||||
///
|
///
|
||||||
/// In particular, the [`global`][crate::eval::GlobalRuntimeState] parameter allows the
|
/// In particular, the [`global`][crate::GlobalRuntimeState] parameter allows the entire
|
||||||
/// entire calling environment to be encapsulated, including automatic global constants.
|
/// calling environment to be encapsulated, including automatic global constants.
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
pub fn eval_ast_as_new_raw(
|
pub fn eval_ast_as_new_raw(
|
||||||
engine: &crate::Engine,
|
engine: &crate::Engine,
|
||||||
|
@ -165,13 +165,13 @@ impl<'e> ParseState<'e> {
|
|||||||
/// The return value is the offset to be deducted from `ParseState::stack::len()`,
|
/// 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.
|
/// i.e. the top element of [`ParseState`]'s variables stack is offset 1.
|
||||||
///
|
///
|
||||||
/// # Return value: `(index, is_func)`
|
/// # Return value: `(index, is_func_name)`
|
||||||
///
|
///
|
||||||
/// * `index`: `None` when the variable name is not found in the `stack`,
|
/// * `index`: `None` when the variable name is not found in the `stack`,
|
||||||
/// otherwise the index value.
|
/// otherwise the index value.
|
||||||
///
|
///
|
||||||
/// * `is_func`: `true` if the variable is actually the name of a function
|
/// * `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).
|
/// (in which case it will be converted into a function pointer).
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn access_var(
|
pub fn access_var(
|
||||||
@ -185,14 +185,15 @@ impl<'e> ParseState<'e> {
|
|||||||
let (index, hit_barrier) = self.find_var(name);
|
let (index, hit_barrier) = self.find_var(name);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
let is_func = lib.values().any(|f| f.name == name);
|
let is_func_name = lib.values().any(|f| f.name == name);
|
||||||
|
|
||||||
#[cfg(feature = "no_function")]
|
#[cfg(feature = "no_function")]
|
||||||
let is_func = false;
|
let is_func_name = false;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
if self.allow_capture {
|
if self.allow_capture {
|
||||||
if !is_func && index == 0 && !self.external_vars.iter().any(|v| v.as_str() == name) {
|
if !is_func_name && index == 0 && !self.external_vars.iter().any(|v| v.as_str() == name)
|
||||||
|
{
|
||||||
self.external_vars.push(crate::ast::Ident {
|
self.external_vars.push(crate::ast::Ident {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
pos: _pos,
|
pos: _pos,
|
||||||
@ -208,7 +209,7 @@ impl<'e> ParseState<'e> {
|
|||||||
NonZeroUsize::new(index)
|
NonZeroUsize::new(index)
|
||||||
};
|
};
|
||||||
|
|
||||||
(index, is_func)
|
(index, is_func_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find a module by name in the [`ParseState`], searching in reverse.
|
/// Find a module by name in the [`ParseState`], searching in reverse.
|
||||||
@ -257,15 +258,15 @@ impl<'e> ParseState<'e> {
|
|||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
struct ParseSettings {
|
struct ParseSettings {
|
||||||
/// Is the construct being parsed located at global level?
|
/// Is the construct being parsed located at global level?
|
||||||
is_global: bool,
|
at_global_level: bool,
|
||||||
/// Is the construct being parsed located at function definition level?
|
/// Is the construct being parsed located inside a function definition?
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
is_function_scope: bool,
|
in_fn_scope: bool,
|
||||||
/// Is the construct being parsed located inside a closure?
|
/// Is the construct being parsed located inside a closure definition?
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
is_closure_scope: bool,
|
in_closure: bool,
|
||||||
/// Is the current position inside a loop?
|
/// Is the construct being parsed located inside a breakable loop?
|
||||||
is_breakable: bool,
|
is_breakable: bool,
|
||||||
/// Language options in effect (overrides Engine options).
|
/// Language options in effect (overrides Engine options).
|
||||||
options: LangOptions,
|
options: LangOptions,
|
||||||
@ -1388,10 +1389,10 @@ impl Engine {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let new_settings = ParseSettings {
|
let new_settings = ParseSettings {
|
||||||
is_global: false,
|
at_global_level: false,
|
||||||
is_function_scope: true,
|
in_fn_scope: true,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
is_closure_scope: true,
|
in_closure: true,
|
||||||
is_breakable: false,
|
is_breakable: false,
|
||||||
level: 0,
|
level: 0,
|
||||||
options,
|
options,
|
||||||
@ -1406,7 +1407,7 @@ impl Engine {
|
|||||||
let (index, is_func) = state.access_var(name, lib, *pos);
|
let (index, is_func) = state.access_var(name, lib, *pos);
|
||||||
|
|
||||||
if settings.options.contains(LangOptions::STRICT_VAR)
|
if settings.options.contains(LangOptions::STRICT_VAR)
|
||||||
&& !settings.is_closure_scope
|
&& !settings.in_closure
|
||||||
&& index.is_none()
|
&& index.is_none()
|
||||||
&& !state.scope.contains(name)
|
&& !state.scope.contains(name)
|
||||||
&& !is_func
|
&& !is_func
|
||||||
@ -1601,7 +1602,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
// Access to `this` as a variable is OK within a function scope
|
// Access to `this` as a variable is OK within a function scope
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
_ if &*s == KEYWORD_THIS && settings.is_function_scope => Expr::Variable(
|
_ if &*s == KEYWORD_THIS && settings.in_fn_scope => Expr::Variable(
|
||||||
(None, ns, 0, state.get_identifier("", s)).into(),
|
(None, ns, 0, state.get_identifier("", s)).into(),
|
||||||
None,
|
None,
|
||||||
settings.pos,
|
settings.pos,
|
||||||
@ -3068,7 +3069,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse statements inside the block
|
// Parse statements inside the block
|
||||||
settings.is_global = false;
|
settings.at_global_level = false;
|
||||||
|
|
||||||
let stmt = self.parse_stmt(input, state, lib, settings.level_up())?;
|
let stmt = self.parse_stmt(input, state, lib, settings.level_up())?;
|
||||||
|
|
||||||
@ -3164,7 +3165,7 @@ impl Engine {
|
|||||||
unreachable!("doc-comment expected but gets {:?}", comment);
|
unreachable!("doc-comment expected but gets {:?}", comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !settings.is_global {
|
if !settings.at_global_level {
|
||||||
return Err(PERR::WrongDocComment.into_err(comments_pos));
|
return Err(PERR::WrongDocComment.into_err(comments_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3206,7 +3207,9 @@ impl Engine {
|
|||||||
|
|
||||||
// fn ...
|
// fn ...
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Token::Fn if !settings.is_global => Err(PERR::WrongFnDefinition.into_err(token_pos)),
|
Token::Fn if !settings.at_global_level => {
|
||||||
|
Err(PERR::WrongFnDefinition.into_err(token_pos))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Token::Fn | Token::Private => {
|
Token::Fn | Token::Private => {
|
||||||
@ -3247,10 +3250,10 @@ impl Engine {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let new_settings = ParseSettings {
|
let new_settings = ParseSettings {
|
||||||
is_global: false,
|
at_global_level: false,
|
||||||
is_function_scope: true,
|
in_fn_scope: true,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
is_closure_scope: false,
|
in_closure: false,
|
||||||
is_breakable: false,
|
is_breakable: false,
|
||||||
level: 0,
|
level: 0,
|
||||||
options,
|
options,
|
||||||
@ -3335,7 +3338,7 @@ impl Engine {
|
|||||||
// `return`/`throw` at <EOF>
|
// `return`/`throw` at <EOF>
|
||||||
(Token::EOF, ..) => Ok(Stmt::Return(None, return_type, token_pos)),
|
(Token::EOF, ..) => Ok(Stmt::Return(None, return_type, token_pos)),
|
||||||
// `return`/`throw` at end of block
|
// `return`/`throw` at end of block
|
||||||
(Token::RightBrace, ..) if !settings.is_global => {
|
(Token::RightBrace, ..) if !settings.at_global_level => {
|
||||||
Ok(Stmt::Return(None, return_type, token_pos))
|
Ok(Stmt::Return(None, return_type, token_pos))
|
||||||
}
|
}
|
||||||
// `return;` or `throw;`
|
// `return;` or `throw;`
|
||||||
@ -3357,7 +3360,9 @@ impl Engine {
|
|||||||
Token::Import => self.parse_import(input, state, lib, settings.level_up()),
|
Token::Import => self.parse_import(input, state, lib, settings.level_up()),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
Token::Export if !settings.is_global => Err(PERR::WrongExport.into_err(token_pos)),
|
Token::Export if !settings.at_global_level => {
|
||||||
|
Err(PERR::WrongExport.into_err(token_pos))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
Token::Export => self.parse_export(input, state, lib, settings.level_up()),
|
Token::Export => self.parse_export(input, state, lib, settings.level_up()),
|
||||||
@ -3717,12 +3722,12 @@ impl Engine {
|
|||||||
options.remove(LangOptions::ANON_FN);
|
options.remove(LangOptions::ANON_FN);
|
||||||
|
|
||||||
let settings = ParseSettings {
|
let settings = ParseSettings {
|
||||||
is_global: true,
|
at_global_level: true,
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
is_function_scope: false,
|
in_fn_scope: false,
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
is_closure_scope: false,
|
in_closure: false,
|
||||||
is_breakable: false,
|
is_breakable: false,
|
||||||
level: 0,
|
level: 0,
|
||||||
options,
|
options,
|
||||||
@ -3772,12 +3777,12 @@ impl Engine {
|
|||||||
|
|
||||||
while !input.peek().expect(NEVER_ENDS).0.is_eof() {
|
while !input.peek().expect(NEVER_ENDS).0.is_eof() {
|
||||||
let settings = ParseSettings {
|
let settings = ParseSettings {
|
||||||
is_global: true,
|
at_global_level: true,
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
is_function_scope: false,
|
in_fn_scope: false,
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
is_closure_scope: false,
|
in_closure: false,
|
||||||
is_breakable: false,
|
is_breakable: false,
|
||||||
options: self.options,
|
options: self.options,
|
||||||
level: 0,
|
level: 0,
|
||||||
|
@ -29,7 +29,7 @@ mod private {
|
|||||||
use crate::func::SendSync;
|
use crate::func::SendSync;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
/// A sealed trait that prevents other crates from implementing [`Variant`].
|
/// A sealed trait that prevents other crates from implementing [`Variant`][super::Variant].
|
||||||
pub trait Sealed {}
|
pub trait Sealed {}
|
||||||
|
|
||||||
impl<T: Any + Clone + SendSync> Sealed for T {}
|
impl<T: Any + Clone + SendSync> Sealed for T {}
|
||||||
|
@ -527,7 +527,7 @@ impl EvalAltResult {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`]
|
/// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`]
|
||||||
/// if the current position is [`Position::None`].
|
/// if the current position is [`Position::NONE`].
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn fill_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {
|
pub(crate) fn fill_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {
|
||||||
|
Loading…
Reference in New Issue
Block a user