Using more concise peg file finding.

This commit is contained in:
Bruce Hill 2018-09-14 14:46:20 -07:00
parent d428725c86
commit 9bba7dd2cd
2 changed files with 11 additions and 24 deletions

View File

@ -130,22 +130,15 @@ end
local Parsers = { }
local max_parser_version = 0
for version = 1, 999 do
local peg_file = io.open("nomsu." .. tostring(version) .. ".peg")
if not peg_file and package.nomsupath then
for path in package.nomsupath:gmatch("[^;]+") do
peg_file = io.open(path .. "/nomsu." .. tostring(version) .. ".peg")
if peg_file then
break
end
end
end
if not (peg_file) then
break
end
do
local peg_contents = Files.read("nomsu." .. tostring(version) .. ".peg")
if peg_contents then
max_parser_version = version
local peg_contents = peg_file:read("*a")
Parsers[version] = make_parser(peg_contents, make_tree)
peg_file:close()
else
break
end
end
end
local MAX_LINE = 80
local NomsuCompiler = setmetatable({

View File

@ -78,16 +78,10 @@ make_tree = (tree, userdata)->
Parsers = {}
max_parser_version = 0
for version=1,999
peg_file = io.open("nomsu.#{version}.peg")
if not peg_file and package.nomsupath
for path in package.nomsupath\gmatch("[^;]+")
peg_file = io.open(path.."/nomsu.#{version}.peg")
break if peg_file
break unless peg_file
if peg_contents = Files.read("nomsu.#{version}.peg")
max_parser_version = version
peg_contents = peg_file\read("*a")
Parsers[version] = make_parser(peg_contents, make_tree)
peg_file\close!
else break
MAX_LINE = 80 -- For beautification purposes, try not to make lines much longer than this value
NomsuCompiler = setmetatable {name:"Nomsu"},