Moving to better, more centralized versioning system. Now the Nomsu

version is just defined as a list at the top of nomsu.moon, and uses
X.Y.Z form instead of X.Y.Z.W. Added a ([...], from 2) method and a
([...], up to 5) method, and fixed a few upgrade bugs.
This commit is contained in:
Bruce Hill 2019-02-06 15:33:10 -08:00
parent 618e48ad98
commit 057f5b74eb
14 changed files with 90 additions and 76 deletions

View File

@ -84,7 +84,7 @@ install: lua version optimize optimize_extra
fi; \ fi; \
version="`cat version`"; \ version="`cat version`"; \
mkdir -pv $$prefix/bin $$prefix/lib/nomsu/$$version $$prefix/share/nomsu/$$version $$prefix/share/man/man1 $$packagepath/nomsu \ mkdir -pv $$prefix/bin $$prefix/lib/nomsu/$$version $$prefix/share/nomsu/$$version $$prefix/share/man/man1 $$packagepath/nomsu \
&& echo "#!$(LUA_BIN)\\nlocal NOMSU_VERSION, NOMSU_PREFIX, NOMSU_PACKAGEPATH = [[$$version]], [[$$prefix]], [[$$packagepath/nomsu]]" \ && echo "#!$(LUA_BIN)\\nlocal NOMSU_PREFIX, NOMSU_PACKAGEPATH = [[$$prefix]], [[$$packagepath/nomsu]]" \
| cat - nomsu.lua > $$prefix/bin/nomsu$$version \ | cat - nomsu.lua > $$prefix/bin/nomsu$$version \
&& chmod +x $$prefix/bin/nomsu$$version \ && chmod +x $$prefix/bin/nomsu$$version \
&& cp -v nomsu $$prefix/bin \ && cp -v nomsu $$prefix/bin \

View File

@ -72,16 +72,9 @@ All `.moon` files have been precompiled into corresponding `.lua` files, so you
## Versioning ## Versioning
Nomsu uses the following versioning scheme: `[syntax version].[core library API version].[compiler internal API version].[minor version]`. Which means:
* Any code that parses on `Nomsu X.a.b.c` will also parse on Nomsu `X.p.w.r`
* Any code that compiles on Nomsu `X.Y.a.b` will also compile on Nomsu `X.Y.p.q` and run without any differences, as long as it only depends on the behavior of the core library functions (i.e. stuff defined in [lib/core/\*.nom](lib/core)), and doesn't mess with the compiler internals at all.
* Any code that compiles on Nomsu `X.Y.Z.a` will also compile on Nomsu `X.Y.Z.p` and run without any differences, unless if it messes with the compiler internals.
* Any code that compiles on Nomsu `X.Y.Z.W` will also compile on any other Nomsu `X.Y.Z.W` and run without any differences.
When Nomsu is istalled via `make install`, all of Nomsu's lua files and [lib/](lib) files are stored in `$PREFIX/share/nomsu/$NOMSU_VERSION` and the Nomsu executable is installed to `$PREFIX/bin/nomsu$NOMSU_VERSION`, along with the file `nomsu` (the version-selection script), which goes to `$PREFIX/bin/nomsu`. When `make uninstall` is run, all those files are deleted (except for `nomsu`, if there are other versions installed). When Nomsu is istalled via `make install`, all of Nomsu's lua files and [lib/](lib) files are stored in `$PREFIX/share/nomsu/$NOMSU_VERSION` and the Nomsu executable is installed to `$PREFIX/bin/nomsu$NOMSU_VERSION`, along with the file `nomsu` (the version-selection script), which goes to `$PREFIX/bin/nomsu`. When `make uninstall` is run, all those files are deleted (except for `nomsu`, if there are other versions installed).
To run different versions, use the `-V` flag, which will select the latest version matching the specified pattern. For example, if you have v1.0.0.0, v1.0.2.1, and 1.1.0.0 installed, then `nomsu` will run v1.1.0.0, `nomsu -V 1.0` will run v1.0.2.1, and `nomsu -V 1.0.0.0` will run v1.0.0.0. To run different versions, use the `-V` flag, which will select the latest version matching the specified pattern. For example, if you have v1.0.0, v1.0.2, and 1.1.0 installed, then `nomsu` will run v1.1.0, `nomsu -V1.0` will run v1.0.2, and `nomsu -V 1.0.0` will run v1.0.0.
## Extra ## Extra

View File

@ -226,6 +226,12 @@ local _list_mt = {
return _accum_0 return _accum_0
end)()) end)())
end, end,
from = function(self, start)
return self:from_1_to(start, -1)
end,
up_to = function(self, stop)
return self:from_1_to(1, stop)
end,
copy = function(self) copy = function(self)
return List((function() return List((function()
local _accum_0 = { } local _accum_0 = { }

View File

@ -88,6 +88,8 @@ _list_mt =
start = (n+1-start) if start < 0 start = (n+1-start) if start < 0
stop = (n+1-stop) if stop < 0 stop = (n+1-stop) if stop < 0
return List[@[i] for i=start,stop] return List[@[i] for i=start,stop]
from: (start)=> @from_1_to(start, -1)
up_to: (stop)=> @from_1_to(1, stop)
copy: => List[@[i] for i=1,#@] copy: => List[@[i] for i=1,#@]
reverse: => reverse: =>
n = #@ n = #@

View File

@ -1,5 +1,5 @@
#!/usr/bin/env nomsu -V7 #!/usr/bin/env nomsu -V7
# ###
This file defines upgrades from Nomsu <7 to 7 This file defines upgrades from Nomsu <7 to 7
use "compatibility/compatibility" use "compatibility/compatibility"
@ -22,3 +22,13 @@ upgrade $tree to "7" as:
return return
"Action" tree from $tree.source with ("Text" tree with $e.type) "tree" "with" "Action" tree from $tree.source with ("Text" tree with $e.type) "tree" "with"
unpack $e unpack $e
upgrade action "Nomsu version" to "7" via ->(`$(NOMSU VERSION))
upgrade action [
"Nomsu syntax version", "Nomsu compiler version", "core version", "lib version"
] to "7" via:
for $:
at $.source fail ("
Deprecation error: Actions for accessing specific parts of the version number have been deprecated.
Hint: Use $(NOMSU VERSION).1, etc. instead.
")

View File

@ -70,8 +70,15 @@ external:
$tree upgraded to $end_version from $start_version $tree upgraded to $end_version from $start_version
] all mean: ] all mean:
unless ($tree is syntax tree): return $tree unless ($tree is syntax tree): return $tree
($ver as version list) means (($ as number) for $ in $ver matching "[0-9]+") ($ver as version list) means:
if ($ver is "Text"):
return (($ as number) for $ in $ver matching "[0-9]+")
return $ver
(Ver $) means: (Ver $) means:
if ($ is "a List"):
if ($.1 is "Text"):
return {.lib = $.1, .version = ($, from 2)}
return {.version = $}
[$lib, $ver] = ($, match "(.*)/([0-9.]+)") [$lib, $ver] = ($, match "(.*)/([0-9.]+)")
if $lib: if $lib:
return {.lib = $lib, .version = ($ver as version list)} return {.lib = $lib, .version = ($ver as version list)}
@ -117,15 +124,15 @@ external:
$tree = (SyntaxTree {: for $k = $v in $tree: add $k = $v}) $tree = (SyntaxTree {: for $k = $v in $tree: add $k = $v})
$tree.version = $end_version $tree.version = $end_version
if $tree.shebang: if $tree.shebang:
$tree.shebang = "#!/usr/bin/env nomsu -V\$end_version\n" $tree.shebang = "#!/usr/bin/env nomsu -V\($end_version, joined with ".")\n"
return $tree return $tree
($tree upgraded from $start_version) means ($tree upgraded from $start_version) means
$tree upgraded from $start_version to (Nomsu version) $tree upgraded from $start_version to $(NOMSU VERSION)
($tree upgraded to $end_version) means ($tree upgraded to $end_version) means
$tree upgraded from ($tree.version or (Nomsu version)) to $end_version $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $end_version
($tree upgraded) means ($tree upgraded) means
$tree upgraded from ($tree.version or (Nomsu version)) to (Nomsu version) $tree upgraded from ($tree.version or $(NOMSU VERSION)) to $(NOMSU VERSION)

View File

@ -17,3 +17,6 @@ export "compatibility/4.11"
export "compatibility/4.12" export "compatibility/4.12"
export "compatibility/5.13" export "compatibility/5.13"
export "compatibility/6.14" export "compatibility/6.14"
export "compatibility/6.15"
export "compatibility/6.15.9"
export "compatibility/7"

View File

@ -3,8 +3,6 @@
This File contains actions for making actions and compile-time actions and some helper This File contains actions for making actions and compile-time actions and some helper
functions to make that easier. functions to make that easier.
lua> "NOMSU_CORE_VERSION = 15"
lua> "NOMSU_LIB_VERSION = 9"
lua> (" lua> ("
do do
local mangle_index = 0 local mangle_index = 0
@ -462,10 +460,6 @@ test:
(yes) compiles to "(true)" (yes) compiles to "(true)"
(no) compiles to "(false)" (no) compiles to "(false)"
[nothing, nil, null] all compile to "(nil)" [nothing, nil, null] all compile to "(nil)"
(Nomsu syntax version) compiles to "NOMSU_SYNTAX_VERSION"
(Nomsu compiler version) compiles to "NOMSU_COMPILER_VERSION"
(core version) compiles to "NOMSU_CORE_VERSION"
(lib version) compiles to "NOMSU_LIB_VERSION"
(command line args) compiles to "COMMAND_LINE_ARGS" (command line args) compiles to "COMMAND_LINE_ARGS"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -496,12 +490,6 @@ test:
return lua return lua
") ")
external:
(Nomsu version) means:
return ("
\(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
")
~~~~ ~~~~
# TODO: Remove shim # TODO: Remove shim
($tree with $t -> $replacement) parses as ($tree with $t -> $replacement) parses as

View File

@ -11,7 +11,7 @@ use "commandline"
external: external:
(help) means: (help) means:
say (" say ("
This is the Nomsu v\(Nomsu version) interactive console. This is the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console.
You can type in Nomsu code here and hit 'enter' twice to run it. You can type in Nomsu code here and hit 'enter' twice to run it.
To exit, type 'exit' or 'quit' and hit enter twice. To exit, type 'exit' or 'quit' and hit enter twice.
") ")
@ -23,7 +23,7 @@ external:
command line program with $args: command line program with $args:
say (" say ("
\(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\ \(bright)\(underscore)Welcome to the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console!\
..\(reset color) ..\(reset color)
press 'enter' twice to run a command press 'enter' twice to run a command
type 'tutorial' to run the tutorial type 'tutorial' to run the tutorial

View File

@ -20,7 +20,7 @@ command line program with $args:
use $start_version use $start_version
..if it fails: ..if it fails:
fail "Could not find upgrade rules for \$start_version" fail "Could not find upgrade rules for \$start_version"
$version = ($args."upgrade-to" or (Nomsu version)) $version = ($args."upgrade-to" or $(NOMSU VERSION))
$test = ($args.t or $args.test) $test = ($args.t or $args.test)
for $filename in $args.extras: for $filename in $args.extras:
$file = (read file $filename) $file = (read file $filename)
@ -30,7 +30,7 @@ command line program with $args:
$code = (NomsuCode from (Source $filename 1 (size of $file)) $file) $code = (NomsuCode from (Source $filename 1 (size of $file)) $file)
$tree = ($code parsed $start_version) $tree = ($code parsed $start_version)
$uptree = $uptree =
$tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to $tree upgraded from ($start_version or ($tree.version or $(NOMSU VERSION))) to
$version $version
$text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")" $text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"
when: when:

View File

@ -1,4 +1,13 @@
NOMSU_VERSION = {
7,
0,
0
}
local clibtype = package.cpath:match("?%.(so)") or package.cpath:match("?%.(dll)") local clibtype = package.cpath:match("?%.(so)") or package.cpath:match("?%.(dll)")
if NOMSU_PREFIX then
package.path = tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(table.concat(NOMSU_VERSION, ".")) .. "/?.lua;" .. package.path
package.cpath = tostring(NOMSU_PREFIX) .. "/lib/nomsu/" .. tostring(table.concat(NOMSU_VERSION, ".")) .. "/?." .. tostring(clibtype) .. ";" .. package.cpath
end
COLOR_ENABLED = true COLOR_ENABLED = true
if clibtype == "dll" then if clibtype == "dll" then
local enable_colors = require('wincolors') local enable_colors = require('wincolors')
@ -8,10 +17,14 @@ if clibtype == "dll" then
end end
os.execute("chcp 65001>nul") os.execute("chcp 65001>nul")
end end
if NOMSU_VERSION and NOMSU_PREFIX then local List, Dict
package.path = tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION) .. "/?.lua;" .. package.path do
package.cpath = tostring(NOMSU_PREFIX) .. "/lib/nomsu/" .. tostring(NOMSU_VERSION) .. "/?." .. tostring(clibtype) .. ";" .. package.cpath local _obj_0 = require('containers')
List, Dict = _obj_0.List, _obj_0.Dict
end end
NOMSU_VERSION = List(NOMSU_VERSION)
local Text = require('text')
require('builtin_metatables')
local usage = [=[Nomsu Compiler local usage = [=[Nomsu Compiler
Usage: (nomsu | lua nomsu.lua | moon nomsu.moon) [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]] Usage: (nomsu | lua nomsu.lua | moon nomsu.moon) [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]]
@ -44,13 +57,6 @@ do
local _obj_0 = require("code_obj") local _obj_0 = require("code_obj")
NomsuCode, LuaCode, Source = _obj_0.NomsuCode, _obj_0.LuaCode, _obj_0.Source NomsuCode, LuaCode, Source = _obj_0.NomsuCode, _obj_0.LuaCode, _obj_0.Source
end end
local List, Dict
do
local _obj_0 = require('containers')
List, Dict = _obj_0.List, _obj_0.Dict
end
local Text = require('text')
require('builtin_metatables')
local sep = "\3" local sep = "\3"
local parser = re.compile([[ args <- {| (flag %sep)* local parser = re.compile([[ args <- {| (flag %sep)*
{:files: {| {:files: {|
@ -98,6 +104,10 @@ if not args or err or args.help then
print(usage) print(usage)
os.exit(EXIT_FAILURE) os.exit(EXIT_FAILURE)
end end
if args.version then
print(NOMSU_VERSION:joined_with("."))
os.exit(EXIT_SUCCESS)
end
local nomsu_args = Dict({ }) local nomsu_args = Dict({ })
local _list_0 = args.nomsu_args local _list_0 = args.nomsu_args
for _index_0 = 1, #_list_0 do for _index_0 = 1, #_list_0 do
@ -128,8 +138,8 @@ add_path = function(p)
table.insert(nomsupath, p .. "/" .. s) table.insert(nomsupath, p .. "/" .. s)
end end
end end
if NOMSU_VERSION and NOMSU_PREFIX then if NOMSU_PREFIX then
add_path(tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION) .. "/lib") add_path(tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION:joined_with(".")) .. "/lib")
else else
add_path("./lib") add_path("./lib")
end end
@ -139,6 +149,7 @@ add_path(".")
package.nomsupath = table.concat(nomsupath, ";") package.nomsupath = table.concat(nomsupath, ";")
package.nomsuloaded = Dict({ }) package.nomsuloaded = Dict({ })
local nomsu_environment = require('nomsu_environment') local nomsu_environment = require('nomsu_environment')
nomsu_environment.NOMSU_VERSION = NOMSU_VERSION
nomsu_environment.COMMAND_LINE_ARGS = nomsu_args nomsu_environment.COMMAND_LINE_ARGS = nomsu_args
nomsu_environment.OPTIMIZATION = optimization nomsu_environment.OPTIMIZATION = optimization
nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH
@ -149,10 +160,6 @@ run = function()
if not (args.no_core) then if not (args.no_core) then
nomsu_environment:export("core") nomsu_environment:export("core")
end end
if args.version then
nomsu_environment:run("say (Nomsu version)")
os.exit(EXIT_SUCCESS)
end
local input_files = { } local input_files = { }
if args.files then if args.files then
local _list_1 = args.files local _list_1 = args.files

View File

@ -1,7 +1,14 @@
#!/usr/bin/env moon #!/usr/bin/env moon
-- This file contains the command-line Nomsu runner. -- This file contains the command-line Nomsu runner.
export NOMSU_VERSION
NOMSU_VERSION = {7, 0, 0}
clibtype = package.cpath\match("?%.(so)") or package.cpath\match("?%.(dll)") clibtype = package.cpath\match("?%.(so)") or package.cpath\match("?%.(dll)")
if NOMSU_PREFIX
package.path = "#{NOMSU_PREFIX}/share/nomsu/#{table.concat NOMSU_VERSION, "."}/?.lua;"..package.path
package.cpath = "#{NOMSU_PREFIX}/lib/nomsu/#{table.concat NOMSU_VERSION, "."}/?.#{clibtype};"..package.cpath
export COLOR_ENABLED export COLOR_ENABLED
COLOR_ENABLED = true COLOR_ENABLED = true
if clibtype == "dll" if clibtype == "dll"
@ -13,9 +20,10 @@ if clibtype == "dll"
-- Special hack to enable utf8 for windows console applications: -- Special hack to enable utf8 for windows console applications:
os.execute("chcp 65001>nul") os.execute("chcp 65001>nul")
if NOMSU_VERSION and NOMSU_PREFIX {:List, :Dict} = require 'containers'
package.path = "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION}/?.lua;"..package.path NOMSU_VERSION = List(NOMSU_VERSION)
package.cpath = "#{NOMSU_PREFIX}/lib/nomsu/#{NOMSU_VERSION}/?.#{clibtype};"..package.cpath Text = require 'text'
require 'builtin_metatables'
usage = [=[ usage = [=[
Nomsu Compiler Nomsu Compiler
@ -46,9 +54,6 @@ if not ok
os.exit(EXIT_FAILURE) os.exit(EXIT_FAILURE)
Files = require "files" Files = require "files"
{:NomsuCode, :LuaCode, :Source} = require "code_obj" {:NomsuCode, :LuaCode, :Source} = require "code_obj"
{:List, :Dict} = require 'containers'
Text = require 'text'
require 'builtin_metatables'
sep = "\3" sep = "\3"
parser = re.compile([[ parser = re.compile([[
@ -94,6 +99,9 @@ if not args or err or args.help
print("Didn't understand: #{err}") print("Didn't understand: #{err}")
print usage print usage
os.exit(EXIT_FAILURE) os.exit(EXIT_FAILURE)
if args.version
print(NOMSU_VERSION\joined_with("."))
os.exit(EXIT_SUCCESS)
nomsu_args = Dict{} nomsu_args = Dict{}
for argpair in *args.nomsu_args for argpair in *args.nomsu_args
nomsu_args[argpair.key] = argpair.value nomsu_args[argpair.key] = argpair.value
@ -106,8 +114,8 @@ suffixes = if optimization > 0
else {"?.nom", "?/init.nom"} else {"?.nom", "?/init.nom"}
add_path = (p)-> add_path = (p)->
for s in *suffixes do table.insert(nomsupath, p.."/"..s) for s in *suffixes do table.insert(nomsupath, p.."/"..s)
if NOMSU_VERSION and NOMSU_PREFIX if NOMSU_PREFIX
add_path "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION}/lib" add_path "#{NOMSU_PREFIX}/share/nomsu/#{NOMSU_VERSION\joined_with(".")}/lib"
else else
add_path "./lib" add_path "./lib"
NOMSU_PACKAGEPATH or= "/opt/nomsu" NOMSU_PACKAGEPATH or= "/opt/nomsu"
@ -117,6 +125,7 @@ package.nomsupath = table.concat(nomsupath, ";")
package.nomsuloaded = Dict{} package.nomsuloaded = Dict{}
nomsu_environment = require('nomsu_environment') nomsu_environment = require('nomsu_environment')
nomsu_environment.NOMSU_VERSION = NOMSU_VERSION
nomsu_environment.COMMAND_LINE_ARGS = nomsu_args nomsu_environment.COMMAND_LINE_ARGS = nomsu_args
nomsu_environment.OPTIMIZATION = optimization nomsu_environment.OPTIMIZATION = optimization
nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH
@ -127,10 +136,6 @@ run = ->
unless args.no_core unless args.no_core
nomsu_environment\export("core") nomsu_environment\export("core")
if args.version
nomsu_environment\run("say (Nomsu version)")
os.exit(EXIT_SUCCESS)
input_files = {} input_files = {}
if args.files if args.files
for f in *args.files for f in *args.files

View File

@ -23,8 +23,7 @@ make_tree = function(tree, userdata)
return tree return tree
end end
local Parsers = { } local Parsers = { }
local max_parser_version = 0 for version = 1, NOMSU_VERSION[1] do
for version = 1, 999 do
local peg_file local peg_file
if package.nomsupath then if package.nomsupath then
local pegpath = package.nomsupath:gsub("lib/%?%.nom", "?.peg"):gsub("lib/%?%.lua", "?.peg") local pegpath = package.nomsupath:gsub("lib/%?%.nom", "?.peg"):gsub("lib/%?%.lua", "?.peg")
@ -37,10 +36,7 @@ for version = 1, 999 do
else else
peg_file = io.open("nomsu." .. tostring(version) .. ".peg") peg_file = io.open("nomsu." .. tostring(version) .. ".peg")
end end
if not (peg_file) then assert(peg_file, "No PEG file found for Nomsu version " .. tostring(version))
break
end
max_parser_version = version
local peg_contents = peg_file:read('*a') local peg_contents = peg_file:read('*a')
peg_file:close() peg_file:close()
Parsers[version] = make_parser(peg_contents, make_tree) Parsers[version] = make_parser(peg_contents, make_tree)
@ -87,8 +83,6 @@ _1_as_list = function(x)
end end
local nomsu_environment local nomsu_environment
nomsu_environment = Importer({ nomsu_environment = Importer({
NOMSU_COMPILER_VERSION = 13,
NOMSU_SYNTAX_VERSION = max_parser_version,
next = next, next = next,
unpack = unpack or table.unpack, unpack = unpack or table.unpack,
setmetatable = setmetatable, setmetatable = setmetatable,
@ -171,8 +165,9 @@ nomsu_environment = Importer({
if syntax_version then if syntax_version then
syntax_version = tonumber(syntax_version:match("^[0-9]+")) syntax_version = tonumber(syntax_version:match("^[0-9]+"))
end end
syntax_version = syntax_version or (version and tonumber(version:match("^[0-9]+")) or max_parser_version) syntax_version = syntax_version or (version and tonumber(version:match("^[0-9]+")) or NOMSU_VERSION[1])
local parse = Parsers[syntax_version] or Parsers[max_parser_version] local parse = Parsers[syntax_version]
assert(parse, "No parser found for Nomsu syntax version " .. tostring(syntax_version))
local tree = parse(nomsu_code, source.filename) local tree = parse(nomsu_code, source.filename)
if tree.shebang then if tree.shebang then
tree.version = tree.version or tree.shebang:match("nomsu %-V[ ]*([%d.]*)") tree.version = tree.version or tree.shebang:match("nomsu %-V[ ]*([%d.]*)")

View File

@ -17,8 +17,7 @@ make_tree = (tree, userdata)->
return tree return tree
Parsers = {} Parsers = {}
max_parser_version = 0 for version=1,NOMSU_VERSION[1]
for version=1,999
local peg_file local peg_file
if package.nomsupath if package.nomsupath
pegpath = package.nomsupath\gsub("lib/%?%.nom", "?.peg")\gsub("lib/%?%.lua", "?.peg") pegpath = package.nomsupath\gsub("lib/%?%.nom", "?.peg")\gsub("lib/%?%.lua", "?.peg")
@ -26,8 +25,7 @@ for version=1,999
peg_file = io.open(path) peg_file = io.open(path)
else else
peg_file = io.open("nomsu.#{version}.peg") peg_file = io.open("nomsu.#{version}.peg")
break unless peg_file assert peg_file, "No PEG file found for Nomsu version #{version}"
max_parser_version = version
peg_contents = peg_file\read('*a') peg_contents = peg_file\read('*a')
peg_file\close! peg_file\close!
Parsers[version] = make_parser(peg_contents, make_tree) Parsers[version] = make_parser(peg_contents, make_tree)
@ -53,7 +51,6 @@ _1_as_list = (x)->
local nomsu_environment local nomsu_environment
nomsu_environment = Importer{ nomsu_environment = Importer{
NOMSU_COMPILER_VERSION: 13, NOMSU_SYNTAX_VERSION: max_parser_version
-- Lua stuff: -- Lua stuff:
:next, unpack: unpack or table.unpack, :setmetatable, :rawequal, :getmetatable, :pcall, :next, unpack: unpack or table.unpack, :setmetatable, :rawequal, :getmetatable, :pcall,
yield:coroutine.yield, resume:coroutine.resume, coroutine_status_of:coroutine.status, yield:coroutine.yield, resume:coroutine.resume, coroutine_status_of:coroutine.status,
@ -89,8 +86,9 @@ nomsu_environment = Importer{
version = nomsu_code\match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)") version = nomsu_code\match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
if syntax_version if syntax_version
syntax_version = tonumber(syntax_version\match("^[0-9]+")) syntax_version = tonumber(syntax_version\match("^[0-9]+"))
syntax_version or= version and tonumber(version\match("^[0-9]+")) or max_parser_version syntax_version or= version and tonumber(version\match("^[0-9]+")) or NOMSU_VERSION[1]
parse = Parsers[syntax_version] or Parsers[max_parser_version] parse = Parsers[syntax_version]
assert parse, "No parser found for Nomsu syntax version #{syntax_version}"
tree = parse(nomsu_code, source.filename) tree = parse(nomsu_code, source.filename)
if tree.shebang if tree.shebang
tree.version or= tree.shebang\match("nomsu %-V[ ]*([%d.]*)") tree.version or= tree.shebang\match("nomsu %-V[ ]*([%d.]*)")