repl: peel trailing punctuation from @path mentions (#7 follow-up)
Natural-language prose like "look at @README.md, then..." or "@foo.lua." at sentence end previously failed to expand because the trailing comma/period was included in the path. Now: if the raw token doesn't resolve, peel trailing chars from [.,;:?!)] one at a time until the path resolves or no more peels are possible. On success, the peeled chars are emitted verbatim AFTER the closing fence so the original punctuation is preserved. Surfaced during higgs smoke test (TC: "say the first line of @README.md, then stop" — the trailing comma broke resolution). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -54,7 +54,22 @@ local function expand_mentions(line, on_status)
|
||||
local at_start = (i == 1) or line:sub(i - 1, i - 1):match("%s") ~= nil
|
||||
if at_start and line:sub(i, i) == "@" then
|
||||
local path_end = line:find("%s", i + 1) or (#line + 1)
|
||||
local path = line:sub(i + 1, path_end - 1)
|
||||
local raw = line:sub(i + 1, path_end - 1)
|
||||
-- Peel one or more trailing punctuation chars (,.;:?!) if the
|
||||
-- full path doesn't resolve — handles natural prose like
|
||||
-- "look at @README.md, then..." or "@foo.lua." at sentence end.
|
||||
local path, trail = raw, ""
|
||||
while #path > 0 do
|
||||
local f = io.open(path, "rb")
|
||||
if f then f:close(); break end
|
||||
local last = path:sub(-1)
|
||||
if last:match("[%.,;:?!)]") then
|
||||
trail = last .. trail
|
||||
path = path:sub(1, -2)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
if path ~= "" then
|
||||
local content, truncated = _read_truncated(path)
|
||||
if content then
|
||||
@@ -62,12 +77,12 @@ local function expand_mentions(line, on_status)
|
||||
on_status(("@%s expanded (%d bytes%s)"):format(
|
||||
path, #content, truncated and ", truncated" or ""))
|
||||
end
|
||||
out[#out + 1] = ("```%s path=%s\n%s\n```"):format(
|
||||
_lang_of(path), path, content)
|
||||
out[#out + 1] = ("```%s path=%s\n%s\n```%s"):format(
|
||||
_lang_of(path), path, content, trail)
|
||||
i = path_end
|
||||
else
|
||||
if on_status then
|
||||
on_status(("@%s: not found"):format(path))
|
||||
on_status(("@%s: not found"):format(raw))
|
||||
end
|
||||
out[#out + 1] = line:sub(i, path_end - 1)
|
||||
i = path_end
|
||||
|
||||
Reference in New Issue
Block a user