Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lua/entities/gmod_wire_expression2/base/preprocessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@

function PreProcessor:FindComments(line)
local isinput = not self.blockcomment and not self.multilinestring and line:match("^@inputs") ~= nil
local isoutput = not self.blockcomment and not self.multilinestring and line:match("^@outputs") ~= nil

Check warning on line 88 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'

local ret, count, pos, found = {}, 0, 1
repeat
found = line:find((isinput or isoutput) and '[#"\\A-Z]' or '[#"\\]', pos)

Check warning on line 92 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'

Check warning on line 92 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
if found then -- We found something
local char = line:sub(found, found)
if (isinput or isoutput) and char:match("[A-Z]") ~= nil then -- we found the start of an input/output variable definition

Check warning on line 95 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
local varname, endpos = line:match("^([A-Z][A-Za-z0-9_]*)()",found)
count = count + 1
ret[count] = {type = isinput and "inputs" or "outputs", name=varname, pos=found, blockcomment = {}}
Expand Down Expand Up @@ -403,27 +403,26 @@
self.ignorestuff = true
end

-- to avoid hangs
local start_time = SysTime()
-- to avoid big hangs, 2 regex changed from 500 to 10000 to avoid false positives
local regex_limits = {[0] = 50000000, 15000, 10000, 150, 70, 40}
local timeout = SysTime() + 0.5

for i, line in ipairs(lines) do
self.readline = i

-- 2 regex changed from 500 to 10000, to avoid hangs
local ok = pcall(function() WireLib.CheckRegex(line, "^(.-)%s*$", {[0] = 50000000, 15000, 10000, 150, 70, 40}) end)
local ok = pcall(function() WireLib.CheckRegex(line, "^(.-)%s*$", regex_limits) end)
if not ok then self:Error("Line strip regex is too complex!") goto cont end

Check warning on line 414 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.

if SysTime() > start_time + 0.1 then
self:Error("Preprocessing take too long!")
break
end

line = string.TrimRight(line)
line = self:RemoveComments(line)
line = self:ParseDirectives(line)

lines[i] = line
::cont::

if SysTime() > timeout then
self:Error("Preprocessing took too long!")
break
end
end

-- convert description lookup table into an array that WireLib understands
Expand Down Expand Up @@ -464,7 +463,7 @@
if not i then
-- no -> malformed variable name
self:Error("Variable name (" .. E2Lib.limitString(key, 10) .. ") must start with an uppercase letter", tr, { { at = tr, replace = key:sub(1, 1):upper() .. key:sub(2) } })
goto cont

Check warning on line 466 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
else
-- yes -> add all variables.
for column2, var in namestring:gmatch("()([^,]+)") do
Expand Down Expand Up @@ -505,7 +504,7 @@

if vtype ~= vtype:lower() then
self:Error("Variable type [" .. E2Lib.limitString(vtype, 10) .. "] must be lowercase", tr, { { at = tr, replace = vtype:lower() } })
goto cont

Check warning on line 507 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
elseif vtype == "number" then
vtype = "normal"
elseif vtype == "normal" then
Expand All @@ -517,7 +516,7 @@
else
-- invalid -> raise an error
self:Error("Variable declaration (" .. E2Lib.limitString(key, 10) .. ") contains invalid characters", tr)
goto cont

Check warning on line 519 in lua/entities/gmod_wire_expression2/base/preprocessor.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
end

-- fill in the missing types
Expand Down
Loading