diff --git a/README.md b/README.md index c916d43..a6a5dfb 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index 6353933..21de3df 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -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 (..) diff --git a/nomsu_environment.lua b/nomsu_environment.lua index fc5ab31..93487aa 100644 --- a/nomsu_environment.lua +++ b/nomsu_environment.lua @@ -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 diff --git a/nomsu_environment.moon b/nomsu_environment.moon index 5d26701..cc059b5 100644 --- a/nomsu_environment.moon +++ b/nomsu_environment.moon @@ -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" diff --git a/tools/upgrade.nom b/tools/upgrade.nom index 48f1811..9244203 100755 --- a/tools/upgrade.nom +++ b/tools/upgrade.nom @@ -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