diff --git a/src/parse.rs b/src/parse.rs index da378114..a776deee 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -11,7 +11,8 @@ use crate::fn_hash::get_hasher; use crate::module::NamespaceRef; use crate::optimize::{optimize_into_ast, OptimizationLevel}; use crate::token::{ - is_keyword_function, is_valid_identifier, Token, TokenStream, TokenizerControl, + is_keyword_function, is_valid_function_name, is_valid_identifier, Token, TokenStream, + TokenizerControl, }; use crate::{ calc_fn_hash, calc_qualified_fn_hash, calc_qualified_var_hash, Engine, Identifier, @@ -478,7 +479,7 @@ fn parse_fn_call( }, ); - let hashes = if is_valid_identifier(id.chars()) { + let hashes = if is_valid_function_name(&id) { FnCallHashes::from_script(hash) } else { FnCallHashes::from_native(hash) @@ -528,7 +529,7 @@ fn parse_fn_call( }, ); - let hashes = if is_valid_identifier(id.chars()) { + let hashes = if is_valid_function_name(&id) { FnCallHashes::from_script(hash) } else { FnCallHashes::from_native(hash) @@ -1949,7 +1950,7 @@ fn parse_binary_op( let hash = calc_fn_hash(&s, 2); FnCallExpr { - hashes: if is_valid_identifier(s.chars()) { + hashes: if is_valid_function_name(&s) { FnCallHashes::from_script(hash) } else { FnCallHashes::from_native(hash) diff --git a/src/token.rs b/src/token.rs index c52a3eb2..e1ff0045 100644 --- a/src/token.rs +++ b/src/token.rs @@ -960,7 +960,7 @@ impl Token { #[inline] pub(crate) fn into_function_name_for_override(self) -> Result { match self { - Self::Custom(s) | Self::Identifier(s) if is_valid_identifier(s.chars()) => Ok(s), + Self::Custom(s) | Self::Identifier(s) if is_valid_function_name(&s) => Ok(s), _ => Err(self), } } @@ -2015,6 +2015,13 @@ pub fn is_valid_identifier(name: impl Iterator) -> bool { first_alphabetic } +/// Is a text string a valid scripted function name? +#[inline(always)] +#[must_use] +pub fn is_valid_function_name(name: &str) -> bool { + is_valid_identifier(name.chars()) +} + /// Is a character valid to start an identifier? #[cfg(feature = "unicode-xid-ident")] #[inline(always)]