aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-22 16:15:25 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-22 16:16:53 -0800
commitf746ba34d799e6560df1aad1cad15a70b34914d1 (patch)
tree3829ce9bd8469e59d1a51470823d510dc808e1c7 /nomsu_compiler.moon
parenta596195f6cfb6731f1e778e4bc304028ecd9bf08 (diff)
Moved all the text method stuff into text.moon instead of splitting
across string2/containers. Modified the type stuff to output better type names and use (a Dict) and (a List) instead of (Dict) and (List). (Text) now also has a proper constructor. (assume) now also handles a bunch of different assumptions with smart error messages.
Diffstat (limited to 'nomsu_compiler.moon')
-rw-r--r--nomsu_compiler.moon12
1 files changed, 6 insertions, 6 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index e17d5e2..b224fad 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -1,7 +1,6 @@
--
-- This file contains the source code of the Nomsu compiler.
--
-{:List, :Dict, :Text} = require 'containers'
unpack or= table.unpack
{:match, :sub, :gsub, :format, :byte, :find} = string
{:LuaCode, :Source} = require "code_obj"
@@ -180,7 +179,7 @@ compile = (tree)=>
if bit.type == "Block" and #bit == 1
bit = bit[1]
if bit.type == "Block"
- bit_lua = LuaCode\from bit.source, "List(function(add)",
+ bit_lua = LuaCode\from bit.source, "a_List(function(add)",
"\n ", bit_lua,
"\nend):joined()"
elseif bit.type != "Text"
@@ -199,8 +198,9 @@ compile = (tree)=>
return lua
when "List", "Dict"
+ typename = "a_"..tree.type
if #tree == 0
- return LuaCode\from tree.source, tree.type, "{}"
+ return LuaCode\from tree.source, typename, "{}"
lua = LuaCode\from tree.source
chunks = 0
@@ -208,7 +208,7 @@ compile = (tree)=>
while tree[i]
if tree[i].type == 'Block'
lua\add " + " if chunks > 0
- lua\add tree.type, "(function(", (tree.type == 'List' and "add" or ("add, "..("add 1 =")\as_lua_id!)), ")"
+ lua\add typename, "(function(", (tree.type == 'List' and "add" or ("add, "..("add 1 =")\as_lua_id!)), ")"
lua\add "\n ", @compile(tree[i]), "\nend)"
chunks += 1
i += 1
@@ -234,9 +234,9 @@ compile = (tree)=>
sep = ', '
i += 1
if items_lua\is_multiline!
- lua\add LuaCode\from items_lua.source, tree.type, "{\n ", items_lua, "\n}"
+ lua\add LuaCode\from items_lua.source, typename, "{\n ", items_lua, "\n}"
else
- lua\add LuaCode\from items_lua.source, tree.type, "{", items_lua, "}"
+ lua\add LuaCode\from items_lua.source, typename, "{", items_lua, "}"
chunks += 1
return lua