Reduce size of Engine.
This commit is contained in:
@@ -35,6 +35,7 @@ pub mod definitions;
|
||||
|
||||
use crate::{Dynamic, Engine, Identifier};
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
||||
@@ -107,7 +108,9 @@ impl Engine {
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
pub fn disable_symbol(&mut self, symbol: impl Into<Identifier>) -> &mut Self {
|
||||
self.disabled_symbols.insert(symbol.into());
|
||||
self.disabled_symbols
|
||||
.get_or_insert_with(|| BTreeSet::new().into())
|
||||
.insert(symbol.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -163,18 +166,31 @@ impl Engine {
|
||||
// Active standard keywords cannot be made custom
|
||||
// Disabled keywords are OK
|
||||
Some(token) if token.is_standard_keyword() => {
|
||||
if !self.disabled_symbols.contains(token.literal_syntax()) {
|
||||
if !self
|
||||
.disabled_symbols
|
||||
.as_ref()
|
||||
.map_or(false, |m| m.contains(token.literal_syntax()))
|
||||
{
|
||||
return Err(format!("'{keyword}' is a reserved keyword"));
|
||||
}
|
||||
}
|
||||
// Active standard symbols cannot be made custom
|
||||
Some(token) if token.is_standard_symbol() => {
|
||||
if !self.disabled_symbols.contains(token.literal_syntax()) {
|
||||
if !self
|
||||
.disabled_symbols
|
||||
.as_ref()
|
||||
.map_or(false, |m| m.contains(token.literal_syntax()))
|
||||
{
|
||||
return Err(format!("'{keyword}' is a reserved operator"));
|
||||
}
|
||||
}
|
||||
// Active standard symbols cannot be made custom
|
||||
Some(token) if !self.disabled_symbols.contains(token.literal_syntax()) => {
|
||||
Some(token)
|
||||
if !self
|
||||
.disabled_symbols
|
||||
.as_ref()
|
||||
.map_or(false, |m| m.contains(token.literal_syntax())) =>
|
||||
{
|
||||
return Err(format!("'{keyword}' is a reserved symbol"))
|
||||
}
|
||||
// Disabled symbols are OK
|
||||
@@ -183,6 +199,7 @@ impl Engine {
|
||||
|
||||
// Add to custom keywords
|
||||
self.custom_keywords
|
||||
.get_or_insert_with(|| std::collections::BTreeMap::new().into())
|
||||
.insert(keyword.into(), Some(precedence));
|
||||
|
||||
Ok(self)
|
||||
|
Reference in New Issue
Block a user