Extract Identifier type.

This commit is contained in:
Stephen Chung
2021-03-29 11:36:02 +08:00
parent 241f5abe10
commit e5249cc1ae
16 changed files with 170 additions and 133 deletions

View File

@@ -12,7 +12,7 @@ use crate::stdlib::{
string::String,
};
use crate::{
scope::Scope, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, Module,
scope::Scope, Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, Identifier, Module,
NativeCallContext, ParseError, Position, RhaiResult, Shared, AST,
};
@@ -53,7 +53,7 @@ impl Engine {
#[inline]
pub fn register_fn<N, A, F>(&mut self, name: N, func: F) -> &mut Self
where
N: AsRef<str> + Into<ImmutableString>,
N: AsRef<str> + Into<Identifier>,
F: RegisterNativeFunction<A, ()>,
{
let param_types = F::param_types();
@@ -113,7 +113,7 @@ impl Engine {
#[inline]
pub fn register_result_fn<N, A, F, R>(&mut self, name: N, func: F) -> &mut Self
where
N: AsRef<str> + Into<ImmutableString>,
N: AsRef<str> + Into<Identifier>,
F: RegisterNativeFunction<A, Result<R, Box<EvalAltResult>>>,
{
let param_types = F::param_types();
@@ -170,7 +170,7 @@ impl Engine {
+ 'static,
) -> &mut Self
where
N: AsRef<str> + Into<ImmutableString>,
N: AsRef<str> + Into<Identifier>,
T: Variant + Clone,
{
self.global_namespace.set_raw_fn(
@@ -901,12 +901,12 @@ impl Engine {
#[cfg(not(feature = "no_module"))]
pub fn register_static_module(
&mut self,
name: impl AsRef<str> + Into<ImmutableString>,
name: impl AsRef<str> + Into<Identifier>,
module: Shared<Module>,
) -> &mut Self {
fn register_static_module_raw(
root: &mut crate::stdlib::collections::BTreeMap<crate::ImmutableString, Shared<Module>>,
name: impl AsRef<str> + Into<ImmutableString>,
root: &mut crate::stdlib::collections::BTreeMap<Identifier, Shared<Module>>,
name: impl AsRef<str> + Into<Identifier>,
module: Shared<Module>,
) {
let separator = crate::token::Token::DoubleColon.syntax();
@@ -952,7 +952,7 @@ impl Engine {
#[deprecated(since = "0.19.9", note = "use `register_static_module` instead")]
pub fn register_module(
&mut self,
name: impl AsRef<str> + Into<ImmutableString>,
name: impl AsRef<str> + Into<Identifier>,
module: impl Into<Shared<Module>>,
) -> &mut Self {
self.register_static_module(name, module.into())
@@ -1045,14 +1045,14 @@ impl Engine {
fn collect_imports(
ast: &AST,
resolver: &StaticModuleResolver,
imports: &mut BTreeSet<ImmutableString>,
imports: &mut BTreeSet<Identifier>,
) {
ast.walk(&mut |path| match path.last().unwrap() {
// Collect all `import` statements with a string constant path
ASTNode::Stmt(Stmt::Import(Expr::StringConstant(s, _), _, _))
if !resolver.contains_path(s) && !imports.contains(s) =>
if !resolver.contains_path(s) && !imports.contains(s.as_str()) =>
{
imports.insert(s.clone());
imports.insert(s.clone().into());
true
}
_ => true,