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

View File

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