summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 13:42:41 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 13:42:41 +0300
commitad7113c9119458f076fea90f55b8a9ceecb45891 (patch)
tree4933d32db05ba3644d24b736ec559cc3eaa70bd6
parent9dd16cddc2d712c3aad0b0a5c8a5a1227e36a1c7 (diff)
refactor(rpn): simplify isValidIdentifier(), removing dead multi-char loop (task 5j)
The loop checking remaining characters was dead code — the final check meant any token longer than 1 char was rejected regardless of what the loop found. Replace the entire function with a simple single-char check.
-rw-r--r--internal/rpn/rpn_parse.go27
1 files changed, 5 insertions, 22 deletions
diff --git a/internal/rpn/rpn_parse.go b/internal/rpn/rpn_parse.go
index 8bc2b96..c3785b2 100644
--- a/internal/rpn/rpn_parse.go
+++ b/internal/rpn/rpn_parse.go
@@ -439,34 +439,17 @@ func (r *RPN) dispatchOperator(stack *Stack, token string) (string, error) {
}
// isValidIdentifier checks if a token looks like a valid variable identifier.
-// Valid identifiers contain only alphanumeric characters and underscores,
-// and start with a letter or underscore (not a digit or special character).
+// Valid identifiers are single alphanumeric characters or underscores.
//
// IMPORTANT: To prevent natural language words (like "what", "is", "of") from
// being incorrectly treated as RPN symbols in mixed-mode expressions,
-// this function currently restricts valid identifiers to a length of 1.
+// this function restricts valid identifiers to a length of 1.
func isValidIdentifier(token string) bool {
- if len(token) == 0 {
+ if len(token) != 1 {
return false
}
-
- // Check first character - must be letter or underscore
- first := token[0]
- if !((first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z') || first == '_') {
- return false
- }
-
- // Check remaining characters - must be alphanumeric or underscore
- for i := 1; i < len(token); i++ {
- c := token[i]
- if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') {
- return false
- }
- }
-
- // Only allow single-character identifiers for symbol support
- // This prevents words like "what", "is", "of" from becoming symbols
- return len(token) == 1
+ c := token[0]
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'
}
// extractVariableName extracts a variable name from a token, stripping the leading colon if present.