nil合体演算子??規則を実装

このコミットが含まれているのは:
routersys committed 2026-07-03 21:32:10 +09:00
1 親 018999ff5e
コミット 85596f76f7
1ファイル変更
+20
+20
ファイルの表示
@@ -0,0 +1,20 @@
namespace LuaScript.Compat.Syntax.Rules
{
[LuaSyntaxRule(100)]
internal sealed class NilCoalesceRule : ILuaSyntaxRule
{
public bool TryApply(LuaRewriteContext context)
{
if (!context.Current.IsOperator("??"))
return false;
if (!context.TryPopOrOperand(out string left))
return false;
context.Advance();
string right = context.ReadForwardOrOperand();
string temporary = context.NextTemporary();
context.EmitRaw($"(function() local {temporary} = ({left}) if {temporary} ~= nil then return {temporary} else return ({right}) end end)()");
return true;
}
}
}