From 94bb19748d3bb8636cf252539b8f0be18f46515a Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 14 Oct 2025 09:53:33 +0530 Subject: Switch grep update script to fnl --- scripts/apply_vimgrep_updates.fnl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 scripts/apply_vimgrep_updates.fnl (limited to 'scripts/apply_vimgrep_updates.fnl') diff --git a/scripts/apply_vimgrep_updates.fnl b/scripts/apply_vimgrep_updates.fnl new file mode 100755 index 0000000..b70e93e --- /dev/null +++ b/scripts/apply_vimgrep_updates.fnl @@ -0,0 +1,39 @@ +#!/usr/bin/env -S fennel --lua luajit + +(local M {}) + +(fn M.main [] + (local write-count (M.apply-vimgrep-changes)) + (print (.. "Applied " write-count " changes"))) + +(fn M.apply-vimgrep-changes [] + (var count 0) + (each [line (io.lines)] + (local (filepath linenr _ text) (M.parse-vimgrep line)) + (when filepath + (local applied? (M.update-line filepath linenr text)) + (when applied? + (set count (+ count 1))))) + count) + +(fn M.parse-vimgrep [line] + (local (filepath linenr col text) (string.match line "(.*):(%d+):(%d+):(.*)")) + (values filepath (tonumber linenr) col text)) + +(fn M.update-line [filepath linenr text] + (local lines (M.read-lines filepath)) + (var written? false) + (when (and (> (length lines) linenr) (not= (. lines linenr) text)) + (set (. lines linenr) text) + (local file (io.open filepath :w)) + (file:write (table.concat lines "\n")) + (file:close) + (set written? true)) + written?) + +(fn M.read-lines [filepath] + (local file (io.open filepath :r)) + (local lines []) + (each [line (file:lines)] (table.insert lines line)) + (file:close) + lines) -- cgit v1.3.1