Renamed repr_if_not_string to "stringify" and added nomsu:stringify for
convenience.
This commit is contained in:
parent
7435b61380
commit
d13bcde2b9
@ -15,7 +15,7 @@ parse [assert %condition] as: assert %condition (nil)
|
|||||||
rule [join %strs with glue %glue] =:
|
rule [join %strs with glue %glue] =:
|
||||||
lua block ".."
|
lua block ".."
|
||||||
|local str_bits = {}
|
|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)
|
|return table.concat(str_bits, vars.glue)
|
||||||
parse [join %strs] as: join %strs with 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)"
|
"(\(%str as lua)):gsub('%l', string.upper, 1)"
|
||||||
|
|
||||||
compile [say %str] to: ".."
|
compile [say %str] to: ".."
|
||||||
|nomsu:writeln(nomsu.utils.repr_if_not_string(\(%str as lua)))
|
|nomsu:writeln(nomsu:stringify(\(%str as lua)))
|
||||||
|
|
||||||
# Number ranges
|
# Number ranges
|
||||||
compile [%start to %stop by %step, %start to %stop via %step] to: ".."
|
compile [%start to %stop by %step, %start to %stop via %step] to: ".."
|
||||||
|
@ -578,7 +578,7 @@ do
|
|||||||
if statement then
|
if statement then
|
||||||
self:error("Cannot use [[" .. tostring(bit.src) .. "]] as a string interpolation value, since it's not an expression.")
|
self:error("Cannot use [[" .. tostring(bit.src) .. "]] as a string interpolation value, since it's not an expression.")
|
||||||
end
|
end
|
||||||
insert(concat_parts, "nomsu.utils.repr_if_not_string(" .. tostring(expr) .. ")")
|
insert(concat_parts, "nomsu:stringify(" .. tostring(expr) .. ")")
|
||||||
_continue_0 = true
|
_continue_0 = true
|
||||||
until true
|
until true
|
||||||
if not _continue_0 then
|
if not _continue_0 then
|
||||||
@ -905,6 +905,9 @@ do
|
|||||||
self.repr = function(self, ...)
|
self.repr = function(self, ...)
|
||||||
return repr(...)
|
return repr(...)
|
||||||
end
|
end
|
||||||
|
self.stringify = function(self, ...)
|
||||||
|
return utils.stringify(...)
|
||||||
|
end
|
||||||
self.loaded_files = setmetatable({ }, {
|
self.loaded_files = setmetatable({ }, {
|
||||||
__index = parent and parent.loaded_files
|
__index = parent and parent.loaded_files
|
||||||
})
|
})
|
||||||
|
@ -197,6 +197,7 @@ class NomsuCompiler
|
|||||||
@debug = false
|
@debug = false
|
||||||
@utils = utils
|
@utils = utils
|
||||||
@repr = (...)=> repr(...)
|
@repr = (...)=> repr(...)
|
||||||
|
@stringify = (...)=> utils.stringify(...)
|
||||||
@loaded_files = setmetatable({}, {__index:parent and parent.loaded_files})
|
@loaded_files = setmetatable({}, {__index:parent and parent.loaded_files})
|
||||||
if not parent
|
if not parent
|
||||||
@initialize_core!
|
@initialize_core!
|
||||||
@ -436,7 +437,7 @@ class NomsuCompiler
|
|||||||
@writeln "#{colored.bright "EXPR:"} #{expr}, #{colored.bright "STATEMENT:"} #{statement}"
|
@writeln "#{colored.bright "EXPR:"} #{expr}, #{colored.bright "STATEMENT:"} #{statement}"
|
||||||
if statement
|
if statement
|
||||||
@error "Cannot use [[#{bit.src}]] as a string interpolation value, since it's not an expression."
|
@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 ~= ""
|
if string_buffer ~= ""
|
||||||
insert concat_parts, repr(string_buffer)
|
insert concat_parts, repr(string_buffer)
|
||||||
|
@ -73,7 +73,7 @@ utils = {
|
|||||||
return tostring(x)
|
return tostring(x)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
repr_if_not_string = function(x)
|
stringify = function(x)
|
||||||
if type(x) == 'string' then
|
if type(x) == 'string' then
|
||||||
return x
|
return x
|
||||||
else
|
else
|
||||||
|
@ -41,7 +41,7 @@ utils = {
|
|||||||
else
|
else
|
||||||
tostring(x)
|
tostring(x)
|
||||||
|
|
||||||
repr_if_not_string: (x)->
|
stringify: (x)->
|
||||||
if type(x) == 'string' then x
|
if type(x) == 'string' then x
|
||||||
else utils.repr(x)
|
else utils.repr(x)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user