Add allow_shadowing.

This commit is contained in:
Stephen Chung
2022-02-04 13:20:47 +08:00
parent 6c1c8bc538
commit 3be27746e0
7 changed files with 65 additions and 14 deletions

View File

@@ -17,9 +17,11 @@ pub struct LanguageOptions {
#[cfg(not(feature = "no_function"))]
pub allow_anonymous_fn: bool,
/// Is looping allowed?
pub allow_loop: bool,
pub allow_looping: bool,
/// Strict variables mode?
pub strict_var: bool,
/// Is variables shadowing allowed?
pub allow_shadowing: bool,
}
impl LanguageOptions {
@@ -32,8 +34,9 @@ impl LanguageOptions {
allow_stmt_expr: true,
#[cfg(not(feature = "no_function"))]
allow_anonymous_fn: true,
allow_loop: true,
allow_looping: true,
strict_var: false,
allow_shadowing: true,
}
}
}
@@ -94,12 +97,12 @@ impl Engine {
/// Is looping allowed?
#[inline(always)]
pub fn allow_looping(&self) -> bool {
self.options.allow_loop
self.options.allow_looping
}
/// Set whether looping is allowed.
#[inline(always)]
pub fn set_allow_looping(&mut self, enable: bool) {
self.options.allow_loop = enable;
self.options.allow_looping = enable;
}
/// Is strict variables mode enabled?
#[inline(always)]
@@ -111,4 +114,14 @@ impl Engine {
pub fn set_strict_variables(&mut self, enable: bool) {
self.options.strict_var = enable;
}
/// Is variables shadowing allowed?
#[inline(always)]
pub fn allow_shadowing(&self) -> bool {
self.options.allow_shadowing
}
/// Set whether variables shadowing is allowed.
#[inline(always)]
pub fn set_allow_shadowing(&mut self, enable: bool) {
self.options.allow_shadowing = enable;
}
}