aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua_obj.lua4
-rw-r--r--nomsu.lua22
-rw-r--r--nomsu.peg10
-rw-r--r--nomsu_tree.lua10
4 files changed, 20 insertions, 26 deletions
diff --git a/lua_obj.lua b/lua_obj.lua
index 076ac1c..e766c34 100644
--- a/lua_obj.lua
+++ b/lua_obj.lua
@@ -424,6 +424,10 @@ do
end,
__len = function(self)
return #tostring(self)
+ end,
+ parenthesize = function(self)
+ self:prepend("(")
+ return self:append(")")
end
}
_base_0.__index = _base_0
diff --git a/nomsu.lua b/nomsu.lua
index 7261a72..0ba1f15 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -353,7 +353,7 @@ do
local tree = self:parse(nomsu_code)
assert(tree, "Failed to parse: " .. tostring(nomsu_code))
assert(tree.type == "File", "Attempt to run non-file: " .. tostring(tree.type))
- local lua = self:tree_to_lua(tree)
+ local lua = tree:as_lua(self)
lua:convert_to_statements()
lua:declare_locals()
lua:prepend("-- File: " .. tostring(nomsu_code.source or "") .. "\n")
@@ -448,12 +448,9 @@ do
if tree.type == 'Text' and #tree.value == 1 and type(tree.value[1]) == 'string' then
return tree.value[1]
end
- local lua = Lua(tree.source, "return ", self:tree_to_lua(tree), ";")
+ local lua = Lua(tree.source, "return ", tree:as_lua(self), ";")
return self:run_lua(lua)
end,
- tree_to_nomsu = function(self, tree)
- return tree:as_nomsu()
- end,
value_to_nomsu = function(self, value)
local _exp_0 = type(value)
if "nil" == _exp_0 then
@@ -497,9 +494,6 @@ do
return error("Unsupported value_to_nomsu type: " .. tostring(type(value)), 0)
end
end,
- tree_to_lua = function(self, tree)
- return tree:as_lua(self)
- end,
walk_tree = function(self, tree, depth)
if depth == nil then
depth = 0
@@ -693,7 +687,7 @@ do
end
local nomsu = self
self:define_compile_action("immediately %block", get_line_no(), function(self, _block)
- local lua = nomsu:tree_to_lua(_block)
+ local lua = _block:as_lua(nomsu)
lua:convert_to_statements()
lua:declare_locals()
nomsu:run_lua(lua)
@@ -712,7 +706,7 @@ do
if type(bit) == "string" then
lua:append(repr(bit))
else
- local bit_lua = nomsu:tree_to_lua(bit)
+ local bit_lua = bit:as_lua(nomsu)
if not (bit_lua.is_value) then
local line, src = bit.source:get_line(), bit.source:get_text()
error(tostring(line) .. ": Cannot use " .. tostring(colored.yellow(src)) .. " as a string interpolation value, since it's not an expression.")
@@ -747,7 +741,7 @@ do
end)
self:define_compile_action("lua> %code", get_line_no(), function(self, _code)
if _code.type ~= "Text" then
- return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(tostring(nomsu:tree_to_lua(_code))), "))")
+ return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(tostring(_code:as_lua(nomsu))), "))")
end
local lua = Lua(_code.source)
local _list_0 = _code.value
@@ -756,7 +750,7 @@ do
if type(bit) == "string" then
lua:append(bit)
else
- local bit_lua = nomsu:tree_to_lua(bit)
+ local bit_lua = bit:as_lua(nomsu)
if not (bit_lua.is_value) then
local line, src = bit.source:get_line(), bit.source:get_text()
error(tostring(line) .. ": Cannot use " .. tostring(colored.yellow(src)) .. " as a string interpolation value, since it's not an expression.", 0)
@@ -768,7 +762,7 @@ do
end)
self:define_compile_action("=lua %code", get_line_no(), function(self, _code)
if _code.type ~= "Text" then
- return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(tostring(nomsu:tree_to_lua(_code))), "))")
+ return Lua.Value(self.source, "nomsu:run_lua(Lua(", repr(_code.source), ", ", repr(tostring(_code:as_lua(nomsu))), "))")
end
local lua = Lua.Value(self.source)
local _list_0 = _code.value
@@ -777,7 +771,7 @@ do
if type(bit) == "string" then
lua:append(bit)
else
- local bit_lua = nomsu:tree_to_lua(bit)
+ local bit_lua = bit:as_lua(nomsu)
if not (lua.is_value) then
local line, src = bit.source:get_line(), bit.source:get_text()
error(tostring(line) .. ": Cannot use " .. tostring(colored.yellow(src)) .. " as a string interpolation value, since it's not an expression.", 0)
diff --git a/nomsu.peg b/nomsu.peg
index e4ca686..7e72011 100644
--- a/nomsu.peg
+++ b/nomsu.peg
@@ -64,13 +64,9 @@ inline_text_interpolation:
)
text_interpolation:
inline_text_interpolation /
- ("\" (
- variable / inline_list / inline_dict / inline_text
- / ("(" %ws* (inline_action / inline_expression) %ws* ")")
- / (%ws* (block_comment / line_comment)? nodent "..")
- / (indented_text %nl+ %nodent "..")
- / ((indented_list / indented_block) nodent "..")
- ))
+ ("\"
+ (block_comment / line_comment / indented_text / indented_list / indented_block)?
+ nodent "..")
number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber)
diff --git a/nomsu_tree.lua b/nomsu_tree.lua
index b0109d2..ebdf812 100644
--- a/nomsu_tree.lua
+++ b/nomsu_tree.lua
@@ -9,10 +9,10 @@ do
local _obj_0 = table
insert, remove, concat = _obj_0.insert, _obj_0.remove, _obj_0.concat
end
-local Lua, Location
+local Lua, Nomsu, Location
do
local _obj_0 = require("lua_obj")
- Lua, Location = _obj_0.Lua, _obj_0.Location
+ Lua, Nomsu, Location = _obj_0.Lua, _obj_0.Nomsu, _obj_0.Location
end
local Types = { }
Types.DictEntry = immutable({
@@ -35,7 +35,7 @@ Tree = function(name, methods)
end
methods.type = name
methods.name = name
- methods.as_nomsu = function(self)
+ methods.as_nomsuXXXX = function(self)
local leading_space = 0
local src_file = FILE_CACHE[self.source.filename]
while src_file:sub(self.source.start - leading_space - 1, self.source.start - leading_space - 1) == " " do
@@ -438,9 +438,9 @@ Tree("Text", {
if not (interp_nomsu) then
return nil
end
- nomsu:append("\\\n ", interp_nomsu)
+ nomsu:append("\\\n ", interp_nomsu)
if i < #self.value then
- nomsu:append("\n..")
+ nomsu:append("\n ..")
end
end
end