aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-15 15:50:18 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-15 15:50:32 -0800
commitd82c4f85d8cdb1d4cdf97e90b2715d2fb06b4bef (patch)
treee31b18f7e575b39960a6ab220b6604a09bde6c11
parent5a526675db93ea95efc82af7fc6c8f80b0275e8a (diff)
Added support for translating comments instead of dropping them.
-rw-r--r--nomsu.lua10
-rwxr-xr-xnomsu.moon9
-rw-r--r--nomsu.peg4
3 files changed, 21 insertions, 2 deletions
diff --git a/nomsu.lua b/nomsu.lua
index 587bc22..0df32fb 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -510,6 +510,12 @@ do
elseif "Nomsu" == _exp_0 then
local inside, inline = self:tree_to_nomsu(tree.value, force_inline)
return "\\" .. tostring(inside), inline
+ elseif "Comment" == _exp_0 then
+ if tree.value:find("\n") then
+ return "#.." .. tostring(self:indent(tree.value)), false
+ else
+ return "#" .. tostring(tree.value), false
+ end
elseif "Block" == _exp_0 then
if force_inline then
return "(:" .. tostring(concat((function()
@@ -706,6 +712,10 @@ do
return {
statements = concat(lua_bits, "\n")
}
+ elseif "Comment" == _exp_0 then
+ return {
+ statements = "--" .. tree.value:gsub("\n", "\n--")
+ }
elseif "Nomsu" == _exp_0 then
return {
expr = "nomsu:parse(" .. tostring(repr(tree.value.src)) .. ", " .. tostring(repr(tree:get_line_no())) .. ").value[1]"
diff --git a/nomsu.moon b/nomsu.moon
index 054d907..bc7aa22 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -368,6 +368,12 @@ class NomsuCompiler
inside, inline = @tree_to_nomsu(tree.value, force_inline)
return "\\#{inside}", inline
+ when "Comment"
+ if tree.value\find("\n")
+ return "#..#{@indent tree.value}", false
+ else
+ return "##{tree.value}", false
+
when "Block"
if force_inline
return "(:#{concat([@tree_to_nomsu(v, true) for v in *tree.value], "; ")})", true
@@ -504,6 +510,9 @@ class NomsuCompiler
if lua.expr then insert lua_bits, "#{lua.expr};"
return statements:concat(lua_bits, "\n")
+ when "Comment"
+ return statements:"--"..tree.value\gsub("\n","\n--")
+
when "Nomsu"
return expr:"nomsu:parse(#{repr tree.value.src}, #{repr tree\get_line_no!}).value[1]"
diff --git a/nomsu.peg b/nomsu.peg
index 9920665..0011924 100644
--- a/nomsu.peg
+++ b/nomsu.peg
@@ -92,8 +92,8 @@ dict_line:
inline_dict_item:
{| {:dict_key: inline_expression / word :} %ws* "=" %ws* {:dict_value: inline_functioncall / inline_expression :} |}
-block_comment: "#.." [^%nl]* (%nl (%ws* &%nl))* %nl %indented [^%nl]+ (%nl ((%ws* ((!.) / &%nl)) / (!%dedented [^%nl]+)))*
-line_comment: "#" [^%nl]*
+block_comment(Comment): "#.." { [^%nl]* (%nl (%ws* &%nl))* %nl %indented [^%nl]+ (%nl ((%ws* ((!.) / &%nl)) / (!%dedented [^%nl]+)))* }
+line_comment(Comment): "#" { [^%nl]* }
eol: %ws* line_comment? (!. / &%nl)
ignored_line: (%nodented (block_comment / line_comment)) / (%ws* (!. / &%nl))