Last active
June 30, 2024 13:57
-
-
Save hymkor/d2f4ebca9bbe83669cef44f7c9aac668 to your computer and use it in GitHub Desktop.
nyagosでシングルクォートを UNIX 風に使えるようにするフィルタ。"で囲まれていない ' を " にかえ、' で囲まれた " を \" に置換するだけ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function sq2dq(source) | |
local sq = false | |
local dq = false | |
return (string.gsub(source,"[\"']",function(c) | |
if c == "'" then | |
if not dq then | |
sq = not sq | |
return '"' | |
end | |
end | |
if c == '"' then | |
if sq then | |
return [[\"]] | |
end | |
dq = not dq | |
end | |
return c | |
end)) | |
end | |
if nyagos then | |
share.org_filter_for_sq2dq = nyagos.filter | |
nyagos.filter = function(s) | |
s = sq2dq(s) | |
if share.org_filter_for_sq2dq then | |
s = share.org_filter_for_sq2dq(s) | |
end | |
return s | |
end | |
else | |
assert(sq2dq[['(print "ahaha")']] == [["(print \"ahaha\")"]]) | |
assert(sq2dq[["(print \"ahaha\")"]] == [["(print \"ahaha\")"]]) | |
assert(sq2dq[["(print 'ahaha')"]] == [["(print 'ahaha')"]] ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.nyagos に直接コピペしてもいいですし、.nyagos に次のように書いてもいいです( ディレクトリの
\
は\\
に変えておくこと )コマンドラインの色付けが対応してませんが、これは仕方ないかなと…