Fix custom syntax bug.

This commit is contained in:
Stephen Chung
2023-04-25 23:14:08 +08:00
parent 6be29cae54
commit 4ec16d14e0
3 changed files with 67 additions and 9 deletions

View File

@@ -232,11 +232,9 @@ impl Engine {
}
let token = Token::lookup_symbol_from_syntax(s).or_else(|| {
if is_reserved_keyword_or_symbol(s).0 {
Some(Token::Reserved(Box::new(s.into())))
} else {
None
}
is_reserved_keyword_or_symbol(s)
.0
.then(|| Token::Reserved(Box::new(s.into())))
});
let seg = match s {
@@ -256,6 +254,9 @@ impl Engine {
#[cfg(not(feature = "no_float"))]
CUSTOM_SYNTAX_MARKER_FLOAT if !segments.is_empty() => s.into(),
// Identifier not in first position
_ if !segments.is_empty() && is_valid_identifier(s) => s.into(),
// Keyword/symbol not in first position
_ if !segments.is_empty() && token.is_some() => {
// Make it a custom keyword/symbol if it is disabled or reserved
@@ -277,10 +278,7 @@ impl Engine {
{
return Err(LexError::ImproperSymbol(
s.to_string(),
format!(
"Improper symbol for custom syntax at position #{}: '{s}'",
segments.len() + 1,
),
format!("Improper symbol for custom syntax at position #0: '{s}'"),
)
.into_err(Position::NONE));
}