我一直在使用lunadry为我重新格式化我的代码,但是我遇到了错误,即当我尝试时会发生这种情况:
lua: ./lunadry.lua:322: assertion failed!
stack traceback:
[C]: in function 'assert'
./lunadry.lua:322: in main chunk
[C]: in ?
现在我已经浏览了大量的代码,并将此错误的来源追溯到此特定功能......
function e.insertvalues(e,...)g(1,e,'table')local n,t
if y('#',...)==1 then
n,t=#e+1,...else
n,t=...end
if#t>0 then
for n=#e,n,-1 do
e[n+#t]=e[n]end
local i=1-n
for n=n,n+#t-1 do
e[n]=t[n+i]end
end
return e
end
(是的,它应该看起来像那样丑陋)。
更具体地说,取出这段代码使其再次起作用:
if y('#',...)==1 then
n,t=#e+1,...else
n,t=...end
正是...... else和......结束位导致它搞乱。
我一直试图让它重新格式化代码,因此它看起来很漂亮,但它会导致错误。据我所知,在作者的代码中只能复制一个错误的海洋,但我希望不会。这是魔术文件的来源:click me。
有人可以看看这个,并告诉我需要改变什么,解决这个非常烦人的错误?谢谢!
答案 0 :(得分:2)
这是因为...
与关键字匹配所致。例如,lunadry.lua
:
K "..."
应该是
C "..."
使用此补丁:
diff --git a/lunadry.lua b/lunadry.lua
index e056140..19d714b 100755
--- a/lunadry.lua
+++ b/lunadry.lua
@@ -201,7 +201,7 @@ local lua = lpeg.locale {
K "true" +
V "Number" +
V "String" +
- K "..." +
+ C "..." +
V "function" +
V "tableconstructor" +
V "functioncall" +
@@ -251,8 +251,8 @@ local lua = lpeg.locale {
funcbody = C "(" * V "whitespace" * (V "parlist" * V "whitespace")^-1 * C ")" * INDENT_INCREASE(V "block" * V "whitespace") * INDENT * K "end";
- parlist = V "namelist" * (V "whitespace" * C "," * SPACE * V "whitespace" * K "...")^-1 +
- K "...";
+ parlist = V "namelist" * (V "whitespace" * C "," * SPACE * V "whitespace" * C "...")^-1 +
+ C "...";
tableconstructor = FLATTEN(C "{" * (INDENT_INCREASE(V "filler" * V "fieldlist" * V "filler") * INDENT + V "filler") * C "}");
我将在今天晚些时候提交修复。