From 5f1c3b66d55e92f2c463a537d1ed9aa409e53f05 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Thu, 15 May 2014 23:17:36 +0000 Subject: [PATCH] Fix compiler operator precedence bugs. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1442 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleCompile.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/OvaleCompile.lua b/OvaleCompile.lua index 8b721f3..7ff066c 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -640,18 +640,40 @@ end local function ParseCommands(text) local original = text text = strgsub(text,"(%b[])", ParseLua) + while true do local was = text text = strgsub(text, "(%w+)%.?(%w*)%s*%((.-)%)", ParseFunction) text = strgsub(text, "([^%w])(%d+%.?%d*)", ParseNumber) - text = strgsub(text, "node(%d+)%s*([%*%/%%])%s*node(%d+)", ParseOp) - text = strgsub(text, "node(%d+)%s*([%+%-])%s*node(%d+)", ParseOp) text = strgsub(text, "{([node%d ]*)}", ParseGroup) if was == text then break end end - + + while true do + local was = text + while true do + local was = text + text = strgsub(text, "node(%d+)%s*([%*%/%%])%s*node(%d+)", ParseOp) + text = strgsub(text, "{([node%d ]*)}", ParseGroup) + if was == text then + break + end + end + while true do + local was = text + text = strgsub(text, "node(%d+)%s*([%+%-])%s*node(%d+)", ParseOp) + text = strgsub(text, "{([node%d ]*)}", ParseGroup) + if was == text then + break + end + end + if was == text then + break + end + end + while true do local was = text text = strgsub(text, "node(%d+)%s*([%>%<]=?)%s*node(%d+)", ParseOp) @@ -661,13 +683,33 @@ local function ParseCommands(text) break end end - + + while true do + local was = text + while true do + local was = text + text = strgsub(text, "not%s+node(%d+)", ParseNot) + text = strgsub(text, "{([node%d ]*)}", ParseGroup) + if was == text then + break + end + end + while true do + local was = text + text = strgsub(text, "node(%d+)%s+and%s+node(%d+)", ParseAnd) + text = strgsub(text, "node(%d+)%s+or%s+node(%d+)", ParseOr) + text = strgsub(text, "{([node%d ]*)}", ParseGroup) + if was == text then + break + end + end + if was == text then + break + end + end + while true do local was = text - text = strgsub(text, "not%s+node(%d+)", ParseNot) - text = strgsub(text, "node(%d+)%s*([%*%+%-%/%>%<]=?|==)%s*node(%d+)", ParseOp) - text = strgsub(text, "node(%d+)%s+and%s+node(%d+)", ParseAnd) - text = strgsub(text, "node(%d+)%s+or%s+node(%d+)", ParseOr) text = strgsub(text, "if%s+node(%d+)%s+node(%d+)",ParseIf) text = strgsub(text, "unless%s+node(%d+)%s+node(%d+)",ParseUnless) text = strgsub(text, "wait%s+node(%d+)",ParseWait) @@ -958,9 +1000,11 @@ function OvaleCompile:GetMasterNodes() return self_masterNodes end -function OvaleCompile:Debug() +function OvaleCompile:Debug(iconNumber) + iconNumber = iconNumber or 1 self_pool:Debug() - Ovale:Print(self:DebugNode(self_masterNodes[1])) + local masterNodes = self:GetMasterNodes() + Ovale:Print(self:DebugNode(masterNodes[iconNumber])) Ovale:FormatPrint("Total number of script compilations: %d", self_compileCount) end @@ -995,14 +1039,16 @@ function OvaleCompile:DebugNode(node) text = self:DebugNode(node.a).." or "..self:DebugNode(node.b) elseif (node.type == "not") then text = "not "..self:DebugNode(node.a) - elseif node.type == "operator" then + elseif node.type == "compare" then + text = self:DebugNode(node.a)..node.operator..self:DebugNode(node.b) + elseif node.type == "arithmetic" then text = self:DebugNode(node.a)..node.operator..self:DebugNode(node.b) elseif node.type == "lua" then text = "["..node.lua.."]" elseif node.type == "value" then text = node.value else - text = "#unknown node type#" + text = "#unknown node type "..node.type.."#" end return text -- 1.7.9.5