diff options
Diffstat (limited to 'lua_src/sild/parse.lua')
| -rw-r--r-- | lua_src/sild/parse.lua | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lua_src/sild/parse.lua b/lua_src/sild/parse.lua new file mode 100644 index 0000000..1757658 --- /dev/null +++ b/lua_src/sild/parse.lua @@ -0,0 +1,44 @@ +local highlight = require("sild.highlight") + +local M = {} + +function M.annotations(path) + local breakpoints, actions = {}, {} + -- Use highlight's read_file for caching purposes + local lines = highlight.read_file(path) + + local function add_action(line_number, action_table) + actions[line_number] = actions[line_number] or {} + actions[line_number][#actions[line_number] + 1] = action_table + end + + for i, line in ipairs(lines) do + local next_line = i + 1 + + local stripped = line:match("^%s*(.-)%s*$") + + if stripped:sub(1, 3) == "---" then + local rest = stripped:sub(4):match("^%s*(.-)%s*$") + + if rest:sub(1, 8) == "BREAK if" then + breakpoints[next_line] = rest:sub(9):match("^%s*(.-)%s*$") + elseif rest == "BREAK" then + breakpoints[next_line] = true + elseif rest:sub(1, 5) == "WATCH" then + local condition = rest:sub(6):match("^%s*(.-)%s*$") + if condition ~= "" then + add_action(next_line, { type = "watch", condition = condition }) + end + elseif rest:sub(1, 7) == "UNWATCH" then + local condition = rest:sub(8):match("^%s*(.-)%s*$") + if condition ~= "" then + add_action(next_line, { type = "unwatch", condition = condition }) + end + end + end + end + + return breakpoints, actions +end + +return M |
