mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
Statement expressions
This commit is contained in:
parent
1d5390d0a7
commit
20e33c279e
4 changed files with 64 additions and 22 deletions
30
candran.lua
30
candran.lua
File diff suppressed because one or more lines are too long
|
|
@ -316,6 +316,30 @@ return function(code, ast, options)
|
|||
Paren = (t)
|
||||
return "(" .. lua(t[1]) .. ")"
|
||||
end,
|
||||
-- DoExpr{ stat* }
|
||||
DoExpr = (t)
|
||||
return "(function()" .. indent() .. lua(t, "Do") .. unindent() .. "end)()"
|
||||
end,
|
||||
-- WhileExpr{ expr block }
|
||||
WhileExpr = (t)
|
||||
return "(function()" .. indent() .. lua(t, "While") .. unindent() .. "end)()"
|
||||
end,
|
||||
-- RepeatExpr{ expr block }
|
||||
RepeatExpr = (t)
|
||||
return "(function()" .. indent() .. lua(t, "Repeat") .. unindent() .. "end)()"
|
||||
end,
|
||||
-- IfExpr{ (expr block)+ block? }
|
||||
IfExpr = (t)
|
||||
return "(function()" .. indent() .. lua(t, "If") .. unindent() .. "end)()"
|
||||
end,
|
||||
-- FornumExpr{ ident expr expr expr? block }
|
||||
FornumExpr = (t)
|
||||
return "(function()" .. indent() .. lua(t, "Fornum") .. unindent() .. "end)()"
|
||||
end,
|
||||
-- Forin{ {ident+} {expr+} block }
|
||||
ForninExpr = (t)
|
||||
return "(function()" .. indent() .. lua(t, "Forin") .. unindent() .. "end)()"
|
||||
end,
|
||||
-- apply (below)
|
||||
-- lhs (below)
|
||||
|
||||
|
|
|
|||
22
ideas.txt
22
ideas.txt
|
|
@ -20,7 +20,7 @@ Example rejected ideas:
|
|||
|
||||
Of course, if you really thinks these would be useful or you found a clever way of making theses work, feel free to open an issue or pull request and discuss.
|
||||
|
||||
Most of Candran's additions were inspired by MoonScript and CoffeeScript.
|
||||
Most of Candran's additions were inspired by MoonScript, CoffeeScript, and Lilia (https://love2d.org/forums/viewtopic.php?f=3&t=82650&sid=b6d9a8dec64afcc1c67806cb5ba65458).
|
||||
|
||||
Please note that the following ideas are just random though and won't be necessarly implemented, and some won't even work together.
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ local a = [x for x in pairs(stuff)]
|
|||
local a = [x for x in pairs(stuff) if x == true]
|
||||
local a = [x for x in pairs(stuff) if x == true for...]
|
||||
local a = x for x in pairs(stuff)
|
||||
local a = for x in pairs(stuff) do x
|
||||
local a = for x in pairs(stuff) do x end
|
||||
local no_color = {k,v for k,v in pairs(thing) if k ~= "color"}
|
||||
|
||||
local a = (x if x == true)
|
||||
|
|
@ -61,23 +61,6 @@ end)()
|
|||
|
||||
foo() if stuff > other end
|
||||
|
||||
* block expressions
|
||||
local a = do
|
||||
return true
|
||||
end
|
||||
->
|
||||
local a = (()
|
||||
return true
|
||||
end)()
|
||||
|
||||
local a = if x == true then
|
||||
return a
|
||||
end
|
||||
|
||||
With implicits returns?...
|
||||
|
||||
local stuff = for ... (accumulate in a table)
|
||||
|
||||
* try / except|catch / finally / else / other keywords
|
||||
try
|
||||
error("hey")
|
||||
|
|
@ -125,7 +108,6 @@ And in implicit assignments:
|
|||
for i, {x, y} in ipairs(positions) do
|
||||
|
||||
* Other potential inspiration
|
||||
https://love2d.org/forums/viewtopic.php?f=3&t=82650&sid=b6d9a8dec64afcc1c67806cb5ba65458
|
||||
https://www.ruby-lang.org/fr/
|
||||
|
||||
Well done, you're at the end of the file!
|
||||
|
|
|
|||
|
|
@ -268,6 +268,11 @@ local function fixAnonymousMethodParams(t1, t2)
|
|||
return t1
|
||||
end
|
||||
|
||||
local function statToExpr(t)
|
||||
t.tag = t.tag .. "Expr"
|
||||
return t
|
||||
end
|
||||
|
||||
-- grammar
|
||||
local G = { V"Lua",
|
||||
Lua = V"Shebang"^-1 * V"Skip" * V"Block" * expect(P(-1), "Extra");
|
||||
|
|
@ -353,7 +358,10 @@ local G = { V"Lua",
|
|||
+ tagC("Dots", sym("..."))
|
||||
+ V"FuncDef"
|
||||
+ V"Table"
|
||||
+ V"SuffixedExpr";
|
||||
+ V"SuffixedExpr"
|
||||
+ V"StatExpr";
|
||||
|
||||
StatExpr = (V"IfStat" + V"DoStat" + V"WhileStat" + V"RepeatStat" + V"ForStat") / statToExpr;
|
||||
|
||||
FuncCall = Cmt(V"SuffixedExpr", function(s, i, exp) return exp.tag == "Call" or exp.tag == "Invoke", exp end);
|
||||
VarExpr = Cmt(V"SuffixedExpr", function(s, i, exp) return exp.tag == "Id" or exp.tag == "Index", exp end);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue