Fix bug in custom syntax starting with disabled stardard keyword.

This commit is contained in:
Stephen Chung
2021-08-13 19:23:20 +08:00
parent c1b4c81e75
commit 114c93f430
3 changed files with 52 additions and 11 deletions

View File

@@ -230,11 +230,10 @@ impl Engine {
}
s.into()
}
// Standard keyword in first position
s if segments.is_empty()
&& token
.as_ref()
.map_or(false, |v| v.is_standard_keyword() || v.is_reserved()) =>
// Standard keyword in first position but not disabled
_ if segments.is_empty()
&& token.as_ref().map_or(false, |v| v.is_standard_keyword())
&& !self.disabled_symbols.contains(s) =>
{
return Err(LexError::ImproperSymbol(
s.to_string(),
@@ -247,13 +246,13 @@ impl Engine {
.into_err(Position::NONE));
}
// Identifier in first position
s if segments.is_empty() && is_valid_identifier(s.chars()) => {
_ if segments.is_empty() && is_valid_identifier(s.chars()) => {
// Make it a custom keyword/symbol if it is disabled or reserved
if (self.disabled_symbols.contains(s)
|| matches!(token, Some(Token::Reserved(_))))
&& !self.custom_keywords.contains_key(s)
if self.disabled_symbols.contains(s) || token.map_or(false, |v| v.is_reserved())
{
self.custom_keywords.insert(s.into(), None);
if !self.custom_keywords.contains_key(s) {
self.custom_keywords.insert(s.into(), None);
}
}
s.into()
}