aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/how_do_i.nom5
-rw-r--r--nomsu.6.peg2
-rw-r--r--nomsu_compiler.lua7
-rw-r--r--nomsu_compiler.moon6
-rw-r--r--nomsu_decompiler.lua4
-rw-r--r--nomsu_decompiler.moon4
6 files changed, 19 insertions, 9 deletions
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index e3c58d6..d40c7f4 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -1,4 +1,5 @@
#!/usr/bin/env nomsu -V6.13.12.8
+
# How do I...
# Write a comment? Put a # and go till the end of the line
# How do I write a multi-line comment?
@@ -313,9 +314,9 @@ debug only:
# Function literals look like: $x -> ($x * $x)
say (best of [2, -3, 4, -8] according to ($x -> ($x * $x)))
-# Or, you can use ((foo $)'s meaning) to access the function that gets called by (foo $)
+# Or, you can use $(foo $) to access the function that gets called by (foo $)
($x squared) means ($x * $x)
-say (best of [2, -3, 4, -8] according to (($ squared)'s meaning))
+say (best of [2, -3, 4, -8] according to $($ squared)
# But nomsu was designed with flexible alternatives that are often better than passing functions.
For example, instead of calling a key function on every item, you could instead define a macro
diff --git a/nomsu.6.peg b/nomsu.6.peg
index 6a1725a..344f679 100644
--- a/nomsu.6.peg
+++ b/nomsu.6.peg
@@ -190,7 +190,7 @@ real_number (Number) <-
(("-"? [0-9]+ "." [0-9]+)-> tonumber)
-variable (Var) <- "$" ({ident_char+} / "(" {(ws+ / operator_char+ / ident_char+)*} ")" / {''})
+variable (Var) <- "$" ({ident_char+} / "(" ws* inline_action ws* ")" / {''})
inline_list (List) <-
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 2b49112..c9f8fd6 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -473,7 +473,12 @@ local compile = setmetatable({
elseif "Number" == _exp_0 then
return LuaCode:from(tree.source, tostring(tree[1]))
elseif "Var" == _exp_0 then
- return LuaCode:from(tree.source, (concat(tree, " ")):as_lua_id())
+ if type(tree[1]) == 'string' then
+ return LuaCode:from(tree.source, (concat(tree, " ")):as_lua_id())
+ else
+ assert(tree[1].type == 'Action')
+ return LuaCode:from(tree.source, tree[1]:get_stub():as_lua_id())
+ end
elseif "FileChunks" == _exp_0 then
return error("Can't convert FileChunks to a single block of lua, since each chunk's " .. "compilation depends on the earlier chunks")
elseif "Comment" == _exp_0 then
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index 45e863d..0602f63 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -370,7 +370,11 @@ compile = setmetatable({
return LuaCode\from(tree.source, tostring(tree[1]))
when "Var"
- return LuaCode\from(tree.source, (concat(tree, " "))\as_lua_id!)
+ if type(tree[1]) == 'string'
+ return LuaCode\from(tree.source, (concat(tree, " "))\as_lua_id!)
+ else
+ assert(tree[1].type == 'Action')
+ return LuaCode\from(tree.source, tree[1]\get_stub!\as_lua_id!)
when "FileChunks"
error("Can't convert FileChunks to a single block of lua, since each chunk's "..
diff --git a/nomsu_decompiler.lua b/nomsu_decompiler.lua
index 1918ac2..bf04f4a 100644
--- a/nomsu_decompiler.lua
+++ b/nomsu_decompiler.lua
@@ -220,10 +220,10 @@ tree_to_inline_nomsu = function(tree)
return NomsuCode:from(tree.source, s)
elseif "Var" == _exp_0 then
local varname = tree[1]
- if varname == "" or is_identifier(varname) then
+ if type(varname) == "string" then
return NomsuCode:from(tree.source, "$", varname)
else
- return NomsuCode:from(tree.source, "$(", varname, ")")
+ return NomsuCode:from(tree.source, "$(", tree_to_inline_nomsu(varname), ")")
end
elseif "FileChunks" == _exp_0 then
return error("Can't inline a FileChunks")
diff --git a/nomsu_decompiler.moon b/nomsu_decompiler.moon
index 3deaabc..9d4face 100644
--- a/nomsu_decompiler.moon
+++ b/nomsu_decompiler.moon
@@ -165,10 +165,10 @@ tree_to_inline_nomsu = (tree)->
when "Var"
varname = tree[1]
- if varname == "" or is_identifier(varname)
+ if type(varname) == "string"
return NomsuCode\from(tree.source, "$", varname)
else
- return NomsuCode\from(tree.source, "$(", varname, ")")
+ return NomsuCode\from(tree.source, "$(", tree_to_inline_nomsu(varname), ")")
when "FileChunks"
error("Can't inline a FileChunks")