aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-09-26 13:05:28 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-09-26 13:05:47 -0700
commitb43432e647fbb3bb76aa2836e3899d5e407c50f9 (patch)
tree640aee09e7dafbcca53c4792d3446c7f6265e004
parent692fae5416ce1f2702b599ffb27b2e3d2235eba7 (diff)
Fixed all syntax errors, got original (non-nomnom) tests passing.
-rw-r--r--containers.lua2
-rw-r--r--containers.moon2
-rw-r--r--core/control_flow.nom21
-rw-r--r--core/metaprogramming.nom6
-rw-r--r--lib/object.nom2
-rw-r--r--nomnom/compile.nom2
-rw-r--r--nomnom/decompile.nom21
-rw-r--r--nomnom/files.nom3
-rw-r--r--nomnom/parser.nom4
9 files changed, 35 insertions, 28 deletions
diff --git a/containers.lua b/containers.lua
index 682932f..2018581 100644
--- a/containers.lua
+++ b/containers.lua
@@ -48,6 +48,7 @@ as_lua = function(self)
return error("Not supported: " .. tostring(self))
end
local _list_mt = {
+ __type = "List",
__eq = equivalent,
__tostring = function(self)
return "[" .. concat((function()
@@ -231,6 +232,7 @@ walk_items = function(self, i)
end
end
local _dict_mt = {
+ __type = "Dict",
__eq = equivalent,
__len = size,
__tostring = function(self)
diff --git a/containers.moon b/containers.moon
index 8a7d7fa..f8f678c 100644
--- a/containers.moon
+++ b/containers.moon
@@ -26,6 +26,7 @@ as_lua = =>
-- List and Dict classes to provide basic equality/tostring functionality for the tables
-- used in Nomsu. This way, they retain a notion of whether they were originally lists or dicts.
_list_mt =
+ __type: "List"
__eq:equivalent
-- Could consider adding a __newindex to enforce list-ness, but would hurt performance
__tostring: =>
@@ -96,6 +97,7 @@ walk_items = (i)=>
return i, Dict{key:k, value:v}
_dict_mt =
+ __type: "Dict"
__eq:equivalent
__len:size
__tostring: =>
diff --git a/core/control_flow.nom b/core/control_flow.nom
index c496d18..a3814b7 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -72,6 +72,8 @@ compile [..]
end
end)())"
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
# GOTOs
test:
%i = 0
@@ -84,9 +86,10 @@ test:
unless (%i == 0): go to (Loop)
assume (%i == 0)
compile [=== %label ===, --- %label ---, *** %label ***] to (..)
- Lua "::label_\(%label as lua identifier)::"
+ Lua "::label_\((%label.stub if (%label.type == "Action") else %label) as lua identifier)::"
-compile [go to %label] to (Lua "goto label_\(%label as lua identifier)")
+compile [go to %label] to (..)
+ Lua "goto label_\((%label.stub if (%label.type == "Action") else %label) as lua identifier)"
# Basic loop control
compile [do next] to (Lua "goto continue")
@@ -165,13 +168,15 @@ compile [repeat %n times %body] to:
return %lua
# For loop control flow
-compile [stop %var] to (Lua "goto stop_\(%var as lua identifier)")
-compile [do next %var] to (Lua "goto continue_\(%var as lua identifier)")
+compile [stop %var] to (..)
+ Lua "goto stop_\((%var.stub if (%var.type == "Action") else %var) as lua identifier)"
+compile [do next %var] to (..)
+ Lua "goto continue_\((%var.stub if (%var.type == "Action") else %var) as lua identifier)"
compile [===stop %var ===, ---stop %var ---, ***stop %var ***] to (..)
- Lua "::stop_\(%var as lua identifier)::"
+ Lua "::stop_\((%var.stub if (%var.type == "Action") else %var) as lua identifier)::"
compile [===next %var ===, ---next %var ---, ***next %var ***] to (..)
- Lua "::continue_\(%var as lua identifier)::"
+ Lua "::continue_\((%var.stub if (%var.type == "Action") else %var) as lua identifier)::"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -516,11 +521,11 @@ test:
%t = [1, [2, [[3], 4], 5, [[[6]]]]]
%flat = []
for % in recursive %t:
- if ((type of %) is "table"):
+ if ((lua type of %) is "table"):
for %2 in %: recurse % on %2
..else: %flat::add %
- assume ((sorted %flat) == [1, 2, 3, 4, 5, 6])
+ assume (sorted %flat) == [1, 2, 3, 4, 5, 6]
# Recurion control flow
compile [for %var in recursive %structure %body] to (..)
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 8b75ccd..f92fb0c 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -236,7 +236,7 @@ action [%var as lua identifier, %var as lua id] (..)
elseif AST.is_syntax_tree(\%var) then
local lua = \(%var as lua expr)
if not tostring(lua):match("^[_a-zA-Z][_a-zA-Z0-9]*$") then
- compile_error_at_1_2(\%var, "This is not a valid Lua identifier.")
+ nomsu:compile_error(\%var, "This is not a valid Lua identifier.")
end
return lua
else error("Unknown type: "..tostring(\%var))
@@ -322,7 +322,7 @@ test:
compile [quote %s] to (Lua value "tostring(\(%s as lua expr)):as_lua()")
test:
- assume (lua type of {}) == "Lua table"
+ assume (lua type of {}) == "table"
assume (type of {}) == "Dict"
assume ({} is a "Dict")
assume ("" is text)
@@ -341,7 +341,7 @@ action [type of %]:
else return lua_type end"
parse [% is a %type, % is an %type] as ((type of %) == %type)
parse [% isn't a %type, % isn't an %type, % is not a %type, % is not an %type]
-..as ((type of %) == %type)
+..as ((type of %) != %type)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/lib/object.nom b/lib/object.nom
index 65da2a1..25ff644 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -80,9 +80,9 @@ compile [object %classname extends %parent %class_body] to:
Lua "\
..do
local class = {name=\(quote %classname.stub)}
+ class.__type = class.name
setmetatable(class, {
__index=\(%parent as lua expr),
- __type=class.name,
__tostring=function(cls) return cls.name end,
__call=function(cls, inst)
inst = setmetatable(inst or {}, cls)
diff --git a/nomnom/compile.nom b/nomnom/compile.nom
index ff3b71f..43e6d84 100644
--- a/nomnom/compile.nom
+++ b/nomnom/compile.nom
@@ -140,7 +140,7 @@ action [compile %tree using %compile_actions]:
..Can't use this as a dict key, since it's not an expression."
%value_lua = (..)
(compile %value using %compile_actions) if %value
- ..else (Lua Value from %key ["true"]))
+ ..else (Lua Value from %key ["true"])
unless %value_lua.is_value:
compile error at %tree.2 "\
..Can't use this as a dict value, since it's not an expression."
diff --git a/nomnom/decompile.nom b/nomnom/decompile.nom
index 27ef406..0d8d4d2 100644
--- a/nomnom/decompile.nom
+++ b/nomnom/decompile.nom
@@ -45,9 +45,10 @@ action [decompile %tree inline]:
"Block":
%nomsu = (Nomsu Code from %tree [":"])
- for i,line in ipairs tree
- %nomsu::add(i == 1 and " " or "; ")
- %nomsu::add recurse(line, nomsu, i == 1 or i < #tree)
+ for %line in %tree at %i:
+ %nomsu::add [..]
+ " " if (%i == 1) else "; "
+ decompile %line inline
return %nomsu
"Text":
@@ -100,12 +101,12 @@ action [decompile %tree inline]:
"IndexChain":
%nomsu = (Nomsu Code from %tree)
for %bit in %tree at %i:
- if (%i > 1): nomsu::add "."
+ if (%i > 1): %nomsu::add "."
if (..)
all of [..]
%i > 1, %bit.type == "Text", (size of %bit) == 1, %bit.1 is text,
%bit.1::is a nomsu identifier
- %nomsu::add %bit.1
+ ..:%nomsu::add %bit.1
..else:
%bit_nomsu = (decompile %bit inline)
if (..)
@@ -261,7 +262,7 @@ action [decompile %tree]:
%bit = (escape text %bit)
for %line in (%bit::lines) at %j:
if:
- (%j > 1): nomsu::add "\n"
+ (%j > 1): %nomsu::add "\n"
(((size of %line) > 10) and ((%nomsu::trailing line length) > %max_line)):
%nomsu::add "\\\n.."
@@ -304,14 +305,14 @@ action [decompile %tree]:
%item_nomsu = (recurse on %item_nomsu)
%nomsu::add %item_nomsu
if (%i < (size of %tree)):
- if (..)
- (%item_nomsu::is multi-line) or (..)
- (%nomsu::trailing line length) + (size of "\%item_nomsu")) >= %MAX_LINE
+ if any of [..]
+ %item_nomsu::is multi-line
+ ((%nomsu::trailing line length) + (size of "\%item_nomsu")) >= %MAX_LINE
..: %nomsu::add "\n"
..else: %nomsu::add ", "
return (..)
Nomsu Code from %tree [..]
- "[..]\n " if tree.type == "List" else "{..}\n "
+ "[..]\n " if (%tree.type == "List") else "{..}\n "
%nomsu
"DictEntry":
diff --git a/nomnom/files.nom b/nomnom/files.nom
index 8fd8f24..a17ec85 100644
--- a/nomnom/files.nom
+++ b/nomnom/files.nom
@@ -82,9 +82,6 @@ try:
..or if it barfs:
# LFS not found! Fall back to shell commands, if available.
unless (sh> "find . -maxdepth 0"):
- url = if jit
- 'https://github.com/spacewander/luafilesystem'
- else
barf "\
..Could not find 'luafilesystem' module and couldn't run system command 'find' \
..(this might happen on Windows). Please install 'luafilesystem' (which can be \
diff --git a/nomnom/parser.nom b/nomnom/parser.nom
index 60c356f..1f460bd 100644
--- a/nomnom/parser.nom
+++ b/nomnom/parser.nom
@@ -21,8 +21,8 @@ set {..}
userdata: Carg 1
utf8_char: (..)
(R "\194\223")*(R "\128\191") +
- (R "\224\239")*(R "\128\191")*(R "\128\191") +
- (R "\240\244")*(R "\128\191")*(R "\128\191")*(R "\128\191")
+ ..(R "\224\239")*(R "\128\191")*(R "\128\191") +
+ ..(R "\240\244")*(R "\128\191")*(R "\128\191")*(R "\128\191")
Tree: [%t, %userdata] ->:
%source = (..)