summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVineet Kumar <git@vineetk.net>2026-05-25 19:57:25 -0400
committerVineet Kumar <git@vineetk.net>2026-05-25 19:57:25 -0400
commit7da69666fcdcee3fe29768476bc6bcec21dc7b70 (patch)
tree1c9e4a3bdd5ff8f54844141e382716aa1e34d599
parente0014f37a16458815e0697fdd930aba3a4a55f5e (diff)
split hl-parse-section-ops to be not monolithic
-rw-r--r--llm-tools-hl.el54
1 files changed, 32 insertions, 22 deletions
diff --git a/llm-tools-hl.el b/llm-tools-hl.el
index 1854acb..f4473d3 100644
--- a/llm-tools-hl.el
+++ b/llm-tools-hl.el
@@ -112,31 +112,41 @@ Each element is a line number and two-character hash, like `1vx'."
112 (payload nil) ; list of strings (nil is no payload) 112 (payload nil) ; list of strings (nil is no payload)
113 (raw nil)) ; raw op line text for error messages 113 (raw nil)) ; raw op line text for error messages
114 114
115(defun llm-tools--hl-non-empty-non-comment-line-p (line)
116 "Return t if LINE is not empty and not a comment (starts with #)."
117 (let ((trimmed (string-trim line)))
118 (and (not (string-empty-p trimmed))
119 (not (string-prefix-p "#" trimmed)))))
120
121(defun llm-tools--hl-parse-op-line-for-verify (line)
122 "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op`."
123 (let* ((trimmed (string-trim line))
124 (ch (substring trimmed 0 1)))
125 (make-hl-verify-op
126 :type (pcase ch
127 ("+" 'insert-after)
128 ("<" 'insert-before)
129 ("-" 'delete)
130 ("=" 'replace))
131 :anchor (string-trim (substring trimmed 1))
132 :raw trimmed)))
133
134(defun llm-tools--hl-add-payload-to-verify-op (op payload-line)
135 "Append PAYLOAD-LINE (without leading ~) to OP's payload list."
136 (setf (hl-verify-op-payload op)
137 (append (hl-verify-op-payload op) (list (substring (string-trim payload-line) 1)))))
138
115(defun llm-tools--hl-parse-section-ops (section-body) 139(defun llm-tools--hl-parse-section-ops (section-body)
116 "Parse SECTION-BODY into a list of `hl-verify-op' structs. 140 "Parse SECTION-BODY into a list of `hl-verify-op' structs."
117Skips comment lines and blank lines."
118 (let (ops op) 141 (let (ops op)
119 (dolist (line (string-lines section-body)) 142 (dolist (line (string-lines section-body))
120 (let ((trimmed (string-trim line))) 143 (when (llm-tools--hl-non-empty-non-comment-line-p line)
121 (when (and (not (string-empty-p trimmed)) 144 (let* ((trimmed (string-trim line))
122 (not (string-prefix-p "#" trimmed))) 145 (ch (substring trimmed 0 1)))
123 (let ((ch (substring trimmed 0 1))) 146 (if (string= ch "~")
124 (pcase ch 147 (when op (llm-tools--hl-add-payload-to-verify-op op trimmed))
125 ("~" 148 (when op (push op ops))
126 (when op 149 (setq op (llm-tools--hl-parse-op-line-for-verify trimmed))))))
127 (setf (hl-verify-op-payload op)
128 (append (hl-verify-op-payload op)
129 (list (substring trimmed 1))))))
130 (_
131 (when op (push op ops))
132 (setq op (make-hl-verify-op
133 :type (pcase ch
134 ("+" 'insert-after)
135 ("<" 'insert-before)
136 ("-" 'delete)
137 ("=" 'replace))
138 :anchor (string-trim (substring trimmed 1))
139 :raw trimmed))))))))
140 (when op (push op ops)) 150 (when op (push op ops))
141 (nreverse ops))) 151 (nreverse ops)))
142 152