feat: improve tree-sitter syntax highlighting with named nodes

- Add aliases for keywords (VAR_INPUT, BEGIN, IF, etc.) as named nodes
- Add aliases for built-in types (INT, BOOL, STRING, etc.) as type_builtin
- Add aliases for constants (TRUE, FALSE)
- Add aliases for operators (AND, OR, NOT, MOD)
- Add prefix node for # variable prefix highlighting
- Highlight FB instance names in calls
- Highlight FB parameter names as properties
- Update README with detailed syntax highlighting features
- Update .gitignore for *.wasm files
This commit is contained in:
2026-02-20 23:29:26 +01:00
parent dfa4ef3381
commit 553192e7a1
10 changed files with 60598 additions and 55374 deletions
+23
View File
@@ -129,6 +129,10 @@ function M.extract_variables(content)
end
end
local var_data_type = "unknown"
local var_comment = line:match("//%s*(.+)$")
if not var_comment then
var_comment = line:match("%(%*(.-)%*%)")
end
if type_start then
local type_part = line:sub(type_start + 1)
type_part = type_part:gsub("%s*:=.*$", "")
@@ -143,6 +147,7 @@ function M.extract_variables(content)
data_type = var_data_type,
line = line_num,
character = col - 1,
comment = var_comment,
}
variable_positions[var_name] = {
line = line_num,
@@ -172,6 +177,7 @@ function M.extract_types(content)
local brace_depth = 0
local in_struct = false
local pending_type_name = nil
local pending_comment = nil
local function extract_type_name(after_colon)
if not after_colon then return nil end
@@ -183,6 +189,11 @@ function M.extract_types(content)
for i, line in ipairs(lines) do
local trimmed = line:gsub("^%s+", ""):gsub("%s+$", "")
local is_comment_only = trimmed:match("^//")
if is_comment_only then
pending_comment = line:match("//%s*(.+)$")
end
local is_type_line = trimmed:match("^TYPE") and (trimmed:match("^TYPE%s") or trimmed:match('^TYPE"') or trimmed == "TYPE")
if is_type_line then
@@ -190,6 +201,9 @@ function M.extract_types(content)
in_struct = false
brace_depth = 0
pending_type_name = trimmed:match('^TYPE%s+"([^"]+)') or trimmed:match("^TYPE%s+(%w+)")
if not pending_comment then
pending_comment = trimmed:match("//%s*(.+)$")
end
elseif in_type_section and trimmed:match("^END_TYPE") then
in_type_section = false
in_struct = false
@@ -203,10 +217,12 @@ function M.extract_types(content)
kind = "struct",
fields = {},
start_line = i - 1,
comment = pending_comment,
}
types[type_name_with_struct] = current_type
in_struct = true
pending_type_name = nil
pending_comment = nil
elseif trimmed:match("^STRUCT%s*$") then
if pending_type_name then
current_type = {
@@ -214,9 +230,11 @@ function M.extract_types(content)
kind = "struct",
fields = {},
start_line = i - 1,
comment = pending_comment,
}
types[pending_type_name] = current_type
pending_type_name = nil
pending_comment = nil
end
in_struct = true
elseif trimmed:match("^END_STRUCT%s*$") then
@@ -226,9 +244,14 @@ function M.extract_types(content)
if field_name then
local after_colon = line:match(":%s*(.+)")
local field_type = after_colon and extract_type_name(after_colon)
local field_comment = line:match("//%s*(.+)$")
if not field_comment then
field_comment = line:match("%(%*(.-)%*%)")
end
table.insert(current_type.fields, {
name = field_name,
type = field_type or "unknown",
comment = field_comment,
})
end
elseif not in_struct and not pending_type_name then