From f3256668c25af76382c6b0aa8a2c0cbba3af534e Mon Sep 17 00:00:00 2001 From: NiteHawk Date: Tue, 10 Apr 2018 14:53:17 +0200 Subject: [PATCH 1/2] Factor out a callexpr() function to de-duplicate code --- minify.lua | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/minify.lua b/minify.lua index 41d7a60..a436edb 100644 --- a/minify.lua +++ b/minify.lua @@ -752,6 +752,20 @@ function CreateLuaParser(text) end end + local function callexpr(base) + return MkNode{ + Type = 'CallExpr'; + Base = base; + FunctionArguments = functionargs(); + GetFirstToken = function(self) + return self.Base:GetFirstToken() + end; + GetLastToken = function(self) + return self.FunctionArguments:GetLastToken() + end; + } + end + local function primaryexpr() local base = prefixexpr() assert(base, "nil prefixexpr") @@ -807,29 +821,9 @@ function CreateLuaParser(text) end; } elseif tk.Source == '{' then - base = MkNode{ - Type = 'CallExpr'; - Base = base; - FunctionArguments = functionargs(); - GetFirstToken = function(self) - return self.Base:GetFirstToken() - end; - GetLastToken = function(self) - return self.FunctionArguments:GetLastToken() - end; - } + base = callexpr(base) -- TableCall elseif tk.Source == '(' then - base = MkNode{ - Type = 'CallExpr'; - Base = base; - FunctionArguments = functionargs(); - GetFirstToken = function(self) - return self.Base:GetFirstToken() - end; - GetLastToken = function(self) - return self.FunctionArguments:GetLastToken() - end; - } + base = callexpr(base) -- ArgCall else return base end From 7f607a08f0a95219fd4eabf4eb0bc21c19488dde Mon Sep 17 00:00:00 2001 From: NiteHawk Date: Thu, 12 Apr 2018 17:16:53 +0200 Subject: [PATCH 2/2] Modify the parser to handle "string call" function invocation Lua syntax allows specifying function calls without parentheses if a single, string-type argument follows. e.g.: require "math" functionargs() is prepared for this (CallType = 'StringCall'), but the higher level primaryexpr() parser didn't arrange for it to be recognized as a valid 'CallExpr'. This commit fixes that. --- minify.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/minify.lua b/minify.lua index a436edb..f26124b 100644 --- a/minify.lua +++ b/minify.lua @@ -824,6 +824,8 @@ function CreateLuaParser(text) base = callexpr(base) -- TableCall elseif tk.Source == '(' then base = callexpr(base) -- ArgCall + elseif tk.Type == 'String' then + base = callexpr(base) -- StringCall else return base end