Fixed some bugs, including upgrade --upgrade-from=version not working.

Also updated the README.
This commit is contained in:
Bruce Hill 2018-12-14 20:34:27 -08:00
parent 4fe63f253f
commit d30f6a397d
5 changed files with 24 additions and 21 deletions

View File

@ -2,7 +2,8 @@
Nomsu (named after **Nom**ic, and its creator, Peter **Su**ber) is a programming language
designed to be used for playing games of [Nomic](https://en.wikipedia.org/wiki/Nomic), or engaging in other similar activities
revolving around natural language rule-making and self modification.
revolving around natural language rule-making and self modification. More information is
available at [Nomsu's homepage](https://nomsu.org).
## Dependencies
@ -21,17 +22,17 @@ There's a more complete set of example code in [examples/how\_do\_i.nom](example
```
say "Hello"
%my_nums = [5, 23, 42]
for %num in %my_nums:
say "\%num is one of my nums"
$my_nums = [5, 23, 42]
for $num in $my_nums:
say "\$num is one of my nums"
(sing %n bottles of beer) means:
for %i in %n to 1 by -1:
say "\
..\%i bottle\("s" if (%i > 1) else "") of beer on the wall,
\%i bottle\("s" if (%i > 1) else "") of beer!
(sing $n bottles of beer) means:
for $i in $n to 1 by -1:
say "
\$i bottle\("s" if ($i > 1) else "") of beer on the wall,
\$i bottle\("s" if ($i > 1) else "") of beer!
Take one down, pass it around..."
say "No bottles of beer on the wall. Go to the store, buy some more..."
say "No bottles of beer on the wall."
sing 99 bottles of beer
```

View File

@ -301,10 +301,7 @@ externally ($ is $kind syntax tree) means (..)
($tree with $t -> $replacement) compiles to "
\($tree as lua expr):map(function(\($t as lua expr))
\(..)
($replacement as lua) if ($replacement.type == "Block") else \
.."return \($replacement as lua expr)"
..
\(=lua "\$replacement.type == 'Block' and \($replacement as lua) or 'return '..\($replacement as lua expr)")
end)"
externally ($tree with vars $replacements) means (..)

View File

@ -137,7 +137,7 @@ local nomsu_environment = Importer({
compile_error_at = compile_error,
_1_forked = _1_forked,
import_to_1_from = import_to_1_from,
_1_parsed = function(nomsu_code)
_1_parsed = function(nomsu_code, syntax_version)
if type(nomsu_code) == 'string' then
local filename = Files.spoof(nomsu_code)
nomsu_code = NomsuCode:from(Source(filename, 1, #nomsu_code), nomsu_code)
@ -145,11 +145,14 @@ local nomsu_environment = Importer({
local source = nomsu_code.source
nomsu_code = tostring(nomsu_code)
local version = nomsu_code:match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
local syntax_version = version and tonumber(version:match("^[0-9]+")) or max_parser_version
if syntax_version then
syntax_version = tonumber(syntax_version:match("^[0-9]+"))
end
syntax_version = syntax_version or (version and tonumber(version:match("^[0-9]+")) or max_parser_version)
local parse = Parsers[syntax_version] or Parsers[max_parser_version]
local tree = parse(nomsu_code, source.filename)
if tree.shebang then
tree.version = tree.shebang:match("nomsu %-V[ ]*([%d.]*)")
tree.version = tree.version or tree.shebang:match("nomsu %-V[ ]*([%d.]*)")
end
local errs = { }
local find_errors

View File

@ -60,18 +60,20 @@ nomsu_environment = Importer{
compile: compile, _1_as_lua: compile, compile_error_at:compile_error,
:_1_forked, :import_to_1_from,
_1_parsed: (nomsu_code)->
_1_parsed: (nomsu_code, syntax_version)->
if type(nomsu_code) == 'string'
filename = Files.spoof(nomsu_code)
nomsu_code = NomsuCode\from(Source(filename, 1, #nomsu_code), nomsu_code)
source = nomsu_code.source
nomsu_code = tostring(nomsu_code)
version = nomsu_code\match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
syntax_version = version and tonumber(version\match("^[0-9]+")) or max_parser_version
if syntax_version
syntax_version = tonumber(syntax_version\match("^[0-9]+"))
syntax_version or= version and tonumber(version\match("^[0-9]+")) or max_parser_version
parse = Parsers[syntax_version] or Parsers[max_parser_version]
tree = parse(nomsu_code, source.filename)
if tree.shebang
tree.version = tree.shebang\match("nomsu %-V[ ]*([%d.]*)")
tree.version or= tree.shebang\match("nomsu %-V[ ]*([%d.]*)")
errs = {}
find_errors = (t)->
if t.type == "Error"

View File

@ -22,7 +22,7 @@ for $filename in $args.extra_args:
barf "File does not exist: \$filename"
$leading_indent = ($file|matching "[\n]*([ ]*)")
$code = (NomsuCode from (Source $filename 1 (size of $file)) $file)
$tree = ($code parsed)
$tree = ($code parsed $start_version)
$uptree = (..)
$tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to \
..$version