Rename scope_changed to scope_may_be_changed.
This commit is contained in:
parent
b4da054bab
commit
ab21ba703f
@ -1394,7 +1394,7 @@ pub struct CustomExpr {
|
|||||||
/// List of keywords.
|
/// List of keywords.
|
||||||
pub keywords: StaticVec<Expr>,
|
pub keywords: StaticVec<Expr>,
|
||||||
/// Is the current [`Scope`][crate::Scope] modified?
|
/// Is the current [`Scope`][crate::Scope] modified?
|
||||||
pub scope_changed: bool,
|
pub scope_may_be_changed: bool,
|
||||||
/// List of tokens actually parsed.
|
/// List of tokens actually parsed.
|
||||||
pub tokens: StaticVec<Identifier>,
|
pub tokens: StaticVec<Identifier>,
|
||||||
}
|
}
|
||||||
|
@ -156,19 +156,19 @@ pub struct CustomSyntax {
|
|||||||
/// Custom syntax implementation function.
|
/// Custom syntax implementation function.
|
||||||
pub func: Shared<FnCustomSyntaxEval>,
|
pub func: Shared<FnCustomSyntaxEval>,
|
||||||
/// Any variables added/removed in the scope?
|
/// Any variables added/removed in the scope?
|
||||||
pub scope_changed: bool,
|
pub scope_may_be_changed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
/// Register a custom syntax with the [`Engine`].
|
/// Register a custom syntax with the [`Engine`].
|
||||||
///
|
///
|
||||||
/// * `keywords` holds a slice of strings that define the custom syntax.
|
/// * `keywords` holds a slice of strings that define the custom syntax.
|
||||||
/// * `scope_changed` specifies variables have been added/removed by this custom syntax.
|
/// * `scope_may_be_changed` specifies variables have been added/removed by this custom syntax.
|
||||||
/// * `func` is the implementation function.
|
/// * `func` is the implementation function.
|
||||||
///
|
///
|
||||||
/// # Caveat - Do not change beyond block scope
|
/// # Caveat - Do not change beyond block scope
|
||||||
///
|
///
|
||||||
/// If `scope_changed` is `true`, then the current [`Scope`][crate::Scope] is assumed to be
|
/// If `scope_may_be_changed` is `true`, then the current [`Scope`][crate::Scope] is assumed to be
|
||||||
/// modified by this custom syntax.
|
/// modified by this custom syntax.
|
||||||
///
|
///
|
||||||
/// Adding new variables and/or removing variables are allowed. Simply modifying the values of
|
/// Adding new variables and/or removing variables are allowed. Simply modifying the values of
|
||||||
@ -182,7 +182,7 @@ impl Engine {
|
|||||||
pub fn register_custom_syntax<S: AsRef<str> + Into<Identifier>>(
|
pub fn register_custom_syntax<S: AsRef<str> + Into<Identifier>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
keywords: &[S],
|
keywords: &[S],
|
||||||
scope_changed: bool,
|
scope_may_be_changed: bool,
|
||||||
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
|
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
|
||||||
) -> Result<&mut Self, ParseError> {
|
) -> Result<&mut Self, ParseError> {
|
||||||
let keywords = keywords.as_ref();
|
let keywords = keywords.as_ref();
|
||||||
@ -289,7 +289,7 @@ impl Engine {
|
|||||||
Ok(Some(segments[stream.len()].clone()))
|
Ok(Some(segments[stream.len()].clone()))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
scope_changed,
|
scope_may_be_changed,
|
||||||
func,
|
func,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ impl Engine {
|
|||||||
///
|
///
|
||||||
/// This function is very low level.
|
/// This function is very low level.
|
||||||
///
|
///
|
||||||
/// * `scope_changed` specifies variables have been added/removed by this custom syntax.
|
/// * `scope_may_be_changed` specifies variables have been added/removed by this custom syntax.
|
||||||
/// * `parse` is the parsing function.
|
/// * `parse` is the parsing function.
|
||||||
/// * `func` is the implementation function.
|
/// * `func` is the implementation function.
|
||||||
///
|
///
|
||||||
@ -313,7 +313,7 @@ impl Engine {
|
|||||||
parse: impl Fn(&[ImmutableString], &str) -> Result<Option<ImmutableString>, ParseError>
|
parse: impl Fn(&[ImmutableString], &str) -> Result<Option<ImmutableString>, ParseError>
|
||||||
+ SendSync
|
+ SendSync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
scope_changed: bool,
|
scope_may_be_changed: bool,
|
||||||
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
|
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.custom_syntax.insert(
|
self.custom_syntax.insert(
|
||||||
@ -321,7 +321,7 @@ impl Engine {
|
|||||||
CustomSyntax {
|
CustomSyntax {
|
||||||
parse: Box::new(parse),
|
parse: Box::new(parse),
|
||||||
func: (Box::new(func) as Box<FnCustomSyntaxEval>).into(),
|
func: (Box::new(func) as Box<FnCustomSyntaxEval>).into(),
|
||||||
scope_changed,
|
scope_may_be_changed,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
@ -1051,7 +1051,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut State, _chaining: bool) {
|
|||||||
|
|
||||||
// Custom syntax
|
// Custom syntax
|
||||||
Expr::Custom(x, _) => {
|
Expr::Custom(x, _) => {
|
||||||
if x.scope_changed {
|
if x.scope_may_be_changed {
|
||||||
state.propagate_constants = false;
|
state.propagate_constants = false;
|
||||||
}
|
}
|
||||||
x.keywords.iter_mut().for_each(|expr| optimize_expr(expr, state, false));
|
x.keywords.iter_mut().for_each(|expr| optimize_expr(expr, state, false));
|
||||||
|
Loading…
Reference in New Issue
Block a user