Use .. for (_).
This commit is contained in:
parent
97a8fd3d5b
commit
7686ca619a
@ -366,7 +366,7 @@ impl Parse for ExportedFn {
|
|||||||
}) => {
|
}) => {
|
||||||
matches!(flatten_type_groups(elem.as_ref()), syn::Type::Path(ref p) if p.path == str_type_path)
|
matches!(flatten_type_groups(elem.as_ref()), syn::Type::Path(ref p) if p.path == str_type_path)
|
||||||
}
|
}
|
||||||
syn::Type::Verbatim(_) => false,
|
syn::Type::Verbatim(..) => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
if !is_ok {
|
if !is_ok {
|
||||||
@ -381,13 +381,13 @@ impl Parse for ExportedFn {
|
|||||||
match fn_all.sig.output {
|
match fn_all.sig.output {
|
||||||
syn::ReturnType::Type(.., ref ret_type) => {
|
syn::ReturnType::Type(.., ref ret_type) => {
|
||||||
match flatten_type_groups(ret_type.as_ref()) {
|
match flatten_type_groups(ret_type.as_ref()) {
|
||||||
syn::Type::Ptr(_) => {
|
syn::Type::Ptr(..) => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
fn_all.sig.output.span(),
|
fn_all.sig.output.span(),
|
||||||
"Rhai functions cannot return pointers",
|
"Rhai functions cannot return pointers",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
syn::Type::Reference(_) => {
|
syn::Type::Reference(..) => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
fn_all.sig.output.span(),
|
fn_all.sig.output.span(),
|
||||||
"Rhai functions cannot return references",
|
"Rhai functions cannot return references",
|
||||||
@ -544,28 +544,28 @@ impl ExportedFn {
|
|||||||
|
|
||||||
match params.special {
|
match params.special {
|
||||||
// 2a. Property getters must take only the subject as an argument.
|
// 2a. Property getters must take only the subject as an argument.
|
||||||
FnSpecialAccess::Property(Property::Get(_)) if self.arg_count() != 1 => {
|
FnSpecialAccess::Property(Property::Get(..)) if self.arg_count() != 1 => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.inputs.span(),
|
self.signature.inputs.span(),
|
||||||
"property getter requires exactly 1 parameter",
|
"property getter requires exactly 1 parameter",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// 2b. Property getters must return a value.
|
// 2b. Property getters must return a value.
|
||||||
FnSpecialAccess::Property(Property::Get(_)) if self.return_type().is_none() => {
|
FnSpecialAccess::Property(Property::Get(..)) if self.return_type().is_none() => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.span(),
|
self.signature.span(),
|
||||||
"property getter must return a value",
|
"property getter must return a value",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// 3a. Property setters must take the subject and a new value as arguments.
|
// 3a. Property setters must take the subject and a new value as arguments.
|
||||||
FnSpecialAccess::Property(Property::Set(_)) if self.arg_count() != 2 => {
|
FnSpecialAccess::Property(Property::Set(..)) if self.arg_count() != 2 => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
self.signature.inputs.span(),
|
self.signature.inputs.span(),
|
||||||
"property setter requires exactly 2 parameters",
|
"property setter requires exactly 2 parameters",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
// 3b. Non-raw property setters must return nothing.
|
// 3b. Non-raw property setters must return nothing.
|
||||||
FnSpecialAccess::Property(Property::Set(_))
|
FnSpecialAccess::Property(Property::Set(..))
|
||||||
if params.return_raw.is_none() && self.return_type().is_some() =>
|
if params.return_raw.is_none() && self.return_type().is_some() =>
|
||||||
{
|
{
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
@ -734,7 +734,7 @@ impl ExportedFn {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
syn::FnArg::Receiver(_) => todo!("true self parameters not implemented yet"),
|
syn::FnArg::Receiver(..) => todo!("true self parameters not implemented yet"),
|
||||||
}
|
}
|
||||||
unpack_exprs.push(syn::parse2::<syn::Expr>(quote! { #var }).unwrap());
|
unpack_exprs.push(syn::parse2::<syn::Expr>(quote! { #var }).unwrap());
|
||||||
} else {
|
} else {
|
||||||
@ -811,7 +811,7 @@ impl ExportedFn {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syn::FnArg::Receiver(_) => panic!("internal error: how did this happen!?"),
|
syn::FnArg::Receiver(..) => panic!("internal error: how did this happen!?"),
|
||||||
}
|
}
|
||||||
if !is_ref {
|
if !is_ref {
|
||||||
unpack_exprs.push(syn::parse2::<syn::Expr>(quote! { #var }).unwrap());
|
unpack_exprs.push(syn::parse2::<syn::Expr>(quote! { #var }).unwrap());
|
||||||
|
@ -144,12 +144,14 @@ impl Parse for Module {
|
|||||||
attrs,
|
attrs,
|
||||||
ty,
|
ty,
|
||||||
..
|
..
|
||||||
}) if matches!(vis, syn::Visibility::Public(_)) => consts.push(ExportedConst {
|
}) if matches!(vis, syn::Visibility::Public(..)) => {
|
||||||
name: ident.to_string(),
|
consts.push(ExportedConst {
|
||||||
typ: ty.clone(),
|
name: ident.to_string(),
|
||||||
expr: expr.as_ref().clone(),
|
typ: ty.clone(),
|
||||||
cfg_attrs: crate::attrs::collect_cfg_attr(&attrs),
|
expr: expr.as_ref().clone(),
|
||||||
}),
|
cfg_attrs: crate::attrs::collect_cfg_attr(&attrs),
|
||||||
|
})
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +163,7 @@ impl Parse for Module {
|
|||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < content.len() {
|
while i < content.len() {
|
||||||
match content[i] {
|
match content[i] {
|
||||||
syn::Item::Mod(_) => {
|
syn::Item::Mod(..) => {
|
||||||
let mut item_mod = match content.remove(i) {
|
let mut item_mod = match content.remove(i) {
|
||||||
syn::Item::Mod(m) => m,
|
syn::Item::Mod(m) => m,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@ -212,7 +214,7 @@ impl Module {
|
|||||||
pub fn update_scope(&mut self, parent_scope: &ExportScope) {
|
pub fn update_scope(&mut self, parent_scope: &ExportScope) {
|
||||||
let keep = match (self.params.skip, parent_scope) {
|
let keep = match (self.params.skip, parent_scope) {
|
||||||
(true, ..) => false,
|
(true, ..) => false,
|
||||||
(.., ExportScope::PubOnly) => matches!(self.mod_all.vis, syn::Visibility::Public(_)),
|
(.., ExportScope::PubOnly) => matches!(self.mod_all.vis, syn::Visibility::Public(..)),
|
||||||
(.., ExportScope::Prefix(s)) => self.mod_all.ident.to_string().starts_with(s),
|
(.., ExportScope::Prefix(s)) => self.mod_all.ident.to_string().starts_with(s),
|
||||||
(.., ExportScope::All) => true,
|
(.., ExportScope::All) => true,
|
||||||
};
|
};
|
||||||
|
@ -99,7 +99,7 @@ pub fn generate_body(
|
|||||||
let fn_input_types: Vec<_> = function
|
let fn_input_types: Vec<_> = function
|
||||||
.arg_list()
|
.arg_list()
|
||||||
.map(|fn_arg| match fn_arg {
|
.map(|fn_arg| match fn_arg {
|
||||||
syn::FnArg::Receiver(_) => panic!("internal error: receiver fn outside impl!?"),
|
syn::FnArg::Receiver(..) => panic!("internal error: receiver fn outside impl!?"),
|
||||||
syn::FnArg::Typed(syn::PatType { ref ty, .. }) => {
|
syn::FnArg::Typed(syn::PatType { ref ty, .. }) => {
|
||||||
let arg_type = match flatten_type_groups(ty.as_ref()) {
|
let arg_type = match flatten_type_groups(ty.as_ref()) {
|
||||||
syn::Type::Reference(syn::TypeReference {
|
syn::Type::Reference(syn::TypeReference {
|
||||||
@ -150,7 +150,7 @@ pub fn generate_body(
|
|||||||
|
|
||||||
match function.params().special {
|
match function.params().special {
|
||||||
FnSpecialAccess::None => (),
|
FnSpecialAccess::None => (),
|
||||||
FnSpecialAccess::Index(_) | FnSpecialAccess::Property(_) => {
|
FnSpecialAccess::Index(..) | FnSpecialAccess::Property(..) => {
|
||||||
let reg_name = fn_literal.value();
|
let reg_name = fn_literal.value();
|
||||||
if reg_name.starts_with(FN_GET)
|
if reg_name.starts_with(FN_GET)
|
||||||
|| reg_name.starts_with(FN_SET)
|
|| reg_name.starts_with(FN_SET)
|
||||||
@ -254,7 +254,7 @@ pub fn check_rename_collisions(fns: &[ExportedFn]) -> Result<(), syn::Error> {
|
|||||||
.arg_list()
|
.arg_list()
|
||||||
.fold(name.to_string(), |mut arg_str, fn_arg| {
|
.fold(name.to_string(), |mut arg_str, fn_arg| {
|
||||||
let type_string: String = match fn_arg {
|
let type_string: String = match fn_arg {
|
||||||
syn::FnArg::Receiver(_) => unimplemented!("receiver rhai_fns not implemented"),
|
syn::FnArg::Receiver(..) => unimplemented!("receiver rhai_fns not implemented"),
|
||||||
syn::FnArg::Typed(syn::PatType { ref ty, .. }) => print_type(ty),
|
syn::FnArg::Typed(syn::PatType { ref ty, .. }) => print_type(ty),
|
||||||
};
|
};
|
||||||
arg_str.push('.');
|
arg_str.push('.');
|
||||||
|
@ -226,7 +226,7 @@ impl Engine {
|
|||||||
|
|
||||||
match Token::lookup_from_syntax(keyword.as_ref()) {
|
match Token::lookup_from_syntax(keyword.as_ref()) {
|
||||||
// Standard identifiers, reserved keywords and custom keywords are OK
|
// Standard identifiers, reserved keywords and custom keywords are OK
|
||||||
None | Some(Token::Reserved(_)) | Some(Token::Custom(_)) => (),
|
None | Some(Token::Reserved(..)) | Some(Token::Custom(..)) => (),
|
||||||
// Active standard keywords cannot be made custom
|
// Active standard keywords cannot be made custom
|
||||||
// Disabled keywords are OK
|
// Disabled keywords are OK
|
||||||
Some(token) if token.is_standard_keyword() => {
|
Some(token) if token.is_standard_keyword() => {
|
||||||
|
@ -449,7 +449,7 @@ impl AST {
|
|||||||
/// foo("!")
|
/// foo("!")
|
||||||
/// "#)?;
|
/// "#)?;
|
||||||
///
|
///
|
||||||
/// // Merge 'ast2', picking only 'error()' but not 'foo(_)', into 'ast1'
|
/// // Merge 'ast2', picking only 'error()' but not 'foo(..)', into 'ast1'
|
||||||
/// let ast = ast1.merge_filtered(&ast2, |_, _, script, name, params|
|
/// let ast = ast1.merge_filtered(&ast2, |_, _, script, name, params|
|
||||||
/// script && name == "error" && params == 0);
|
/// script && name == "error" && params == 0);
|
||||||
///
|
///
|
||||||
@ -551,7 +551,7 @@ impl AST {
|
|||||||
/// foo("!")
|
/// foo("!")
|
||||||
/// "#)?;
|
/// "#)?;
|
||||||
///
|
///
|
||||||
/// // Combine 'ast2', picking only 'error()' but not 'foo(_)', into 'ast1'
|
/// // Combine 'ast2', picking only 'error()' but not 'foo(..)', into 'ast1'
|
||||||
/// ast1.combine_filtered(ast2, |_, _, script, name, params|
|
/// ast1.combine_filtered(ast2, |_, _, script, name, params|
|
||||||
/// script && name == "error" && params == 0);
|
/// script && name == "error" && params == 0);
|
||||||
///
|
///
|
||||||
@ -613,7 +613,7 @@ impl AST {
|
|||||||
/// fn bar() { print("hello"); }
|
/// fn bar() { print("hello"); }
|
||||||
/// "#)?;
|
/// "#)?;
|
||||||
///
|
///
|
||||||
/// // Remove all functions except 'foo(_)'
|
/// // Remove all functions except 'foo(..)'
|
||||||
/// ast.retain_functions(|_, _, name, params| name == "foo" && params == 1);
|
/// ast.retain_functions(|_, _, name, params| name == "foo" && params == 1);
|
||||||
/// # }
|
/// # }
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
|
@ -450,7 +450,7 @@ impl fmt::Debug for Expr {
|
|||||||
Self::FloatConstant(value, ..) => write!(f, "{:?}", value),
|
Self::FloatConstant(value, ..) => write!(f, "{:?}", value),
|
||||||
Self::CharConstant(value, ..) => write!(f, "{:?}", value),
|
Self::CharConstant(value, ..) => write!(f, "{:?}", value),
|
||||||
Self::StringConstant(value, ..) => write!(f, "{:?}", value),
|
Self::StringConstant(value, ..) => write!(f, "{:?}", value),
|
||||||
Self::Unit(_) => f.write_str("()"),
|
Self::Unit(..) => f.write_str("()"),
|
||||||
|
|
||||||
Self::InterpolatedString(x, ..) => {
|
Self::InterpolatedString(x, ..) => {
|
||||||
f.write_str("InterpolatedString")?;
|
f.write_str("InterpolatedString")?;
|
||||||
@ -535,7 +535,7 @@ impl Expr {
|
|||||||
Self::CharConstant(x, ..) => (*x).into(),
|
Self::CharConstant(x, ..) => (*x).into(),
|
||||||
Self::StringConstant(x, ..) => x.clone().into(),
|
Self::StringConstant(x, ..) => x.clone().into(),
|
||||||
Self::BoolConstant(x, ..) => (*x).into(),
|
Self::BoolConstant(x, ..) => (*x).into(),
|
||||||
Self::Unit(_) => Dynamic::UNIT,
|
Self::Unit(..) => Dynamic::UNIT,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
Self::Array(x, ..) if self.is_constant() => {
|
Self::Array(x, ..) if self.is_constant() => {
|
||||||
@ -772,7 +772,7 @@ impl Expr {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_unit(&self) -> bool {
|
pub const fn is_unit(&self) -> bool {
|
||||||
matches!(self, Self::Unit(_))
|
matches!(self, Self::Unit(..))
|
||||||
}
|
}
|
||||||
/// Is the expression a constant?
|
/// Is the expression a constant?
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -787,7 +787,7 @@ impl Expr {
|
|||||||
| Self::IntegerConstant(..)
|
| Self::IntegerConstant(..)
|
||||||
| Self::CharConstant(..)
|
| Self::CharConstant(..)
|
||||||
| Self::StringConstant(..)
|
| Self::StringConstant(..)
|
||||||
| Self::Unit(_)
|
| Self::Unit(..)
|
||||||
| Self::Stack(..) => true,
|
| Self::Stack(..) => true,
|
||||||
|
|
||||||
Self::InterpolatedString(x, ..) | Self::Array(x, ..) => x.iter().all(Self::is_constant),
|
Self::InterpolatedString(x, ..) | Self::Array(x, ..) => x.iter().all(Self::is_constant),
|
||||||
@ -816,13 +816,13 @@ impl Expr {
|
|||||||
| Self::CharConstant(..)
|
| Self::CharConstant(..)
|
||||||
| Self::And(..)
|
| Self::And(..)
|
||||||
| Self::Or(..)
|
| Self::Or(..)
|
||||||
| Self::Unit(_) => false,
|
| Self::Unit(..) => false,
|
||||||
|
|
||||||
Self::IntegerConstant(..)
|
Self::IntegerConstant(..)
|
||||||
| Self::StringConstant(..)
|
| Self::StringConstant(..)
|
||||||
| Self::InterpolatedString(..)
|
| Self::InterpolatedString(..)
|
||||||
| Self::FnCall(..)
|
| Self::FnCall(..)
|
||||||
| Self::Stmt(_)
|
| Self::Stmt(..)
|
||||||
| Self::Dot(..)
|
| Self::Dot(..)
|
||||||
| Self::Index(..)
|
| Self::Index(..)
|
||||||
| Self::Array(..)
|
| Self::Array(..)
|
||||||
|
@ -404,7 +404,7 @@ impl Stmt {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_noop(&self) -> bool {
|
pub const fn is_noop(&self) -> bool {
|
||||||
matches!(self, Self::Noop(_))
|
matches!(self, Self::Noop(..))
|
||||||
}
|
}
|
||||||
/// Get the [position][Position] of this statement.
|
/// Get the [position][Position] of this statement.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@ -432,7 +432,7 @@ impl Stmt {
|
|||||||
Self::Export(.., pos) => *pos,
|
Self::Export(.., pos) => *pos,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::Share(_) => Position::NONE,
|
Self::Share(..) => Position::NONE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Override the [position][Position] of this statement.
|
/// Override the [position][Position] of this statement.
|
||||||
@ -462,7 +462,7 @@ impl Stmt {
|
|||||||
Self::Export(.., pos) => *pos = new_pos,
|
Self::Export(.., pos) => *pos = new_pos,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::Share(_) => (),
|
Self::Share(..) => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -474,10 +474,10 @@ impl Stmt {
|
|||||||
Self::If(..)
|
Self::If(..)
|
||||||
| Self::Switch(..)
|
| Self::Switch(..)
|
||||||
| Self::Block(..)
|
| Self::Block(..)
|
||||||
| Self::Expr(_)
|
| Self::Expr(..)
|
||||||
| Self::FnCall(..) => true,
|
| Self::FnCall(..) => true,
|
||||||
|
|
||||||
Self::Noop(_) | Self::While(..) | Self::Do(..) | Self::For(..) | Self::TryCatch(..) => {
|
Self::Noop(..) | Self::While(..) | Self::Do(..) | Self::For(..) | Self::TryCatch(..) => {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +487,7 @@ impl Stmt {
|
|||||||
Self::Import(..) | Self::Export(..) => false,
|
Self::Import(..) | Self::Export(..) => false,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::Share(_) => false,
|
Self::Share(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this statement self-terminated (i.e. no need for a semicolon terminator)?
|
/// Is this statement self-terminated (i.e. no need for a semicolon terminator)?
|
||||||
@ -502,13 +502,13 @@ impl Stmt {
|
|||||||
| Self::TryCatch(..) => true,
|
| Self::TryCatch(..) => true,
|
||||||
|
|
||||||
// A No-op requires a semicolon in order to know it is an empty statement!
|
// A No-op requires a semicolon in order to know it is an empty statement!
|
||||||
Self::Noop(_) => false,
|
Self::Noop(..) => false,
|
||||||
|
|
||||||
Self::Expr(Expr::Custom(x, ..)) if x.is_self_terminated() => true,
|
Self::Expr(Expr::Custom(x, ..)) if x.is_self_terminated() => true,
|
||||||
|
|
||||||
Self::Var(..)
|
Self::Var(..)
|
||||||
| Self::Assignment(..)
|
| Self::Assignment(..)
|
||||||
| Self::Expr(_)
|
| Self::Expr(..)
|
||||||
| Self::FnCall(..)
|
| Self::FnCall(..)
|
||||||
| Self::Do(..)
|
| Self::Do(..)
|
||||||
| Self::BreakLoop(..)
|
| Self::BreakLoop(..)
|
||||||
@ -518,7 +518,7 @@ impl Stmt {
|
|||||||
Self::Import(..) | Self::Export(..) => false,
|
Self::Import(..) | Self::Export(..) => false,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::Share(_) => false,
|
Self::Share(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this statement _pure_?
|
/// Is this statement _pure_?
|
||||||
@ -527,7 +527,7 @@ impl Stmt {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_pure(&self) -> bool {
|
pub fn is_pure(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Noop(_) => true,
|
Self::Noop(..) => true,
|
||||||
Self::Expr(expr) => expr.is_pure(),
|
Self::Expr(expr) => expr.is_pure(),
|
||||||
Self::If(condition, x, ..) => {
|
Self::If(condition, x, ..) => {
|
||||||
condition.is_pure()
|
condition.is_pure()
|
||||||
@ -575,7 +575,7 @@ impl Stmt {
|
|||||||
Self::Export(..) => false,
|
Self::Export(..) => false,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::Share(_) => false,
|
Self::Share(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Does this statement's behavior depend on its containing block?
|
/// Does this statement's behavior depend on its containing block?
|
||||||
|
@ -724,7 +724,9 @@ impl Engine {
|
|||||||
|
|
||||||
match expr {
|
match expr {
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
Expr::FnCall(x, ..) if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => {
|
Expr::FnCall(x, ..)
|
||||||
|
if _parent_chain_type == ChainType::Dotting && !x.is_qualified() =>
|
||||||
|
{
|
||||||
let crate::ast::FnCallExpr {
|
let crate::ast::FnCallExpr {
|
||||||
args, constants, ..
|
args, constants, ..
|
||||||
} = x.as_ref();
|
} = x.as_ref();
|
||||||
|
@ -465,16 +465,16 @@ impl Engine {
|
|||||||
|
|
||||||
// Skip transitive nodes
|
// Skip transitive nodes
|
||||||
match node {
|
match node {
|
||||||
ASTNode::Expr(Expr::Stmt(_)) | ASTNode::Stmt(Stmt::Expr(_)) => return Ok(None),
|
ASTNode::Expr(Expr::Stmt(..)) | ASTNode::Stmt(Stmt::Expr(..)) => return Ok(None),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
let stop = match global.debugger.status {
|
let stop = match global.debugger.status {
|
||||||
DebuggerStatus::Next(false, false) => false,
|
DebuggerStatus::Next(false, false) => false,
|
||||||
DebuggerStatus::Next(true, false) => matches!(node, ASTNode::Stmt(_)),
|
DebuggerStatus::Next(true, false) => matches!(node, ASTNode::Stmt(..)),
|
||||||
DebuggerStatus::Next(false, true) => matches!(node, ASTNode::Expr(_)),
|
DebuggerStatus::Next(false, true) => matches!(node, ASTNode::Expr(..)),
|
||||||
DebuggerStatus::Next(true, true) => true,
|
DebuggerStatus::Next(true, true) => true,
|
||||||
DebuggerStatus::FunctionExit(_) => false,
|
DebuggerStatus::FunctionExit(..) => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = if stop {
|
let event = if stop {
|
||||||
|
@ -324,7 +324,7 @@ impl Engine {
|
|||||||
Expr::StringConstant(x, ..) => Ok(x.clone().into()),
|
Expr::StringConstant(x, ..) => Ok(x.clone().into()),
|
||||||
Expr::CharConstant(x, ..) => Ok((*x).into()),
|
Expr::CharConstant(x, ..) => Ok((*x).into()),
|
||||||
Expr::BoolConstant(x, ..) => Ok((*x).into()),
|
Expr::BoolConstant(x, ..) => Ok((*x).into()),
|
||||||
Expr::Unit(_) => Ok(Dynamic::UNIT),
|
Expr::Unit(..) => Ok(Dynamic::UNIT),
|
||||||
|
|
||||||
// `... ${...} ...`
|
// `... ${...} ...`
|
||||||
Expr::InterpolatedString(x, pos) => {
|
Expr::InterpolatedString(x, pos) => {
|
||||||
|
@ -323,7 +323,7 @@ impl Engine {
|
|||||||
|
|
||||||
let result = match stmt {
|
let result = match stmt {
|
||||||
// No-op
|
// No-op
|
||||||
Stmt::Noop(_) => Ok(Dynamic::UNIT),
|
Stmt::Noop(..) => Ok(Dynamic::UNIT),
|
||||||
|
|
||||||
// Expression as statement
|
// Expression as statement
|
||||||
Stmt::Expr(expr) => self
|
Stmt::Expr(expr) => self
|
||||||
@ -483,7 +483,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loop
|
// Loop
|
||||||
Stmt::While(Expr::Unit(_), body, ..) => loop {
|
Stmt::While(Expr::Unit(..), body, ..) => loop {
|
||||||
if !body.is_empty() {
|
if !body.is_empty() {
|
||||||
match self
|
match self
|
||||||
.eval_stmt_block(scope, global, state, lib, this_ptr, body, true, level)
|
.eval_stmt_block(scope, global, state, lib, this_ptr, body, true, level)
|
||||||
|
@ -144,10 +144,10 @@ impl<'a> Target<'a> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_ref(&self) -> bool {
|
pub const fn is_ref(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(_) => true,
|
Self::RefMut(..) => true,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::SharedValue { .. } => true,
|
Self::SharedValue { .. } => true,
|
||||||
Self::TempValue(_) => false,
|
Self::TempValue(..) => false,
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
Self::Bit { .. }
|
Self::Bit { .. }
|
||||||
| Self::BitField { .. }
|
| Self::BitField { .. }
|
||||||
@ -160,10 +160,10 @@ impl<'a> Target<'a> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_temp_value(&self) -> bool {
|
pub const fn is_temp_value(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(_) => false,
|
Self::RefMut(..) => false,
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::SharedValue { .. } => false,
|
Self::SharedValue { .. } => false,
|
||||||
Self::TempValue(_) => true,
|
Self::TempValue(..) => true,
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
Self::Bit { .. }
|
Self::Bit { .. }
|
||||||
| Self::BitField { .. }
|
| Self::BitField { .. }
|
||||||
@ -275,7 +275,7 @@ impl<'a> Target<'a> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn propagate_changed_value(&mut self) -> RhaiResultOf<()> {
|
pub fn propagate_changed_value(&mut self) -> RhaiResultOf<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::RefMut(_) | Self::TempValue(_) => (),
|
Self::RefMut(..) | Self::TempValue(..) => (),
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
Self::SharedValue { .. } => (),
|
Self::SharedValue { .. } => (),
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
@ -972,7 +972,7 @@ impl Engine {
|
|||||||
// Do not match function exit for arguments
|
// Do not match function exit for arguments
|
||||||
#[cfg(feature = "debugging")]
|
#[cfg(feature = "debugging")]
|
||||||
let reset_debugger = global.debugger.clear_status_if(|status| {
|
let reset_debugger = global.debugger.clear_status_if(|status| {
|
||||||
matches!(status, crate::eval::DebuggerStatus::FunctionExit(_))
|
matches!(status, crate::eval::DebuggerStatus::FunctionExit(..))
|
||||||
});
|
});
|
||||||
|
|
||||||
let result = self.eval_expr(scope, global, state, lib, this_ptr, arg_expr, level);
|
let result = self.eval_expr(scope, global, state, lib, this_ptr, arg_expr, level);
|
||||||
|
@ -30,10 +30,10 @@ pub enum CallableFunction {
|
|||||||
impl fmt::Debug for CallableFunction {
|
impl fmt::Debug for CallableFunction {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) => write!(f, "NativePureFunction"),
|
Self::Pure(..) => write!(f, "NativePureFunction"),
|
||||||
Self::Method(_) => write!(f, "NativeMethod"),
|
Self::Method(..) => write!(f, "NativeMethod"),
|
||||||
Self::Iterator(_) => write!(f, "NativeIterator"),
|
Self::Iterator(..) => write!(f, "NativeIterator"),
|
||||||
Self::Plugin(_) => write!(f, "PluginFunction"),
|
Self::Plugin(..) => write!(f, "PluginFunction"),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f),
|
Self::Script(fn_def) => fmt::Debug::fmt(fn_def, f),
|
||||||
@ -44,10 +44,10 @@ impl fmt::Debug for CallableFunction {
|
|||||||
impl fmt::Display for CallableFunction {
|
impl fmt::Display for CallableFunction {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) => write!(f, "NativePureFunction"),
|
Self::Pure(..) => write!(f, "NativePureFunction"),
|
||||||
Self::Method(_) => write!(f, "NativeMethod"),
|
Self::Method(..) => write!(f, "NativeMethod"),
|
||||||
Self::Iterator(_) => write!(f, "NativeIterator"),
|
Self::Iterator(..) => write!(f, "NativeIterator"),
|
||||||
Self::Plugin(_) => write!(f, "PluginFunction"),
|
Self::Plugin(..) => write!(f, "PluginFunction"),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(s) => fmt::Display::fmt(s, f),
|
Self::Script(s) => fmt::Display::fmt(s, f),
|
||||||
@ -61,13 +61,13 @@ impl CallableFunction {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_pure(&self) -> bool {
|
pub fn is_pure(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) => true,
|
Self::Pure(..) => true,
|
||||||
Self::Method(_) | Self::Iterator(_) => false,
|
Self::Method(..) | Self::Iterator(..) => false,
|
||||||
|
|
||||||
Self::Plugin(p) => !p.is_method_call(),
|
Self::Plugin(p) => !p.is_method_call(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => false,
|
Self::Script(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a native Rust method function?
|
/// Is this a native Rust method function?
|
||||||
@ -75,13 +75,13 @@ impl CallableFunction {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn is_method(&self) -> bool {
|
pub fn is_method(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Method(_) => true,
|
Self::Method(..) => true,
|
||||||
Self::Pure(_) | Self::Iterator(_) => false,
|
Self::Pure(..) | Self::Iterator(..) => false,
|
||||||
|
|
||||||
Self::Plugin(p) => p.is_method_call(),
|
Self::Plugin(p) => p.is_method_call(),
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => false,
|
Self::Script(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this an iterator function?
|
/// Is this an iterator function?
|
||||||
@ -89,11 +89,11 @@ impl CallableFunction {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_iter(&self) -> bool {
|
pub const fn is_iter(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Iterator(_) => true,
|
Self::Iterator(..) => true,
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Plugin(_) => false,
|
Self::Pure(..) | Self::Method(..) | Self::Plugin(..) => false,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => false,
|
Self::Script(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a script-defined function?
|
/// Is this a script-defined function?
|
||||||
@ -105,8 +105,8 @@ impl CallableFunction {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
match self {
|
match self {
|
||||||
Self::Script(_) => true,
|
Self::Script(..) => true,
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) | Self::Plugin(_) => false,
|
Self::Pure(..) | Self::Method(..) | Self::Iterator(..) | Self::Plugin(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a plugin function?
|
/// Is this a plugin function?
|
||||||
@ -114,11 +114,11 @@ impl CallableFunction {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_plugin_fn(&self) -> bool {
|
pub const fn is_plugin_fn(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Plugin(_) => true,
|
Self::Plugin(..) => true,
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => false,
|
Self::Pure(..) | Self::Method(..) | Self::Iterator(..) => false,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => false,
|
Self::Script(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this a native Rust function?
|
/// Is this a native Rust function?
|
||||||
@ -130,10 +130,10 @@ impl CallableFunction {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) | Self::Method(_) => true,
|
Self::Pure(..) | Self::Method(..) => true,
|
||||||
Self::Plugin(_) => true,
|
Self::Plugin(..) => true,
|
||||||
Self::Iterator(_) => true,
|
Self::Iterator(..) => true,
|
||||||
Self::Script(_) => false,
|
Self::Script(..) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the access mode.
|
/// Get the access mode.
|
||||||
@ -145,8 +145,8 @@ impl CallableFunction {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
match self {
|
match self {
|
||||||
Self::Plugin(_) => FnAccess::Public,
|
Self::Plugin(..) => FnAccess::Public,
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => FnAccess::Public,
|
Self::Pure(..) | Self::Method(..) | Self::Iterator(..) => FnAccess::Public,
|
||||||
Self::Script(f) => f.access,
|
Self::Script(f) => f.access,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,10 +156,10 @@ impl CallableFunction {
|
|||||||
pub fn get_native_fn(&self) -> Option<&Shared<FnAny>> {
|
pub fn get_native_fn(&self) -> Option<&Shared<FnAny>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(f) | Self::Method(f) => Some(f),
|
Self::Pure(f) | Self::Method(f) => Some(f),
|
||||||
Self::Iterator(_) | Self::Plugin(_) => None,
|
Self::Iterator(..) | Self::Plugin(..) => None,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => None,
|
Self::Script(..) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get a shared reference to a script-defined function definition.
|
/// Get a shared reference to a script-defined function definition.
|
||||||
@ -170,7 +170,7 @@ impl CallableFunction {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn get_script_fn_def(&self) -> Option<&Shared<crate::ast::ScriptFnDef>> {
|
pub const fn get_script_fn_def(&self) -> Option<&Shared<crate::ast::ScriptFnDef>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) | Self::Plugin(_) => None,
|
Self::Pure(..) | Self::Method(..) | Self::Iterator(..) | Self::Plugin(..) => None,
|
||||||
Self::Script(f) => Some(f),
|
Self::Script(f) => Some(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,10 +180,10 @@ impl CallableFunction {
|
|||||||
pub fn get_iter_fn(&self) -> Option<&IteratorFn> {
|
pub fn get_iter_fn(&self) -> Option<&IteratorFn> {
|
||||||
match self {
|
match self {
|
||||||
Self::Iterator(f) => Some(f.as_ref()),
|
Self::Iterator(f) => Some(f.as_ref()),
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Plugin(_) => None,
|
Self::Pure(..) | Self::Method(..) | Self::Plugin(..) => None,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => None,
|
Self::Script(..) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get a shared reference to a plugin function.
|
/// Get a shared reference to a plugin function.
|
||||||
@ -192,10 +192,10 @@ impl CallableFunction {
|
|||||||
pub fn get_plugin_fn(&self) -> Option<&Shared<FnPlugin>> {
|
pub fn get_plugin_fn(&self) -> Option<&Shared<FnPlugin>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Plugin(f) => Some(f),
|
Self::Plugin(f) => Some(f),
|
||||||
Self::Pure(_) | Self::Method(_) | Self::Iterator(_) => None,
|
Self::Pure(..) | Self::Method(..) | Self::Iterator(..) => None,
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
Self::Script(_) => None,
|
Self::Script(..) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Create a new [`CallableFunction::Pure`].
|
/// Create a new [`CallableFunction::Pure`].
|
||||||
|
@ -349,7 +349,7 @@ fn optimize_stmt_block(
|
|||||||
.map_or_else(|| Stmt::Noop(pos), |e| Stmt::Expr(mem::take(e)));
|
.map_or_else(|| Stmt::Noop(pos), |e| Stmt::Expr(mem::take(e)));
|
||||||
}
|
}
|
||||||
// { ...; stmt; noop } -> done
|
// { ...; stmt; noop } -> done
|
||||||
[.., ref second_last_stmt, Stmt::Noop(_)]
|
[.., ref second_last_stmt, Stmt::Noop(..)]
|
||||||
if second_last_stmt.returns_value() =>
|
if second_last_stmt.returns_value() =>
|
||||||
{
|
{
|
||||||
break
|
break
|
||||||
@ -636,7 +636,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b
|
|||||||
if let Some(mut condition) = mem::take(&mut block.condition) {
|
if let Some(mut condition) = mem::take(&mut block.condition) {
|
||||||
optimize_expr(&mut condition, state, false);
|
optimize_expr(&mut condition, state, false);
|
||||||
match condition {
|
match condition {
|
||||||
Expr::Unit(_) | Expr::BoolConstant(true, ..) => state.set_dirty(),
|
Expr::Unit(..) | Expr::BoolConstant(true, ..) => state.set_dirty(),
|
||||||
_ => block.condition = Some(condition),
|
_ => block.condition = Some(condition),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,7 +665,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b
|
|||||||
if let Some(mut condition) = mem::take(&mut block.condition) {
|
if let Some(mut condition) = mem::take(&mut block.condition) {
|
||||||
optimize_expr(&mut condition, state, false);
|
optimize_expr(&mut condition, state, false);
|
||||||
match condition {
|
match condition {
|
||||||
Expr::Unit(_) | Expr::BoolConstant(true, ..) => state.set_dirty(),
|
Expr::Unit(..) | Expr::BoolConstant(true, ..) => state.set_dirty(),
|
||||||
_ => block.condition = Some(condition),
|
_ => block.condition = Some(condition),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -941,8 +941,8 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) {
|
|||||||
while n < x.len() - 1 {
|
while n < x.len() - 1 {
|
||||||
match (mem::take(&mut x[n]), mem::take(&mut x[n+1])) {
|
match (mem::take(&mut x[n]), mem::take(&mut x[n+1])) {
|
||||||
(Expr::StringConstant(mut s1, pos), Expr::StringConstant(s2, ..)) => { s1 += s2; x[n] = Expr::StringConstant(s1, pos); x.remove(n+1); state.set_dirty(); }
|
(Expr::StringConstant(mut s1, pos), Expr::StringConstant(s2, ..)) => { s1 += s2; x[n] = Expr::StringConstant(s1, pos); x.remove(n+1); state.set_dirty(); }
|
||||||
(expr1, Expr::Unit(_)) => { x[n] = expr1; x.remove(n+1); state.set_dirty(); }
|
(expr1, Expr::Unit(..)) => { x[n] = expr1; x.remove(n+1); state.set_dirty(); }
|
||||||
(Expr::Unit(_), expr2) => { x[n+1] = expr2; x.remove(n); state.set_dirty(); }
|
(Expr::Unit(..), expr2) => { x[n+1] = expr2; x.remove(n); state.set_dirty(); }
|
||||||
(expr1, Expr::StringConstant(s, ..)) if s.is_empty() => { x[n] = expr1; x.remove(n+1); state.set_dirty(); }
|
(expr1, Expr::StringConstant(s, ..)) if s.is_empty() => { x[n] = expr1; x.remove(n+1); state.set_dirty(); }
|
||||||
(Expr::StringConstant(s, ..), expr2) if s.is_empty()=> { x[n+1] = expr2; x.remove(n); state.set_dirty(); }
|
(Expr::StringConstant(s, ..), expr2) if s.is_empty()=> { x[n+1] = expr2; x.remove(n); state.set_dirty(); }
|
||||||
(expr1, expr2) => { x[n] = expr1; x[n+1] = expr2; n += 1; }
|
(expr1, expr2) => { x[n] = expr1; x[n+1] = expr2; n += 1; }
|
||||||
|
@ -291,7 +291,7 @@ impl Expr {
|
|||||||
/// Raise an error if the expression can never yield a boolean value.
|
/// Raise an error if the expression can never yield a boolean value.
|
||||||
fn ensure_bool_expr(self) -> ParseResult<Expr> {
|
fn ensure_bool_expr(self) -> ParseResult<Expr> {
|
||||||
let type_name = match self {
|
let type_name = match self {
|
||||||
Expr::Unit(_) => "()",
|
Expr::Unit(..) => "()",
|
||||||
Expr::DynamicConstant(ref v, ..) if !v.is::<bool>() => v.type_name(),
|
Expr::DynamicConstant(ref v, ..) if !v.is::<bool>() => v.type_name(),
|
||||||
Expr::IntegerConstant(..) => "a number",
|
Expr::IntegerConstant(..) => "a number",
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
@ -312,7 +312,7 @@ impl Expr {
|
|||||||
/// Raise an error if the expression can never yield an iterable value.
|
/// Raise an error if the expression can never yield an iterable value.
|
||||||
fn ensure_iterable(self) -> ParseResult<Expr> {
|
fn ensure_iterable(self) -> ParseResult<Expr> {
|
||||||
let type_name = match self {
|
let type_name = match self {
|
||||||
Expr::Unit(_) => "()",
|
Expr::Unit(..) => "()",
|
||||||
Expr::BoolConstant(..) => "a boolean",
|
Expr::BoolConstant(..) => "a boolean",
|
||||||
Expr::IntegerConstant(..) => "a number",
|
Expr::IntegerConstant(..) => "a number",
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
@ -661,7 +661,7 @@ fn parse_index_chain(
|
|||||||
| Expr::And(..)
|
| Expr::And(..)
|
||||||
| Expr::Or(..)
|
| Expr::Or(..)
|
||||||
| Expr::BoolConstant(..)
|
| Expr::BoolConstant(..)
|
||||||
| Expr::Unit(_) => {
|
| Expr::Unit(..) => {
|
||||||
return Err(PERR::MalformedIndexExpr(
|
return Err(PERR::MalformedIndexExpr(
|
||||||
"Only arrays, object maps and strings can be indexed".into(),
|
"Only arrays, object maps and strings can be indexed".into(),
|
||||||
)
|
)
|
||||||
@ -694,7 +694,7 @@ fn parse_index_chain(
|
|||||||
| Expr::And(..)
|
| Expr::And(..)
|
||||||
| Expr::Or(..)
|
| Expr::Or(..)
|
||||||
| Expr::BoolConstant(..)
|
| Expr::BoolConstant(..)
|
||||||
| Expr::Unit(_) => {
|
| Expr::Unit(..) => {
|
||||||
return Err(PERR::MalformedIndexExpr(
|
return Err(PERR::MalformedIndexExpr(
|
||||||
"Only arrays, object maps and strings can be indexed".into(),
|
"Only arrays, object maps and strings can be indexed".into(),
|
||||||
)
|
)
|
||||||
@ -720,7 +720,7 @@ fn parse_index_chain(
|
|||||||
.into_err(x.start_position()))
|
.into_err(x.start_position()))
|
||||||
}
|
}
|
||||||
// lhs[()]
|
// lhs[()]
|
||||||
x @ Expr::Unit(_) => {
|
x @ Expr::Unit(..) => {
|
||||||
return Err(PERR::MalformedIndexExpr(
|
return Err(PERR::MalformedIndexExpr(
|
||||||
"Array access expects integer index, not ()".into(),
|
"Array access expects integer index, not ()".into(),
|
||||||
)
|
)
|
||||||
@ -897,7 +897,9 @@ fn parse_map_literal(
|
|||||||
}
|
}
|
||||||
(s, pos)
|
(s, pos)
|
||||||
}
|
}
|
||||||
(Token::InterpolatedString(_), pos) => return Err(PERR::PropertyExpected.into_err(pos)),
|
(Token::InterpolatedString(..), pos) => {
|
||||||
|
return Err(PERR::PropertyExpected.into_err(pos))
|
||||||
|
}
|
||||||
(Token::Reserved(s), pos) if is_valid_identifier(s.chars()) => {
|
(Token::Reserved(s), pos) if is_valid_identifier(s.chars()) => {
|
||||||
return Err(PERR::Reserved(s.to_string()).into_err(pos));
|
return Err(PERR::Reserved(s.to_string()).into_err(pos));
|
||||||
}
|
}
|
||||||
@ -951,7 +953,7 @@ fn parse_map_literal(
|
|||||||
eat_token(input, Token::Comma);
|
eat_token(input, Token::Comma);
|
||||||
}
|
}
|
||||||
(Token::RightBrace, ..) => (),
|
(Token::RightBrace, ..) => (),
|
||||||
(Token::Identifier(_), pos) => {
|
(Token::Identifier(..), pos) => {
|
||||||
return Err(PERR::MissingToken(
|
return Err(PERR::MissingToken(
|
||||||
Token::Comma.into(),
|
Token::Comma.into(),
|
||||||
"to separate the items of this object map literal".into(),
|
"to separate the items of this object map literal".into(),
|
||||||
@ -1147,7 +1149,7 @@ fn parse_switch(
|
|||||||
)
|
)
|
||||||
.into_err(*pos))
|
.into_err(*pos))
|
||||||
}
|
}
|
||||||
(..) => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1183,9 +1185,9 @@ fn parse_primary(
|
|||||||
let root_expr = match token {
|
let root_expr = match token {
|
||||||
Token::EOF => return Err(PERR::UnexpectedEOF.into_err(settings.pos)),
|
Token::EOF => return Err(PERR::UnexpectedEOF.into_err(settings.pos)),
|
||||||
|
|
||||||
Token::IntegerConstant(_)
|
Token::IntegerConstant(..)
|
||||||
| Token::CharConstant(_)
|
| Token::CharConstant(..)
|
||||||
| Token::StringConstant(_)
|
| Token::StringConstant(..)
|
||||||
| Token::True
|
| Token::True
|
||||||
| Token::False => match input.next().expect(NEVER_ENDS).0 {
|
| Token::False => match input.next().expect(NEVER_ENDS).0 {
|
||||||
Token::IntegerConstant(x) => Expr::IntegerConstant(x, settings.pos),
|
Token::IntegerConstant(x) => Expr::IntegerConstant(x, settings.pos),
|
||||||
@ -1284,7 +1286,7 @@ fn parse_primary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Interpolated string
|
// Interpolated string
|
||||||
Token::InterpolatedString(_) => {
|
Token::InterpolatedString(..) => {
|
||||||
let mut segments = StaticVec::<Expr>::new();
|
let mut segments = StaticVec::<Expr>::new();
|
||||||
|
|
||||||
match input.next().expect(NEVER_ENDS) {
|
match input.next().expect(NEVER_ENDS) {
|
||||||
@ -1352,7 +1354,7 @@ fn parse_primary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Identifier
|
// Identifier
|
||||||
Token::Identifier(_) => {
|
Token::Identifier(..) => {
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
let none = None;
|
let none = None;
|
||||||
#[cfg(feature = "no_module")]
|
#[cfg(feature = "no_module")]
|
||||||
@ -1416,7 +1418,7 @@ fn parse_primary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reserved keyword or symbol
|
// Reserved keyword or symbol
|
||||||
Token::Reserved(_) => {
|
Token::Reserved(..) => {
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
let none = None;
|
let none = None;
|
||||||
#[cfg(feature = "no_module")]
|
#[cfg(feature = "no_module")]
|
||||||
@ -1450,7 +1452,7 @@ fn parse_primary(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::LexError(_) => match input.next().expect(NEVER_ENDS) {
|
Token::LexError(..) => match input.next().expect(NEVER_ENDS) {
|
||||||
(Token::LexError(err), ..) => return Err(err.into_err(settings.pos)),
|
(Token::LexError(err), ..) => return Err(err.into_err(settings.pos)),
|
||||||
token => unreachable!("Token::LexError expected but gets {:?}", token),
|
token => unreachable!("Token::LexError expected but gets {:?}", token),
|
||||||
},
|
},
|
||||||
@ -1575,7 +1577,7 @@ fn parse_postfix(
|
|||||||
(expr, Token::Period) => {
|
(expr, Token::Period) => {
|
||||||
// Expression after dot must start with an identifier
|
// Expression after dot must start with an identifier
|
||||||
match input.peek().expect(NEVER_ENDS) {
|
match input.peek().expect(NEVER_ENDS) {
|
||||||
(Token::Identifier(_), ..) => {
|
(Token::Identifier(..), ..) => {
|
||||||
#[cfg(not(feature = "no_closure"))]
|
#[cfg(not(feature = "no_closure"))]
|
||||||
{
|
{
|
||||||
// Prevents capturing of the object properties as vars: xxx.<var>
|
// Prevents capturing of the object properties as vars: xxx.<var>
|
||||||
@ -2792,7 +2794,7 @@ fn parse_block(
|
|||||||
eat_token(input, Token::SemiColon);
|
eat_token(input, Token::SemiColon);
|
||||||
}
|
}
|
||||||
// { ... { stmt } ???
|
// { ... { stmt } ???
|
||||||
(..) if !need_semicolon => (),
|
_ if !need_semicolon => (),
|
||||||
// { ... stmt <error>
|
// { ... stmt <error>
|
||||||
(Token::LexError(err), err_pos) => return Err(err.clone().into_err(*err_pos)),
|
(Token::LexError(err), err_pos) => return Err(err.clone().into_err(*err_pos)),
|
||||||
// { ... stmt ???
|
// { ... stmt ???
|
||||||
@ -2874,7 +2876,7 @@ fn parse_stmt(
|
|||||||
|
|
||||||
match input.peek().expect(NEVER_ENDS) {
|
match input.peek().expect(NEVER_ENDS) {
|
||||||
(Token::Fn, ..) | (Token::Private, ..) => break,
|
(Token::Fn, ..) | (Token::Private, ..) => break,
|
||||||
(Token::Comment(_), ..) => (),
|
(Token::Comment(..), ..) => (),
|
||||||
_ => return Err(PERR::WrongDocComment.into_err(comments_pos)),
|
_ => return Err(PERR::WrongDocComment.into_err(comments_pos)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3027,7 +3029,7 @@ fn parse_stmt(
|
|||||||
// `return;` or `throw;`
|
// `return;` or `throw;`
|
||||||
(Token::SemiColon, ..) => Ok(Stmt::Return(return_type, None, token_pos)),
|
(Token::SemiColon, ..) => Ok(Stmt::Return(return_type, None, token_pos)),
|
||||||
// `return` or `throw` with expression
|
// `return` or `throw` with expression
|
||||||
(..) => {
|
_ => {
|
||||||
let expr = parse_expr(input, state, lib, settings.level_up())?;
|
let expr = parse_expr(input, state, lib, settings.level_up())?;
|
||||||
Ok(Stmt::Return(return_type, Some(expr), token_pos))
|
Ok(Stmt::Return(return_type, Some(expr), token_pos))
|
||||||
}
|
}
|
||||||
@ -3491,7 +3493,7 @@ impl Engine {
|
|||||||
// stmt ;
|
// stmt ;
|
||||||
(Token::SemiColon, ..) if !need_semicolon => (),
|
(Token::SemiColon, ..) if !need_semicolon => (),
|
||||||
// { stmt } ???
|
// { stmt } ???
|
||||||
(..) if !need_semicolon => (),
|
_ if !need_semicolon => (),
|
||||||
// stmt <error>
|
// stmt <error>
|
||||||
(Token::LexError(err), pos) => return Err(err.clone().into_err(*pos)),
|
(Token::LexError(err), pos) => return Err(err.clone().into_err(*pos)),
|
||||||
// stmt ???
|
// stmt ???
|
||||||
|
@ -603,8 +603,8 @@ impl Token {
|
|||||||
FloatConstant(f) => f.to_string().into(),
|
FloatConstant(f) => f.to_string().into(),
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
DecimalConstant(d) => d.to_string().into(),
|
DecimalConstant(d) => d.to_string().into(),
|
||||||
StringConstant(_) => "string".into(),
|
StringConstant(..) => "string".into(),
|
||||||
InterpolatedString(_) => "string".into(),
|
InterpolatedString(..) => "string".into(),
|
||||||
CharConstant(c) => c.to_string().into(),
|
CharConstant(c) => c.to_string().into(),
|
||||||
Identifier(s) => s.to_string().into(),
|
Identifier(s) => s.to_string().into(),
|
||||||
Reserved(s) => s.to_string().into(),
|
Reserved(s) => s.to_string().into(),
|
||||||
@ -825,7 +825,7 @@ impl Token {
|
|||||||
use Token::*;
|
use Token::*;
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
LexError(_) |
|
LexError(..) |
|
||||||
SemiColon | // ; - is unary
|
SemiColon | // ; - is unary
|
||||||
Colon | // #{ foo: - is unary
|
Colon | // #{ foo: - is unary
|
||||||
Comma | // ( ... , -expr ) - is unary
|
Comma | // ( ... , -expr ) - is unary
|
||||||
@ -970,7 +970,7 @@ impl Token {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_reserved(&self) -> bool {
|
pub const fn is_reserved(&self) -> bool {
|
||||||
matches!(self, Self::Reserved(_))
|
matches!(self, Self::Reserved(..))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a token into a function name, if possible.
|
/// Convert a token into a function name, if possible.
|
||||||
@ -987,7 +987,7 @@ impl Token {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_custom(&self) -> bool {
|
pub const fn is_custom(&self) -> bool {
|
||||||
matches!(self, Self::Custom(_))
|
matches!(self, Self::Custom(..))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2197,7 +2197,7 @@ impl<'a> Iterator for TokenIterator<'a> {
|
|||||||
// a verbatim string or a string with continuation encounters {EOF}.
|
// a verbatim string or a string with continuation encounters {EOF}.
|
||||||
// This is necessary to handle such cases for line-by-line parsing, but for an entire
|
// This is necessary to handle such cases for line-by-line parsing, but for an entire
|
||||||
// script it is a syntax error.
|
// script it is a syntax error.
|
||||||
Some((Token::StringConstant(_), pos)) if self.state.is_within_text_terminated_by.is_some() => {
|
Some((Token::StringConstant(..), pos)) if self.state.is_within_text_terminated_by.is_some() => {
|
||||||
self.state.is_within_text_terminated_by = None;
|
self.state.is_within_text_terminated_by = None;
|
||||||
return Some((Token::LexError(LERR::UnterminatedString), pos));
|
return Some((Token::LexError(LERR::UnterminatedString), pos));
|
||||||
}
|
}
|
||||||
|
@ -153,11 +153,11 @@ impl fmt::Display for EvalAltResult {
|
|||||||
s => f.write_str(s),
|
s => f.write_str(s),
|
||||||
}?,
|
}?,
|
||||||
Self::ErrorIndexingType(s, ..) => write!(f, "Indexer not registered: {}", s)?,
|
Self::ErrorIndexingType(s, ..) => write!(f, "Indexer not registered: {}", s)?,
|
||||||
Self::ErrorUnboundThis(_) => f.write_str("'this' is not bound")?,
|
Self::ErrorUnboundThis(..) => f.write_str("'this' is not bound")?,
|
||||||
Self::ErrorFor(_) => f.write_str("For loop expects a type that is iterable")?,
|
Self::ErrorFor(..) => f.write_str("For loop expects a type that is iterable")?,
|
||||||
Self::ErrorTooManyOperations(_) => f.write_str("Too many operations")?,
|
Self::ErrorTooManyOperations(..) => f.write_str("Too many operations")?,
|
||||||
Self::ErrorTooManyModules(_) => f.write_str("Too many modules imported")?,
|
Self::ErrorTooManyModules(..) => f.write_str("Too many modules imported")?,
|
||||||
Self::ErrorStackOverflow(_) => f.write_str("Stack overflow")?,
|
Self::ErrorStackOverflow(..) => f.write_str("Stack overflow")?,
|
||||||
Self::ErrorTerminated(..) => f.write_str("Script terminated")?,
|
Self::ErrorTerminated(..) => f.write_str("Script terminated")?,
|
||||||
|
|
||||||
Self::ErrorRuntime(d, ..) if d.is::<()>() => f.write_str("Runtime error")?,
|
Self::ErrorRuntime(d, ..) if d.is::<()>() => f.write_str("Runtime error")?,
|
||||||
@ -270,13 +270,13 @@ impl EvalAltResult {
|
|||||||
Self::ErrorFunctionNotFound(..)
|
Self::ErrorFunctionNotFound(..)
|
||||||
| Self::ErrorInFunctionCall(..)
|
| Self::ErrorInFunctionCall(..)
|
||||||
| Self::ErrorInModule(..)
|
| Self::ErrorInModule(..)
|
||||||
| Self::ErrorUnboundThis(_)
|
| Self::ErrorUnboundThis(..)
|
||||||
| Self::ErrorMismatchDataType(..)
|
| Self::ErrorMismatchDataType(..)
|
||||||
| Self::ErrorArrayBounds(..)
|
| Self::ErrorArrayBounds(..)
|
||||||
| Self::ErrorStringBounds(..)
|
| Self::ErrorStringBounds(..)
|
||||||
| Self::ErrorBitFieldBounds(..)
|
| Self::ErrorBitFieldBounds(..)
|
||||||
| Self::ErrorIndexingType(..)
|
| Self::ErrorIndexingType(..)
|
||||||
| Self::ErrorFor(_)
|
| Self::ErrorFor(..)
|
||||||
| Self::ErrorVariableExists(..)
|
| Self::ErrorVariableExists(..)
|
||||||
| Self::ErrorVariableNotFound(..)
|
| Self::ErrorVariableNotFound(..)
|
||||||
| Self::ErrorModuleNotFound(..)
|
| Self::ErrorModuleNotFound(..)
|
||||||
@ -293,9 +293,9 @@ impl EvalAltResult {
|
|||||||
// Therefore, this error should not be catchable.
|
// Therefore, this error should not be catchable.
|
||||||
Self::ErrorCustomSyntax(..) => false,
|
Self::ErrorCustomSyntax(..) => false,
|
||||||
|
|
||||||
Self::ErrorTooManyOperations(_)
|
Self::ErrorTooManyOperations(..)
|
||||||
| Self::ErrorTooManyModules(_)
|
| Self::ErrorTooManyModules(..)
|
||||||
| Self::ErrorStackOverflow(_)
|
| Self::ErrorStackOverflow(..)
|
||||||
| Self::ErrorDataTooLarge(..)
|
| Self::ErrorDataTooLarge(..)
|
||||||
| Self::ErrorTerminated(..) => false,
|
| Self::ErrorTerminated(..) => false,
|
||||||
|
|
||||||
@ -310,9 +310,9 @@ impl EvalAltResult {
|
|||||||
Self::ErrorParsing(..) => true,
|
Self::ErrorParsing(..) => true,
|
||||||
|
|
||||||
Self::ErrorCustomSyntax(..)
|
Self::ErrorCustomSyntax(..)
|
||||||
| Self::ErrorTooManyOperations(_)
|
| Self::ErrorTooManyOperations(..)
|
||||||
| Self::ErrorTooManyModules(_)
|
| Self::ErrorTooManyModules(..)
|
||||||
| Self::ErrorStackOverflow(_)
|
| Self::ErrorStackOverflow(..)
|
||||||
| Self::ErrorDataTooLarge(..) => true,
|
| Self::ErrorDataTooLarge(..) => true,
|
||||||
|
|
||||||
Self::ErrorTerminated(..) => true,
|
Self::ErrorTerminated(..) => true,
|
||||||
@ -337,12 +337,12 @@ impl EvalAltResult {
|
|||||||
|
|
||||||
Self::ErrorSystem(..)
|
Self::ErrorSystem(..)
|
||||||
| Self::ErrorParsing(..)
|
| Self::ErrorParsing(..)
|
||||||
| Self::ErrorUnboundThis(_)
|
| Self::ErrorUnboundThis(..)
|
||||||
| Self::ErrorFor(_)
|
| Self::ErrorFor(..)
|
||||||
| Self::ErrorArithmetic(..)
|
| Self::ErrorArithmetic(..)
|
||||||
| Self::ErrorTooManyOperations(_)
|
| Self::ErrorTooManyOperations(..)
|
||||||
| Self::ErrorTooManyModules(_)
|
| Self::ErrorTooManyModules(..)
|
||||||
| Self::ErrorStackOverflow(_)
|
| Self::ErrorStackOverflow(..)
|
||||||
| Self::ErrorRuntime(..) => (),
|
| Self::ErrorRuntime(..) => (),
|
||||||
|
|
||||||
Self::ErrorFunctionNotFound(f, ..) => {
|
Self::ErrorFunctionNotFound(f, ..) => {
|
||||||
|
@ -48,7 +48,7 @@ fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
|||||||
.compile_expression("let f = |x| {};")
|
.compile_expression("let f = |x| {};")
|
||||||
.expect_err("should error")
|
.expect_err("should error")
|
||||||
.0,
|
.0,
|
||||||
ParseErrorType::BadInput(_)
|
ParseErrorType::BadInput(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -74,7 +74,7 @@ fn test_fn_ptr() -> Result<(), Box<EvalAltResult>> {
|
|||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorInFunctionCall(fn_name, _, err, ..)
|
EvalAltResult::ErrorInFunctionCall(fn_name, _, err, ..)
|
||||||
if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(_))
|
if fn_name == "foo" && matches!(*err, EvalAltResult::ErrorUnboundThis(..))
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -249,7 +249,7 @@ fn test_internal_fn_bang() -> Result<(), Box<EvalAltResult>> {
|
|||||||
)
|
)
|
||||||
.expect_err("should error")
|
.expect_err("should error")
|
||||||
.0,
|
.0,
|
||||||
ParseErrorType::MalformedCapture(_)
|
ParseErrorType::MalformedCapture(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -214,7 +214,7 @@ fn test_module_resolver() -> Result<(), Box<EvalAltResult>> {
|
|||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorTooManyModules(_)
|
EvalAltResult::ErrorTooManyModules(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
|
@ -19,7 +19,7 @@ fn test_max_operations() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
*engine.run("for x in 0..500 {}").expect_err("should error"),
|
*engine.run("for x in 0..500 {}").expect_err("should error"),
|
||||||
EvalAltResult::ErrorTooManyOperations(_)
|
EvalAltResult::ErrorTooManyOperations(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
engine.set_max_operations(0);
|
engine.set_max_operations(0);
|
||||||
@ -44,7 +44,7 @@ fn test_max_operations_literal() -> Result<(), Box<EvalAltResult>> {
|
|||||||
*engine
|
*engine
|
||||||
.run("[1, 2, 3, 4, 5, 6, 7, 8, 9]")
|
.run("[1, 2, 3, 4, 5, 6, 7, 8, 9]")
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorTooManyOperations(_)
|
EvalAltResult::ErrorTooManyOperations(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
@ -55,7 +55,7 @@ fn test_max_operations_literal() -> Result<(), Box<EvalAltResult>> {
|
|||||||
*engine
|
*engine
|
||||||
.run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9}")
|
.run("#{a:1, b:2, c:3, d:4, e:5, f:6, g:7, h:8, i:9}")
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorTooManyOperations(_)
|
EvalAltResult::ErrorTooManyOperations(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -111,7 +111,7 @@ fn test_max_operations_functions() -> Result<(), Box<EvalAltResult>> {
|
|||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorTooManyOperations(_)
|
EvalAltResult::ErrorTooManyOperations(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -138,7 +138,7 @@ fn test_max_operations_eval() -> Result<(), Box<EvalAltResult>> {
|
|||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(_))
|
EvalAltResult::ErrorInFunctionCall(.., err, _) if matches!(*err, EvalAltResult::ErrorTooManyOperations(..))
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -29,7 +29,7 @@ fn test_stack_overflow_fn_calls() -> Result<(), Box<EvalAltResult>> {
|
|||||||
max + 1
|
max + 1
|
||||||
))
|
))
|
||||||
.expect_err("should error"),
|
.expect_err("should error"),
|
||||||
EvalAltResult::ErrorStackOverflow(_)
|
EvalAltResult::ErrorStackOverflow(..)
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user