aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.lua
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-10-29 13:00:08 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-10-29 13:00:30 -0700
commit23abab4f809e8d4b825746580082292db700036b (patch)
tree8eb95a3b781547abedadd08705a6e6291662737c /nomsu_compiler.lua
parentbe1df7ccd3fb5352ca666129aee93c56b5b27b40 (diff)
Some cleanups and fixes, made the parser more permissive of prematurely
terminated files.
Diffstat (limited to 'nomsu_compiler.lua')
-rw-r--r--nomsu_compiler.lua28
1 files changed, 16 insertions, 12 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index ff923ab..3d0580a 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -129,17 +129,21 @@ make_tree = function(tree, userdata)
return tree
end
local Parsers = { }
-local max_parser_version = 0
-for version = 1, 999 do
- 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
+local max_parser_version = 4
+for version = 1, max_parser_version 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
+ assert(peg_file, "could not find nomsu .peg file")
+ local peg_contents = peg_file:read('*a')
+ peg_file:close()
+ Parsers[version] = make_parser(peg_contents, make_tree)
end
local MAX_LINE = 80
local NomsuCompiler = setmetatable({ }, {
@@ -199,9 +203,8 @@ do
re = re,
Files = Files,
AST = AST,
- TESTS = Dict({ }, {
- globals = Dict({ })
- }),
+ TESTS = Dict({ }),
+ globals = Dict({ }),
LuaCode = LuaCode,
NomsuCode = NomsuCode,
Source = Source,
@@ -209,6 +212,7 @@ do
__imported = Dict({ }),
__parent = nil
}
+ assert(NomsuCompiler.environment.globals)
setmetatable(NomsuCompiler.environment, {
__index = function(self, key)
do