From 0fbc437916981959688095e5b9ebf720b592734e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 11 Nov 2021 13:55:52 +0800 Subject: [PATCH] Use Box internally. --- src/ast.rs | 4 +-- src/engine_api.rs | 10 +++--- src/engine_settings.rs | 6 ++-- src/fn_ptr.rs | 10 ++++++ src/immutable_string.rs | 7 ++++ src/module/mod.rs | 4 +-- src/parse.rs | 78 ++++++++++++++++++++++------------------- src/serde/metadata.rs | 28 +++++++-------- src/token.rs | 71 +++++++++++++++++++------------------ 9 files changed, 121 insertions(+), 97 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 94281968..9a56ef87 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -77,7 +77,7 @@ pub struct ScriptFnDef { /// Not available under `no_function`. #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - pub comments: StaticVec, + pub comments: StaticVec>, } impl fmt::Display for ScriptFnDef { @@ -156,7 +156,7 @@ impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> { Self { #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments: value.comments.iter().map(|s| s.as_str()).collect(), + comments: value.comments.iter().map(Box::as_ref).collect(), access: value.access, name: &value.name, params: value.params.iter().map(|s| s.as_str()).collect(), diff --git a/src/engine_api.rs b/src/engine_api.rs index 49595865..8cafcd26 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1385,7 +1385,7 @@ impl Engine { Some(&|token, _, _| { match token { // If `null` is present, make sure `null` is treated as a variable - Token::Reserved(s) if s == "null" => Token::Identifier(s), + Token::Reserved(s) if &*s == "null" => Token::Identifier(s), _ => token, } }) @@ -2118,7 +2118,7 @@ impl Engine { signatures.extend( self.global_modules .iter() - .take(self.global_modules.len() - 1) + .skip(1) .flat_map(|m| m.gen_fn_signatures()), ); } @@ -2214,10 +2214,10 @@ impl Engine { /// engine.on_parse_token(|token, _, _| { /// match token { /// // Convert all integer literals to strings - /// Token::IntegerConstant(n) => Token::StringConstant(n.to_string()), + /// Token::IntegerConstant(n) => Token::StringConstant(n.to_string().into()), /// // Convert 'begin' .. 'end' to '{' .. '}' - /// Token::Identifier(s) if &s == "begin" => Token::LeftBrace, - /// Token::Identifier(s) if &s == "end" => Token::RightBrace, + /// Token::Identifier(s) if &*s == "begin" => Token::LeftBrace, + /// Token::Identifier(s) if &*s == "end" => Token::RightBrace, /// // Pass through all other tokens unchanged /// _ => token /// } diff --git a/src/engine_settings.rs b/src/engine_settings.rs index 7032f84f..600434f9 100644 --- a/src/engine_settings.rs +++ b/src/engine_settings.rs @@ -308,18 +308,18 @@ 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.syntax().as_ref()) { + if !self.disabled_symbols.contains(&*token.syntax()) { return Err(format!("'{}' is a reserved keyword", keyword.as_ref())); } } // Active standard symbols cannot be made custom Some(token) if token.is_standard_symbol() => { - if !self.disabled_symbols.contains(token.syntax().as_ref()) { + if !self.disabled_symbols.contains(&*token.syntax()) { return Err(format!("'{}' is a reserved operator", keyword.as_ref())); } } // Active standard symbols cannot be made custom - Some(token) if !self.disabled_symbols.contains(token.syntax().as_ref()) => { + Some(token) if !self.disabled_symbols.contains(&*token.syntax()) => { return Err(format!("'{}' is a reserved symbol", keyword.as_ref())) } // Disabled symbols are OK diff --git a/src/fn_ptr.rs b/src/fn_ptr.rs index 8f091077..47197920 100644 --- a/src/fn_ptr.rs +++ b/src/fn_ptr.rs @@ -174,6 +174,16 @@ impl TryFrom for FnPtr { } } +impl TryFrom> for FnPtr { + type Error = Box; + + #[inline(always)] + fn try_from(value: Box) -> Result { + let s: Identifier = value.into(); + Self::try_from(s) + } +} + impl TryFrom<&str> for FnPtr { type Error = Box; diff --git a/src/immutable_string.rs b/src/immutable_string.rs index 53ccdab5..83bede60 100644 --- a/src/immutable_string.rs +++ b/src/immutable_string.rs @@ -94,6 +94,13 @@ impl From<&str> for ImmutableString { Self(value.into()) } } +impl From> for ImmutableString { + #[inline(always)] + fn from(value: Box) -> Self { + let value: SmartString = value.into(); + Self(value.into()) + } +} impl From<&String> for ImmutableString { #[inline(always)] fn from(value: &String) -> Self { diff --git a/src/module/mod.rs b/src/module/mod.rs index 03ef891e..d0a35342 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -66,11 +66,11 @@ impl FuncInfo { let mut sig = format!("{}(", self.name); if !self.param_names.is_empty() { - let mut params: StaticVec = + let mut params: StaticVec> = self.param_names.iter().map(|s| s.as_str().into()).collect(); let return_type = params.pop().unwrap_or_else(|| "()".into()); sig.push_str(¶ms.join(", ")); - if return_type != "()" { + if &*return_type != "()" { sig.push_str(") -> "); sig.push_str(&return_type); } else { diff --git a/src/parse.rs b/src/parse.rs index 9e3be877..daf8aab1 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -382,13 +382,13 @@ fn match_token(input: &mut TokenStream, token: Token) -> (bool, Position) { } /// Parse a variable name. -fn parse_var_name(input: &mut TokenStream) -> Result<(String, Position), ParseError> { +fn parse_var_name(input: &mut TokenStream) -> Result<(Box, Position), ParseError> { match input.next().expect(NEVER_ENDS) { // Variable name (Token::Identifier(s), pos) => Ok((s, pos)), // Reserved keyword (Token::Reserved(s), pos) if is_valid_identifier(s.chars()) => { - Err(PERR::Reserved(s).into_err(pos)) + Err(PERR::Reserved(s.to_string()).into_err(pos)) } // Bad identifier (Token::LexError(err), pos) => Err(err.into_err(pos)), @@ -398,7 +398,7 @@ fn parse_var_name(input: &mut TokenStream) -> Result<(String, Position), ParseEr } /// Parse a symbol. -fn parse_symbol(input: &mut TokenStream) -> Result<(String, Position), ParseError> { +fn parse_symbol(input: &mut TokenStream) -> Result<(Box, Position), ParseError> { match input.next().expect(NEVER_ENDS) { // Symbol (token, pos) if token.is_standard_symbol() => Ok((token.literal_syntax().into(), pos)), @@ -860,14 +860,14 @@ fn parse_map_literal( let (name, pos) = match input.next().expect(NEVER_ENDS) { (Token::Identifier(s), pos) | (Token::StringConstant(s), pos) => { - if map.iter().any(|(p, _)| p.name == s) { - return Err(PERR::DuplicatedProperty(s).into_err(pos)); + if map.iter().any(|(p, _)| p.name == &*s) { + return Err(PERR::DuplicatedProperty(s.to_string()).into_err(pos)); } (s, pos) } (Token::InterpolatedString(_), pos) => return Err(PERR::PropertyExpected.into_err(pos)), (Token::Reserved(s), pos) if is_valid_identifier(s.chars()) => { - return Err(PERR::Reserved(s).into_err(pos)); + return Err(PERR::Reserved(s.to_string()).into_err(pos)); } (Token::LexError(err), pos) => return Err(err.into_err(pos)), (Token::EOF, pos) => { @@ -1313,20 +1313,20 @@ fn parse_primary( (None, None, state.get_identifier(s)).into(), ), // Access to `this` as a variable is OK within a function scope - _ if s == KEYWORD_THIS && settings.is_function_scope => Expr::Variable( + _ if &*s == KEYWORD_THIS && settings.is_function_scope => Expr::Variable( None, settings.pos, (None, None, state.get_identifier(s)).into(), ), // Cannot access to `this` as a variable not in a function scope - _ if s == KEYWORD_THIS => { + _ if &*s == KEYWORD_THIS => { let msg = format!("'{}' can only be used in functions", s); - return Err(LexError::ImproperSymbol(s, msg).into_err(settings.pos)); + return Err(LexError::ImproperSymbol(s.to_string(), msg).into_err(settings.pos)); } _ if is_valid_identifier(s.chars()) => { - return Err(PERR::Reserved(s).into_err(settings.pos)) + return Err(PERR::Reserved(s.to_string()).into_err(settings.pos)) } - _ => return Err(LexError::UnexpectedInput(s).into_err(settings.pos)), + _ => return Err(LexError::UnexpectedInput(s.to_string()).into_err(settings.pos)), } } @@ -1840,11 +1840,11 @@ fn parse_binary_op( Token::Custom(c) => state .engine .custom_keywords - .get(c.as_str()) + .get(c.as_ref()) .cloned() - .ok_or_else(|| PERR::Reserved(c.clone()).into_err(*current_pos))?, + .ok_or_else(|| PERR::Reserved(c.to_string()).into_err(*current_pos))?, Token::Reserved(c) if !is_valid_identifier(c.chars()) => { - return Err(PERR::UnknownOperator(c.into()).into_err(*current_pos)) + return Err(PERR::UnknownOperator(c.to_string()).into_err(*current_pos)) } _ => current_op.precedence(), }; @@ -1865,11 +1865,11 @@ fn parse_binary_op( Token::Custom(c) => state .engine .custom_keywords - .get(c.as_str()) + .get(c.as_ref()) .cloned() - .ok_or_else(|| PERR::Reserved(c.clone()).into_err(*next_pos))?, + .ok_or_else(|| PERR::Reserved(c.to_string()).into_err(*next_pos))?, Token::Reserved(c) if !is_valid_identifier(c.chars()) => { - return Err(PERR::UnknownOperator(c.into()).into_err(*next_pos)) + return Err(PERR::UnknownOperator(c.to_string()).into_err(*next_pos)) } _ => next_op.precedence(), }; @@ -1971,7 +1971,7 @@ fn parse_binary_op( if state .engine .custom_keywords - .get(s.as_str()) + .get(s.as_ref()) .map_or(false, Option::is_some) => { let hash = calc_fn_hash(&s, 2); @@ -2027,7 +2027,7 @@ fn parse_custom_syntax( settings.pos = *fwd_pos; let settings = settings.level_up(); - required_token = match parse_func(&segments, fwd_token.syntax().as_ref()) { + required_token = match parse_func(&segments, &*fwd_token.syntax()) { Ok(Some(seg)) if seg.starts_with(CUSTOM_SYNTAX_MARKER_SYNTAX_VARIANT) && seg.len() > CUSTOM_SYNTAX_MARKER_SYNTAX_VARIANT.len() => @@ -2123,7 +2123,7 @@ fn parse_custom_syntax( }, s => match input.next().expect(NEVER_ENDS) { (Token::LexError(err), pos) => return Err(err.into_err(pos)), - (t, _) if t.syntax().as_ref() == s => { + (t, _) if &*t.syntax() == s => { segments.push(required_token.clone()); tokens.push(required_token.clone().into()); } @@ -2185,7 +2185,7 @@ fn parse_expr( match token { Token::Custom(key) | Token::Reserved(key) | Token::Identifier(key) => { - if let Some((key, syntax)) = state.engine.custom_syntax.get_key_value(key.as_str()) + if let Some((key, syntax)) = state.engine.custom_syntax.get_key_value(key.as_ref()) { input.next().expect(NEVER_ENDS); return parse_custom_syntax( @@ -2355,7 +2355,7 @@ fn parse_for( let (counter_name, counter_pos) = parse_var_name(input)?; if counter_name == name { - return Err(PERR::DuplicatedVariable(counter_name).into_err(counter_pos)); + return Err(PERR::DuplicatedVariable(counter_name.to_string()).into_err(counter_pos)); } let (has_close_paren, pos) = match_token(input, Token::RightParen); @@ -2560,12 +2560,12 @@ fn parse_export( let (rename, rename_pos) = if match_token(input, Token::As).0 { let (name, pos) = parse_var_name(input)?; - if exports.iter().any(|(_, alias)| alias.name == name) { - return Err(PERR::DuplicatedVariable(name).into_err(pos)); + if exports.iter().any(|(_, alias)| alias.name == name.as_ref()) { + return Err(PERR::DuplicatedVariable(name.to_string()).into_err(pos)); } - (name, pos) + (Some(name), pos) } else { - (String::new(), Position::NONE) + (None, Position::NONE) }; exports.push(( @@ -2574,7 +2574,7 @@ fn parse_export( pos: id_pos, }, Ident { - name: state.get_identifier(rename), + name: state.get_identifier(rename.as_ref().map_or("", |s| s.as_ref())), pos: rename_pos, }, )); @@ -2733,7 +2733,7 @@ fn parse_stmt( #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] let comments = { - let mut comments = StaticVec::::new(); + let mut comments = StaticVec::>::new(); let mut comments_pos = Position::NONE; // Handle doc-comments. @@ -2996,7 +2996,7 @@ fn parse_fn( settings: ParseSettings, #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] - comments: StaticVec, + comments: StaticVec>, ) -> Result { let mut settings = settings; @@ -3007,13 +3007,13 @@ fn parse_fn( let name = match token.into_function_name_for_override() { Ok(r) => r, - Err(Token::Reserved(s)) => return Err(PERR::Reserved(s).into_err(pos)), + Err(Token::Reserved(s)) => return Err(PERR::Reserved(s.to_string()).into_err(pos)), Err(_) => return Err(PERR::FnMissingName.into_err(pos)), }; match input.peek().expect(NEVER_ENDS) { (Token::LeftParen, _) => eat_token(input, Token::LeftParen), - (_, pos) => return Err(PERR::FnMissingParams(name).into_err(*pos)), + (_, pos) => return Err(PERR::FnMissingParams(name.to_string()).into_err(*pos)), }; let mut params = StaticVec::new(); @@ -3025,8 +3025,10 @@ fn parse_fn( match input.next().expect(NEVER_ENDS) { (Token::RightParen, _) => break, (Token::Identifier(s), pos) => { - if params.iter().any(|(p, _)| p == &s) { - return Err(PERR::FnDuplicatedParam(name, s).into_err(pos)); + if params.iter().any(|(p, _)| p == &*s) { + return Err( + PERR::FnDuplicatedParam(name.to_string(), s.to_string()).into_err(pos) + ); } let s = state.get_identifier(s); state.stack.push((s.clone(), AccessMode::ReadWrite)); @@ -3059,7 +3061,7 @@ fn parse_fn( settings.is_breakable = false; parse_block(input, state, lib, settings.level_up())? } - (_, pos) => return Err(PERR::FnMissingBody(name).into_err(*pos)), + (_, pos) => return Err(PERR::FnMissingBody(name.to_string()).into_err(*pos)), } .into(); @@ -3076,7 +3078,7 @@ fn parse_fn( .collect(); Ok(ScriptFnDef { - name: state.get_identifier(&name), + name: state.get_identifier(name), access, params, #[cfg(not(feature = "no_closure"))] @@ -3156,8 +3158,10 @@ fn parse_anon_fn( match input.next().expect(NEVER_ENDS) { (Token::Pipe, _) => break, (Token::Identifier(s), pos) => { - if params_list.iter().any(|p| p == &s) { - return Err(PERR::FnDuplicatedParam("".to_string(), s).into_err(pos)); + if params_list.iter().any(|p| p == &*s) { + return Err( + PERR::FnDuplicatedParam("".to_string(), s.to_string()).into_err(pos) + ); } let s = state.get_identifier(s); state.stack.push((s.clone(), AccessMode::ReadWrite)); diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index 1e10e58a..263dea3d 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -46,9 +46,9 @@ impl From for FnAccess { #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct FnParam { - pub name: String, + pub name: Box, #[serde(rename = "type", skip_serializing_if = "Option::is_none")] - pub typ: Option, + pub typ: Option>, } impl PartialOrd for FnParam { @@ -98,10 +98,10 @@ struct FnMetadata { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub params: Vec, #[serde(default, skip_serializing_if = "Option::is_none")] - pub return_type: Option, + pub return_type: Option>, pub signature: String, #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub doc_comments: Vec, + pub doc_comments: Vec>, } impl PartialOrd for FnMetadata { @@ -142,17 +142,17 @@ impl From<&crate::module::FuncInfo> for FnMetadata { let mut seg = s.splitn(2, ':'); let name = seg .next() - .map(|s| s.trim().to_string()) - .unwrap_or_else(|| "_".to_string()); - let typ = seg.next().map(|s| s.trim().to_string()); + .map(|s| s.trim().into()) + .unwrap_or_else(|| "_".into()); + let typ = seg.next().map(|s| s.trim().into()); FnParam { name, typ } }) .collect(), return_type: info .param_names .last() - .map(|s| s.to_string()) - .or_else(|| Some("()".to_string())), + .map(|s| s.as_str().into()) + .or_else(|| Some("()".into())), signature: info.gen_signature(), doc_comments: if info.func.is_script() { #[cfg(feature = "no_function")] @@ -186,14 +186,14 @@ impl From> for FnMetadata { params: info .params .iter() - .map(|s| FnParam { - name: s.to_string(), - typ: Some("Dynamic".to_string()), + .map(|&s| FnParam { + name: s.into(), + typ: Some("Dynamic".into()), }) .collect(), - return_type: Some("Dynamic".to_string()), + return_type: Some("Dynamic".into()), signature: info.to_string(), - doc_comments: info.comments.iter().map(|s| s.to_string()).collect(), + doc_comments: info.comments.iter().map(|&s| s.into()).collect(), } } } diff --git a/src/token.rs b/src/token.rs index 51c57726..61c31bcb 100644 --- a/src/token.rs +++ b/src/token.rs @@ -320,13 +320,13 @@ pub enum Token { #[cfg(feature = "decimal")] DecimalConstant(Decimal), /// An identifier. - Identifier(String), + Identifier(Box), /// A character constant. CharConstant(char), /// A string constant. - StringConstant(String), + StringConstant(Box), /// An interpolated string. - InterpolatedString(String), + InterpolatedString(Box), /// `{` LeftBrace, /// `}` @@ -489,11 +489,11 @@ pub enum Token { /// A lexer error. LexError(LexError), /// A comment block. - Comment(String), + Comment(Box), /// A reserved symbol. - Reserved(String), + Reserved(Box), /// A custom keyword. - Custom(String), + Custom(Box), /// End of the input stream. EOF, } @@ -603,11 +603,11 @@ impl Token { StringConstant(_) => "string".into(), InterpolatedString(_) => "string".into(), CharConstant(c) => c.to_string().into(), - Identifier(s) => s.clone().into(), - Reserved(s) => s.clone().into(), - Custom(s) => s.clone().into(), + Identifier(s) => s.to_string().into(), + Reserved(s) => s.to_string().into(), + Custom(s) => s.to_string().into(), LexError(err) => err.to_string().into(), - Comment(s) => s.clone().into(), + Comment(s) => s.to_string().into(), EOF => "{EOF}".into(), @@ -975,9 +975,9 @@ impl Token { /// Convert a token into a function name, if possible. #[cfg(not(feature = "no_function"))] #[inline] - pub(crate) fn into_function_name_for_override(self) -> Result { + pub(crate) fn into_function_name_for_override(self) -> Result, Self> { match self { - Self::Custom(s) | Self::Identifier(s) if is_valid_function_name(&s) => Ok(s), + Self::Custom(s) | Self::Identifier(s) if is_valid_function_name(&*s) => Ok(s), _ => Err(self), } } @@ -1077,7 +1077,7 @@ pub fn parse_string_literal( continuation: bool, verbatim: bool, allow_interpolation: bool, -) -> Result<(String, bool), (LexError, Position)> { +) -> Result<(Box, bool), (LexError, Position)> { let mut result = String::with_capacity(12); let mut escape = String::with_capacity(12); @@ -1268,7 +1268,7 @@ pub fn parse_string_literal( } } - Ok((result, interpolated)) + Ok((result.into(), interpolated)) } /// Consume the next character. @@ -1399,7 +1399,7 @@ fn get_next_token_inner( if return_comment { return Some(( - Token::Comment(comment.expect("`return_comment` is true")), + Token::Comment(comment.expect("`return_comment` is true").into()), start_pos, )); } @@ -1649,7 +1649,10 @@ fn get_next_token_inner( let first = chars.next().expect("`chars` is not empty"); if chars.next().is_some() { - (Token::LexError(LERR::MalformedChar(result)), start_pos) + ( + Token::LexError(LERR::MalformedChar(result.to_string())), + start_pos, + ) } else { (Token::CharConstant(first), start_pos) } @@ -1773,7 +1776,7 @@ fn get_next_token_inner( } if let Some(comment) = comment { - return Some((Token::Comment(comment), start_pos)); + return Some((Token::Comment(comment.into()), start_pos)); } } ('/', '*') => { @@ -1800,7 +1803,7 @@ fn get_next_token_inner( scan_block_comment(stream, state.comment_level, pos, comment.as_mut()); if let Some(comment) = comment { - return Some((Token::Comment(comment), start_pos)); + return Some((Token::Comment(comment.into()), start_pos)); } } @@ -2001,7 +2004,7 @@ fn get_identifier( )); } - Some((Token::Identifier(identifier), start_pos)) + Some((Token::Identifier(identifier.into()), start_pos)) } /// Is this keyword allowed as a function? @@ -2185,29 +2188,29 @@ impl<'a> Iterator for TokenIterator<'a> { } // Reserved keyword/symbol Some((Token::Reserved(s), pos)) => (match - (s.as_str(), self.engine.custom_keywords.contains_key(s.as_str())) + (&*s, self.engine.custom_keywords.contains_key(&*s)) { - ("===", false) => Token::LexError(LERR::ImproperSymbol(s, + ("===", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'===' is not a valid operator. This is not JavaScript! Should it be '=='?".to_string(), )), - ("!==", false) => Token::LexError(LERR::ImproperSymbol(s, + ("!==", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'!==' is not a valid operator. This is not JavaScript! Should it be '!='?".to_string(), )), - ("->", false) => Token::LexError(LERR::ImproperSymbol(s, + ("->", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'->' is not a valid symbol. This is not C or C++!".to_string())), - ("<-", false) => Token::LexError(LERR::ImproperSymbol(s, + ("<-", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'<-' is not a valid symbol. This is not Go! Should it be '<='?".to_string(), )), - (":=", false) => Token::LexError(LERR::ImproperSymbol(s, + (":=", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "':=' is not a valid assignment operator. This is not Go or Pascal! Should it be simply '='?".to_string(), )), - ("::<", false) => Token::LexError(LERR::ImproperSymbol(s, + ("::<", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'::<>' is not a valid symbol. This is not Rust! Should it be '::'?".to_string(), )), - ("(*", false) | ("*)", false) => Token::LexError(LERR::ImproperSymbol(s, + ("(*", false) | ("*)", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'(* .. *)' is not a valid comment format. This is not Pascal! Should it be '/* .. */'?".to_string(), )), - ("#", false) => Token::LexError(LERR::ImproperSymbol(s, + ("#", false) => Token::LexError(LERR::ImproperSymbol(s.to_string(), "'#' is not a valid symbol. Should it be '#{'?".to_string(), )), // Reserved keyword/operator that is custom. @@ -2215,23 +2218,23 @@ impl<'a> Iterator for TokenIterator<'a> { // Reserved operator that is not custom. (token, false) if !is_valid_identifier(token.chars()) => { let msg = format!("'{}' is a reserved symbol", token); - Token::LexError(LERR::ImproperSymbol(s, msg)) + Token::LexError(LERR::ImproperSymbol(s.to_string(), msg)) }, // Reserved keyword that is not custom and disabled. (token, false) if self.engine.disabled_symbols.contains(token) => { let msg = format!("reserved symbol '{}' is disabled", token); - Token::LexError(LERR::ImproperSymbol(s, msg)) + Token::LexError(LERR::ImproperSymbol(s.to_string(), msg)) }, // Reserved keyword/operator that is not custom. (_, false) => Token::Reserved(s), }, pos), // Custom keyword - Some((Token::Identifier(s), pos)) if self.engine.custom_keywords.contains_key(s.as_str()) => { + Some((Token::Identifier(s), pos)) if self.engine.custom_keywords.contains_key(&*s) => { (Token::Custom(s), pos) } // Custom standard keyword/symbol - must be disabled - Some((token, pos)) if self.engine.custom_keywords.contains_key(token.syntax().as_ref()) => { - if self.engine.disabled_symbols.contains(token.syntax().as_ref()) { + Some((token, pos)) if self.engine.custom_keywords.contains_key(&*token.syntax()) => { + if self.engine.disabled_symbols.contains(&*token.syntax()) { // Disabled standard keyword/symbol (Token::Custom(token.syntax().into()), pos) } else { @@ -2240,7 +2243,7 @@ impl<'a> Iterator for TokenIterator<'a> { } } // Disabled symbol - Some((token, pos)) if self.engine.disabled_symbols.contains(token.syntax().as_ref()) => { + Some((token, pos)) if self.engine.disabled_symbols.contains(&*token.syntax()) => { (Token::Reserved(token.syntax().into()), pos) } // Normal symbol