From c6734d82e99166fc55e44ab03a476889f1a14e9e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 9 Mar 2019 15:59:20 -0800 Subject: Passing around DictEntry and changing API to _1_as_an_iterable --- nomsu_environment.lua | 21 +++++++++++++-------- nomsu_environment.moon | 13 +++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/nomsu_environment.lua b/nomsu_environment.lua index 08face7..fdfeeb0 100644 --- a/nomsu_environment.lua +++ b/nomsu_environment.lua @@ -3,10 +3,10 @@ do local _obj_0 = require("code_obj") NomsuCode, LuaCode, Source = _obj_0.NomsuCode, _obj_0.LuaCode, _obj_0.Source end -local List, Dict +local List, Dict, DictEntries do local _obj_0 = require('containers') - List, Dict = _obj_0.List, _obj_0.Dict + List, Dict, DictEntries = _obj_0.List, _obj_0.Dict, _obj_0.DictEntries end local Text = require('text') local SyntaxTree = require("syntax_tree") @@ -73,11 +73,15 @@ _1_as_text = function(x) end return tostring(x) end -local _1_as_list -_1_as_list = function(x) - local mt = getmetatable(x) - if mt.as_list then - return mt.as_list(x) +local _1_as_an_iterable +_1_as_an_iterable = function(x) + do + local mt = getmetatable(x) + if mt then + if mt.as_iterable then + return mt.as_iterable(x) + end + end end return x end @@ -128,6 +132,7 @@ nomsu_environment = Importer({ a_List = List, a_Dict = Dict, Text = Text, + Dict_Entries = DictEntries, lpeg = lpeg, re = re, Files = Files, @@ -151,7 +156,7 @@ nomsu_environment = Importer({ compile = compile, at_1_fail = fail_at, _1_as_text = _1_as_text, - _1_as_list = _1_as_list, + _1_as_an_iterable = _1_as_an_iterable, exit = os.exit, quit = os.exit, _1_parsed = function(nomsu_code, syntax_version) diff --git a/nomsu_environment.moon b/nomsu_environment.moon index 7066be1..4aa23f9 100644 --- a/nomsu_environment.moon +++ b/nomsu_environment.moon @@ -1,7 +1,7 @@ -- This file defines the environment in which Nomsu code runs, including some -- basic bootstrapping functionality. {:NomsuCode, :LuaCode, :Source} = require "code_obj" -{:List, :Dict} = require 'containers' +{:List, :Dict, :DictEntries} = require 'containers' Text = require 'text' SyntaxTree = require "syntax_tree" Files = require "files" @@ -44,9 +44,10 @@ _1_as_text = (x)-> if x == false then return "no" return tostring(x) -_1_as_list = (x)-> - mt = getmetatable(x) - if mt.as_list then return mt.as_list(x) +_1_as_an_iterable = (x)-> + if mt = getmetatable(x) + if mt.as_iterable + return mt.as_iterable(x) return x local nomsu_environment @@ -61,7 +62,7 @@ nomsu_environment = Importer{ :pairs, :ipairs, :jit, :_VERSION, LUA_VERSION: (jit and jit.version or _VERSION), LUA_API: _VERSION, Bit: (jit or _VERSION == "Lua 5.2") and require('bitops') or nil -- Nomsu types: - a_List:List, a_Dict:Dict, Text:Text, + a_List:List, a_Dict:Dict, Text:Text, Dict_Entries:DictEntries, -- Utilities and misc. lpeg:lpeg, re:re, Files:Files, :SyntaxTree, TESTS: Dict({}), globals: Dict({}), @@ -74,7 +75,7 @@ nomsu_environment = Importer{ -- Nomsu functions: _1_as_nomsu:tree_to_nomsu, _1_as_inline_nomsu:tree_to_inline_nomsu, - compile: compile, at_1_fail:fail_at, :_1_as_text, :_1_as_list, + compile: compile, at_1_fail:fail_at, :_1_as_text, :_1_as_an_iterable, exit:os.exit, quit:os.exit, _1_parsed: (nomsu_code, syntax_version)-> -- cgit v1.2.3