diff --git a/src/formatter.lua b/src/formatter.lua index 3e6aef7..77cde74 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -260,7 +260,8 @@ function M.format_document(content, options) -- Helper: extract keyword from line local function get_keyword(trimmed) - return trimmed:match("^(%w+_%w+)") or trimmed:match("^(%w+)") + -- Match VAR_IN_OUT, VAR_CONSTANT, etc. (words with multiple underscores) + return trimmed:match("^([%w_]+)") or trimmed:match("^(%w+)") end -- Helper: find case block in stack @@ -498,7 +499,7 @@ function M.format_document(content, options) goto continue end - -- Regular line + -- Regular line (including variable declarations inside VAR sections) local formatted = get_indent() .. trimmed -- Add semicolon if it looks like it needs one if NEEDS_SEMICOLON[kw] and trimmed:sub(-1) ~= ";" then