From f46cb08f85ca36dd5e36c8c0be08936e3377f001 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 3 Jul 2026 21:31:46 +0900 Subject: [PATCH] =?UTF-8?q?is/is=20not/!=3D=E8=A6=8F=E5=89=87=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Syntax/Rules/LuaComparisonRules.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 LuaScript.Compat/Scripting/Syntax/Rules/LuaComparisonRules.cs diff --git a/LuaScript.Compat/Scripting/Syntax/Rules/LuaComparisonRules.cs b/LuaScript.Compat/Scripting/Syntax/Rules/LuaComparisonRules.cs new file mode 100644 index 0000000..c6fca2c --- /dev/null +++ b/LuaScript.Compat/Scripting/Syntax/Rules/LuaComparisonRules.cs @@ -0,0 +1,60 @@ +namespace LuaScript.Compat.Syntax.Rules +{ + [LuaSyntaxRule(10)] + internal sealed class IsNotRule : ILuaSyntaxRule + { + public bool TryApply(LuaRewriteContext context) + { + if (!context.Current.IsName("is")) + return false; + if (!context.TryPreviousOutputSignificantSameLine(out var previous) || !LuaSyntaxFacts.IsValueEnd(previous)) + return false; + + int notIndex = context.NextSignificantSameLine(context.Index + 1); + if (notIndex < 0 || !context.Input[notIndex].IsName("not")) + return false; + + int after = context.NextSignificant(notIndex + 1); + if (after < 0 || !LuaSyntaxFacts.IsValueStart(context.Input[after])) + return false; + + context.EmitOperator("~="); + context.Index = notIndex + 1; + return true; + } + } + + [LuaSyntaxRule(20)] + internal sealed class IsRule : ILuaSyntaxRule + { + public bool TryApply(LuaRewriteContext context) + { + if (!context.Current.IsName("is")) + return false; + if (!context.TryPreviousOutputSignificantSameLine(out var previous) || !LuaSyntaxFacts.IsValueEnd(previous)) + return false; + + int next = context.NextSignificantSameLine(context.Index + 1); + if (next < 0 || !LuaSyntaxFacts.IsValueStart(context.Input[next])) + return false; + + context.EmitOperator("=="); + context.Advance(); + return true; + } + } + + [LuaSyntaxRule(30)] + internal sealed class NotEqualRule : ILuaSyntaxRule + { + public bool TryApply(LuaRewriteContext context) + { + if (!context.Current.IsOperator("!=")) + return false; + + context.EmitOperator("~="); + context.Advance(); + return true; + } + } +}