diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-10 22:47:03 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-10 22:47:18 -0700 |
| commit | 4126589afef1c3c14cfa5a3a0f43cc6e98569f1d (patch) | |
| tree | 3a6aee67f531c76f2b979f4b81cba5fc53b3fc6e /nomsu.moon | |
| parent | 77c11a2443adb883621b4253d63fe40db048bd85 (diff) | |
Cleanup: removed "File" type trees (now just Block), overhauled
how_do_i.nom, added "result of %" macro, which allowed comprehensions to
be way more concisely defined. Moved len() operator into the nomsu
environment.
Diffstat (limited to 'nomsu.moon')
| -rwxr-xr-x | nomsu.moon | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -254,6 +254,13 @@ class NomsuCompiler :table, :assert, :dofile, :loadstring, :type, :select, :debug, :math, :io, :pairs, :load, :ipairs, } + @environment.len = if jit + (x)-> + if mt = getmetatable(x) + if mt.__len + return mt.__len(x) + return #x + else ((x) -> #x) for k,v in pairs(Types) do @environment[k] = v @environment.Tuple = Tuple @environment.Lua = Lua @@ -331,7 +338,6 @@ class NomsuCompiler if #tostring(nomsu_code) == 0 then return nil tree = @parse(nomsu_code) assert tree, "Failed to parse: #{nomsu_code}" - assert tree.type == "File", "Attempt to run non-file: #{tree.type}" lua = tree\as_lua(@) lua\convert_to_statements! lua\declare_locals! @@ -410,7 +416,7 @@ class NomsuCompiler coroutine.yield(tree, depth) return unless Types.is_node(tree) switch tree.type - when "List", "File", "Block", "Action", "Text", "IndexChain" + when "List", "Block", "Action", "Text", "IndexChain" for v in *tree.value @walk_tree(v, depth+1) when "Dict" @@ -445,6 +451,9 @@ class NomsuCompiler return tree\map(fn) tree_with_replaced_vars: (tree, replacements)=> + return tree unless next(replacements) + if next(replacements).type == "Var" + replacements = {@var_to_lua_identifier(k),v for k,v in pairs(replacements)} tree\map (t)-> if t.type == "Var" id = tostring(t\as_lua(self)) |
