From 9bba7dd2cd5860c8b527f10044f7e1c4d1a4a0e2 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 14 Sep 2018 14:46:20 -0700 Subject: [PATCH] Using more concise peg file finding. --- nomsu_compiler.lua | 21 +++++++-------------- nomsu_compiler.moon | 14 ++++---------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index ea71671..bfeca01 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -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 + do + local peg_contents = Files.read("nomsu." .. tostring(version) .. ".peg") + if peg_contents then + max_parser_version = version + Parsers[version] = make_parser(peg_contents, make_tree) + else + break 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 local MAX_LINE = 80 local NomsuCompiler = setmetatable({ diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index bc6a25c..ea79843 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -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 - max_parser_version = version - peg_contents = peg_file\read("*a") - Parsers[version] = make_parser(peg_contents, make_tree) - peg_file\close! + if peg_contents = Files.read("nomsu.#{version}.peg") + max_parser_version = version + Parsers[version] = make_parser(peg_contents, make_tree) + else break MAX_LINE = 80 -- For beautification purposes, try not to make lines much longer than this value NomsuCompiler = setmetatable {name:"Nomsu"},