glimr/db/gen/parser/util
SQL Parser Utilities
Shared utility functions for SQL parsing including character classification, identifier extraction, and keyword detection.
Values
pub fn consume_digits(
s: String,
acc: String,
) -> #(String, String)
Consume consecutive digit characters from the start of a string. Returns the consumed digits and remaining string.
pub fn extract_identifier(s: String) -> String
Extract a SQL identifier (table or column name) from the start of a string. Handles both regular identifiers and double-quoted identifiers like “table-name” or “schema”.“table”.
pub fn extract_last_identifier(s: String) -> String
Extract the last SQL identifier from a string by working backwards from the end.
pub const identifier_chars: String
Valid identifier characters for SQL column and table names
pub fn is_identifier_char(c: String) -> Bool
Check if a character is valid in a SQL identifier (letters, digits, underscore).
pub fn is_sql_keyword(s: String) -> Bool
Check if a string is a SQL keyword (not a valid column name). Used to filter out false positives in column detection.
pub fn parse_int(s: String) -> option.Option(Int)
Parse an integer from a string, returning None for empty strings or invalid integers.
pub fn strip_string_literals(sql: String) -> String
Remove content from single-quoted string literals to prevent false positives when parsing SQL keywords. Replaces ‘content’ with ‘’ to preserve SQL structure.