Utilities for Lotus {{variable}} template syntax.
Variables use the {{name}} placeholder format and can appear in SQL
queries, templates, or any other Lotus content type.
Placeholders are found with Lotus.Query.Tokenizer, so a {{name}}
inside a comment or a quoted identifier is not a variable. A placeholder
inside a string literal is, because the dialect transformer rewrites
literals such as '%{{q}}%' before binding. Every function takes an
optional Lotus.Query.Tokenizer.Profile; the default is ANSI SQL.
Summary
Functions
@spec extract_names(String.t(), Lotus.Query.Tokenizer.Profile.t()) :: [String.t()]
Extracts variable names from a string containing {{variable}} placeholders.
Returns names in the order they appear, with duplicates preserved.
Examples
iex> Lotus.Variables.extract_names("WHERE id = {{user_id}} AND status = {{status}}")
["user_id", "status"]
iex> Lotus.Variables.extract_names("no variables here")
[]
iex> Lotus.Variables.extract_names("-- {{note}}\nSELECT {{id}}")
["id"]
@spec neutralize(String.t(), String.t(), Lotus.Query.Tokenizer.Profile.t()) :: String.t()
Replaces all {{variable}} placeholders with the given replacement value.
Useful for neutralizing variables before validation (e.g. replacing with
"NULL" for SQL syntax checking) or for any context where placeholders
need to be substituted with a static value.
Examples
iex> Lotus.Variables.neutralize("SELECT * FROM users WHERE id = {{user_id}}", "NULL")
"SELECT * FROM users WHERE id = NULL"
iex> Lotus.Variables.neutralize("Hello {{name}}", "")
"Hello "
@spec regex() :: Regex.t()
Returns the compiled regex for matching {{variable}} placeholders.
Captures the variable name (without braces) in group 1. The regex is not
aware of comments or literals; prefer extract_names/2.
Examples
iex> Regex.scan(Lotus.Variables.regex(), "WHERE id = {{user_id}}")
[["{{user_id}}", "user_id"]]