diff --git a/LuaScript.Compat/Scripting/Syntax/Rules/LuaLogicalRules.cs b/LuaScript.Compat/Scripting/Syntax/Rules/LuaLogicalRules.cs new file mode 100644 index 0000000..ca0a0ba --- /dev/null +++ b/LuaScript.Compat/Scripting/Syntax/Rules/LuaLogicalRules.cs @@ -0,0 +1,44 @@ +namespace LuaScript.Compat.Syntax.Rules +{ + [LuaSyntaxRule(40)] + internal sealed class LogicalNotRule : ILuaSyntaxRule + { + public bool TryApply(LuaRewriteContext context) + { + if (!context.Current.IsOperator("!")) + return false; + + context.Advance(); + context.EmitWord("not"); + return true; + } + } + + [LuaSyntaxRule(50)] + internal sealed class AndAliasRule : ILuaSyntaxRule + { + public bool TryApply(LuaRewriteContext context) + { + if (!context.Current.IsOperator("&&")) + return false; + + context.Advance(); + context.EmitWord("and"); + return true; + } + } + + [LuaSyntaxRule(60)] + internal sealed class OrAliasRule : ILuaSyntaxRule + { + public bool TryApply(LuaRewriteContext context) + { + if (!context.Current.IsOperator("||")) + return false; + + context.Advance(); + context.EmitWord("or"); + return true; + } + } +}