Skip to content

Commit

Permalink
Support Guile results that lack an assignment (like display)
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Dec 1, 2023
1 parent befd4e7 commit af8a3da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
29 changes: 17 additions & 12 deletions fnl/conjure/client/guile/socket.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,23 @@
(a.assoc (state) :repl nil))))

(defn- parse-guile-result [s]
(if (s:find "scheme@%([%w%-%s]+%)> ")
(let [(ind1 ind2 result) (s:find "%$%d+ = ([^\n]+)\n")]
{:done? true
:error? false
:result result})
(if (s:find "scheme@%([%w%-%s]+%) %[%d+%]>")
{:done? true
:error? true
:result nil}
{:done? false
:error? false
:result s})))
(let [prompt (s:find "scheme@%([%w%-%s]+%)> ")]
(if prompt
(let [(ind1 ind2 result) (s:find "%$%d+ = ([^\n]+)\n")]
(if result
{:done? true
:error? false
:result result}
{:done? true
:error? false
:result (s:sub 1 (- prompt 1))}))
(if (s:find "scheme@%([%w%-%s]+%) %[%d+%]>")
{:done? true
:error? true
:result nil}
{:done? false
:error? false
:result s}))))

(defn connect [opts]
(disconnect)
Expand Down
23 changes: 14 additions & 9 deletions lua/conjure/client/guile/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,14 @@ local function disconnect()
end
_2amodule_2a["disconnect"] = disconnect
local function parse_guile_result(s)
if s:find("scheme@%([%w%-%s]+%)> ") then
local prompt = s:find("scheme@%([%w%-%s]+%)> ")
if prompt then
local ind1, ind2, result = s:find("%$%d+ = ([^\n]+)\n")
return {["done?"] = true, result = result, ["error?"] = false}
if result then
return {["done?"] = true, result = result, ["error?"] = false}
else
return {["done?"] = true, result = s:sub(1, (prompt - 1)), ["error?"] = false}
end
else
if s:find("scheme@%([%w%-%s]+%) %[%d+%]>") then
return {["done?"] = true, ["error?"] = true, result = nil}
Expand All @@ -172,16 +177,16 @@ local function connect(opts)
if ("string" ~= type(pipename)) then
return log.append({(comment_prefix .. "g:conjure#client#guile#socket#pipename is not specified"), (comment_prefix .. "Please set it to the name of your Guile REPL pipe or pass it to :ConjureConnect [pipename]")})
else
local function _23_()
local function _24_()
return display_repl_status()
end
local function _24_(msg, repl)
local function _25_(msg, repl)
display_result(msg)
local function _25_()
local function _26_()
end
return repl.send(",q\n", _25_)
return repl.send(",q\n", _26_)
end
return a.assoc(state(), "repl", socket.start({["parse-output"] = parse_guile_result, pipename = pipename, ["on-success"] = _23_, ["on-error"] = _24_, ["on-failure"] = disconnect, ["on-close"] = disconnect, ["on-stray-output"] = display_result}))
return a.assoc(state(), "repl", socket.start({["parse-output"] = parse_guile_result, pipename = pipename, ["on-success"] = _24_, ["on-error"] = _25_, ["on-failure"] = disconnect, ["on-close"] = disconnect, ["on-stray-output"] = display_result}))
end
end
_2amodule_2a["connect"] = connect
Expand All @@ -190,10 +195,10 @@ local function on_exit()
end
_2amodule_2a["on-exit"] = on_exit
local function on_filetype()
local function _27_()
local function _28_()
return connect()
end
mapping.buf("GuileConnect", cfg({"mapping", "connect"}), _27_, {desc = "Connect to a REPL"})
mapping.buf("GuileConnect", cfg({"mapping", "connect"}), _28_, {desc = "Connect to a REPL"})
return mapping.buf("GuileDisconnect", cfg({"mapping", "disconnect"}), disconnect, {desc = "Disconnect from the REPL"})
end
_2amodule_2a["on-filetype"] = on_filetype
Expand Down

0 comments on commit af8a3da

Please sign in to comment.