aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-10-13 16:16:07 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-10-13 16:16:07 -0700
commitd13bcde2b9306e0c87b055faed88da76bd3ff41e (patch)
tree4c9e974d8e448adb6f6c1ba232b4114137aba4cc
parent7435b61380054307148ec2c3a6af6d7ef9187fbe (diff)
Renamed repr_if_not_string to "stringify" and added nomsu:stringify for
convenience.
-rw-r--r--lib/utils.nom4
-rw-r--r--nomsu.lua5
-rwxr-xr-xnomsu.moon3
-rw-r--r--utils.lua2
-rw-r--r--utils.moon2
5 files changed, 10 insertions, 6 deletions
diff --git a/lib/utils.nom b/lib/utils.nom
index 55df1b7..f0a7342 100644
--- a/lib/utils.nom
+++ b/lib/utils.nom
@@ -15,7 +15,7 @@ parse [assert %condition] as: assert %condition (nil)
rule [join %strs with glue %glue] =:
lua block ".."
|local str_bits = {}
- |for i,bit in ipairs(vars.strs) do str_bits[i] = nomsu.utils.repr_if_not_string(bit) end
+ |for i,bit in ipairs(vars.strs) do str_bits[i] = nomsu:stringify(bit) end
|return table.concat(str_bits, vars.glue)
parse [join %strs] as: join %strs with glue ""
@@ -23,7 +23,7 @@ compile [capitalize %str, %str capitalized] to:
"(\(%str as lua)):gsub('%l', string.upper, 1)"
compile [say %str] to: ".."
- |nomsu:writeln(nomsu.utils.repr_if_not_string(\(%str as lua)))
+ |nomsu:writeln(nomsu:stringify(\(%str as lua)))
# Number ranges
compile [%start to %stop by %step, %start to %stop via %step] to: ".."
diff --git a/nomsu.lua b/nomsu.lua
index b937ad8..45a1569 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -578,7 +578,7 @@ do
if statement then
self:error("Cannot use [[" .. tostring(bit.src) .. "]] as a string interpolation value, since it's not an expression.")
end
- insert(concat_parts, "nomsu.utils.repr_if_not_string(" .. tostring(expr) .. ")")
+ insert(concat_parts, "nomsu:stringify(" .. tostring(expr) .. ")")
_continue_0 = true
until true
if not _continue_0 then
@@ -905,6 +905,9 @@ do
self.repr = function(self, ...)
return repr(...)
end
+ self.stringify = function(self, ...)
+ return utils.stringify(...)
+ end
self.loaded_files = setmetatable({ }, {
__index = parent and parent.loaded_files
})
diff --git a/nomsu.moon b/nomsu.moon
index 8d952f2..d24b27c 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -197,6 +197,7 @@ class NomsuCompiler
@debug = false
@utils = utils
@repr = (...)=> repr(...)
+ @stringify = (...)=> utils.stringify(...)
@loaded_files = setmetatable({}, {__index:parent and parent.loaded_files})
if not parent
@initialize_core!
@@ -436,7 +437,7 @@ class NomsuCompiler
@writeln "#{colored.bright "EXPR:"} #{expr}, #{colored.bright "STATEMENT:"} #{statement}"
if statement
@error "Cannot use [[#{bit.src}]] as a string interpolation value, since it's not an expression."
- insert concat_parts, "nomsu.utils.repr_if_not_string(#{expr})"
+ insert concat_parts, "nomsu:stringify(#{expr})"
if string_buffer ~= ""
insert concat_parts, repr(string_buffer)
diff --git a/utils.lua b/utils.lua
index 2f6f25a..e8fca96 100644
--- a/utils.lua
+++ b/utils.lua
@@ -73,7 +73,7 @@ utils = {
return tostring(x)
end
end,
- repr_if_not_string = function(x)
+ stringify = function(x)
if type(x) == 'string' then
return x
else
diff --git a/utils.moon b/utils.moon
index 87cd5a3..9cceaac 100644
--- a/utils.moon
+++ b/utils.moon
@@ -41,7 +41,7 @@ utils = {
else
tostring(x)
- repr_if_not_string: (x)->
+ stringify: (x)->
if type(x) == 'string' then x
else utils.repr(x)