From 2f71fbc13f18d1c2c6628aa6470b9adaa8da72e4 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Tue, 29 Sep 2015 21:06:51 -0700 Subject: [PATCH] use colon instead of colon stub for bound import --- moonscript/parse.lua | 2 +- moonscript/parse.moon | 2 +- moonscript/transform.lua | 10 +++++----- moonscript/transform.moon | 4 ++-- moonscript/transform/destructure.lua | 2 +- moonscript/transform/destructure.moon | 4 +++- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 30846db..53c12f0 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -120,7 +120,7 @@ local build_grammar = wrap_env(debug_grammar, function(root) InBlock = Advance * Block * PopIndent, Local = key("local") * ((op("*") + op("^")) / mark("declare_glob") + Ct(NameList) / mark("declare_with_shadows")), Import = key("import") * Ct(ImportNameList) * SpaceBreak ^ 0 * key("from") * Exp / mark("import"), - ImportName = (sym("\\") * Ct(Cc("colon_stub") * Name) + Name), + ImportName = (sym("\\") * Ct(Cc("colon") * Name) + Name), ImportNameList = SpaceBreak ^ 0 * ImportName * ((SpaceBreak ^ 1 + sym(",") * SpaceBreak ^ 0) * ImportName) ^ 0, BreakLoop = Ct(key("break") / trim) + Ct(key("continue") / trim), Return = key("return") * (ExpListLow / mark("explist") + C("")) / mark("return"), diff --git a/moonscript/parse.moon b/moonscript/parse.moon index ca27557..96c26e5 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -134,7 +134,7 @@ build_grammar = wrap_env debug_grammar, (root) -> Local: key"local" * ((op"*" + op"^") / mark"declare_glob" + Ct(NameList) / mark"declare_with_shadows") Import: key"import" * Ct(ImportNameList) * SpaceBreak^0 * key"from" * Exp / mark"import" - ImportName: (sym"\\" * Ct(Cc"colon_stub" * Name) + Name) + ImportName: (sym"\\" * Ct(Cc"colon" * Name) + Name) ImportNameList: SpaceBreak^0 * ImportName * ((SpaceBreak^1 + sym"," * SpaceBreak^0) * ImportName)^0 BreakLoop: Ct(key"break"/trim) + Ct(key"continue"/trim) diff --git a/moonscript/transform.lua b/moonscript/transform.lua index 0b1e1d0..a378674 100644 --- a/moonscript/transform.lua +++ b/moonscript/transform.lua @@ -484,18 +484,18 @@ Statement = Transformer({ local _len_0 = 1 for _index_0 = 1, #names do local name = names[_index_0] - local dest_val - if ntype(name) == "colon_stub" then - dest_val = name[2] + local dest_name + if ntype(name) == "colon" then + dest_name = name[2] else - dest_val = name + dest_name = name end local _value_0 = { { "key_literal", name }, - dest_val + dest_name } _accum_0[_len_0] = _value_0 _len_0 = _len_0 + 1 diff --git a/moonscript/transform.moon b/moonscript/transform.moon index 9be3292..accc153 100644 --- a/moonscript/transform.moon +++ b/moonscript/transform.moon @@ -291,12 +291,12 @@ Statement = Transformer { import: (node) => _, names, source = unpack node table_values = for name in *names - dest_val = if ntype(name) == "colon_stub" + dest_name = if ntype(name) == "colon" name[2] else name - {{"key_literal", name}, dest_val} + {{"key_literal", name}, dest_name} dest = { "table", table_values } { "assign", {dest}, {source}, [-1]: node[-1] } diff --git a/moonscript/transform/destructure.lua b/moonscript/transform/destructure.lua index 6798c61..2ec46be 100644 --- a/moonscript/transform/destructure.lua +++ b/moonscript/transform/destructure.lua @@ -68,7 +68,7 @@ extract_assign_names = function(name, accum, prefix) local s if ntype(key) == "key_literal" then local key_name = key[2] - if ntype(key_name) == "colon_stub" then + if ntype(key_name) == "colon" then s = key_name else s = { diff --git a/moonscript/transform/destructure.moon b/moonscript/transform/destructure.moon index eef2852..5b22247 100644 --- a/moonscript/transform/destructure.moon +++ b/moonscript/transform/destructure.moon @@ -20,6 +20,7 @@ has_destructure = (names) -> false extract_assign_names = (name, accum={}, prefix={}) -> + i = 1 for tuple in *name[2] value, suffix = if #tuple == 1 @@ -28,9 +29,10 @@ extract_assign_names = (name, accum={}, prefix={}) -> tuple[1], s else key = tuple[1] + s = if ntype(key) == "key_literal" key_name = key[2] - if ntype(key_name) == "colon_stub" + if ntype(key_name) == "colon" key_name else {"dot", key_name}