MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / AnalyzeTokenError

Function AnalyzeTokenError

pkg/errors/suggestions.go:264–295  ·  view source on GitHub ↗

AnalyzeTokenError produces a context-aware suggestion string for token-level parse errors. It inspects the actual and expected token types to provide specific guidance - for example, detecting when a quoted string is used where a number is expected, or when an unknown identifier looks like a misspel

(tokenType, tokenValue, expectedType string)

Source from the content-addressed store, hash-verified

262//
263// Returns a human-readable suggestion string; never returns empty string.
264func AnalyzeTokenError(tokenType, tokenValue, expectedType string) string {
265 // String literal where number expected
266 if tokenType == "STRING" && (expectedType == "NUMBER" || expectedType == "INTEGER") {
267 return fmt.Sprintf("Expected a number but found a string literal '%s'. Remove the quotes if this should be numeric.", tokenValue)
268 }
269
270 // Number where string expected
271 if tokenType == "NUMBER" && expectedType == "STRING" {
272 return fmt.Sprintf("Expected a string but found a number %s. Add quotes if this should be a string literal.", tokenValue)
273 }
274
275 // Identifier issues
276 if tokenType == "IDENT" {
277 suggestion := SuggestKeyword(tokenValue)
278 if suggestion != "" && suggestion != strings.ToUpper(tokenValue) {
279 return fmt.Sprintf("Unknown identifier '%s'. Did you mean the keyword '%s'?", tokenValue, suggestion)
280 }
281 }
282
283 // Missing operator between tokens
284 if tokenType == "IDENT" && expectedType == "OPERATOR" {
285 return "Expected an operator (=, <, >, AND, OR, etc.) between expressions."
286 }
287
288 // Unclosed parenthesis
289 if tokenType == "EOF" && expectedType == "RPAREN" {
290 return "Unclosed parenthesis detected. Check that all opening parentheses have matching closing parentheses."
291 }
292
293 // Generic suggestion
294 return fmt.Sprintf("Expected %s but found %s. Review the SQL syntax at this position.", expectedType, tokenType)
295}
296
297// SuggestForIncompleteStatement returns a suggestion string explaining what tokens
298// or clauses are expected to follow the given SQL keyword. This is used when the

Callers 2

TestAnalyzeTokenErrorFunction · 0.85

Calls 1

SuggestKeywordFunction · 0.85

Tested by 2

TestAnalyzeTokenErrorFunction · 0.68