mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
Added suffixable string and table litterals
This commit is contained in:
parent
30a10d6ed9
commit
98a6a87962
6 changed files with 271 additions and 138 deletions
18
README.md
18
README.md
|
|
@ -252,6 +252,24 @@ end
|
||||||
|
|
||||||
`if`, `elseif`, `for`, and `while` statements can be writtent without `do`, `then` or `end`, in which case they contain a single statement.
|
`if`, `elseif`, `for`, and `while` statements can be writtent without `do`, `then` or `end`, in which case they contain a single statement.
|
||||||
|
|
||||||
|
##### Suffixable string and table litterals
|
||||||
|
_Not in the latest release, install the `candran-scm-1.rockspec` version if you want this feature._
|
||||||
|
```lua
|
||||||
|
"some text":upper() -- same as ("some text"):upper() in Lua
|
||||||
|
"string".upper -- the actual string.upper function. "string"["upper"] also works.
|
||||||
|
-- Also works with calls, for example "string"(), but it isn't really useful for strings.
|
||||||
|
|
||||||
|
{thing = 3}.thing -- 3. Also works with tables!
|
||||||
|
[for i=0,5 do i*i end][3] -- 9. And table comprehensions!
|
||||||
|
|
||||||
|
-- Functions calls have priority:
|
||||||
|
someFunction"thing":upper() -- same as (someFunction("thing")):upper() (i.e., the way it would be parsed by Lua)
|
||||||
|
```
|
||||||
|
|
||||||
|
String litterals, table litterals, and comprehensions can be suffixed with `:` method calls, `.` or `[` indexing, or `(` functions calls, without needing to be enclosed in parantheses.
|
||||||
|
|
||||||
|
*Please note*, that "normal" functions calls have priority over this syntax, in order to maintain Lua compatibility.
|
||||||
|
|
||||||
### Preprocessor
|
### Preprocessor
|
||||||
Before compiling, Candran's preprocessor is run. It execute every line starting with a _#_ (ignoring prefixing whitespace, long strings and comments) as Candran code.
|
Before compiling, Candran's preprocessor is run. It execute every line starting with a _#_ (ignoring prefixing whitespace, long strings and comments) as Candran code.
|
||||||
For example,
|
For example,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#import("lib.lua-parser.parser")
|
#import("lib.lua-parser.parser")
|
||||||
|
|
||||||
local candran = {
|
local candran = {
|
||||||
VERSION = "0.6.2"
|
VERSION = "0.7.0-dev"
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Default options.
|
--- Default options.
|
||||||
|
|
|
||||||
284
candran.lua
284
candran.lua
|
|
@ -629,68 +629,80 @@ end, -- ./compiler/lua53.can:494
|
||||||
return lua(t, "_statexpr", "Forin") -- ./compiler/lua53.can:498
|
return lua(t, "_statexpr", "Forin") -- ./compiler/lua53.can:498
|
||||||
end, -- ./compiler/lua53.can:498
|
end, -- ./compiler/lua53.can:498
|
||||||
["Call"] = function(t) -- ./compiler/lua53.can:504
|
["Call"] = function(t) -- ./compiler/lua53.can:504
|
||||||
return lua(t[1]) .. "(" .. lua(t, "_lhs", 2) .. ")" -- ./compiler/lua53.can:505
|
if t[1]["tag"] == "String" or t[1]["tag"] == "Table" then -- ./compiler/lua53.can:505
|
||||||
end, -- ./compiler/lua53.can:505
|
return "(" .. lua(t[1]) .. ")(" .. lua(t, "_lhs", 2) .. ")" -- ./compiler/lua53.can:506
|
||||||
["Invoke"] = function(t) -- ./compiler/lua53.can:509
|
else -- ./compiler/lua53.can:506
|
||||||
return lua(t[1]) .. ":" .. lua(t[2], "Id") .. "(" .. lua(t, "_lhs", 3) .. ")" -- ./compiler/lua53.can:510
|
return lua(t[1]) .. "(" .. lua(t, "_lhs", 2) .. ")" -- ./compiler/lua53.can:508
|
||||||
end, -- ./compiler/lua53.can:510
|
end -- ./compiler/lua53.can:508
|
||||||
["_lhs"] = function(t, start, newlines) -- ./compiler/lua53.can:514
|
end, -- ./compiler/lua53.can:508
|
||||||
if start == nil then start = 1 end -- ./compiler/lua53.can:514
|
["Invoke"] = function(t) -- ./compiler/lua53.can:513
|
||||||
local r -- ./compiler/lua53.can:515
|
if t[1]["tag"] == "String" or t[1]["tag"] == "Table" then -- ./compiler/lua53.can:514
|
||||||
if t[start] then -- ./compiler/lua53.can:516
|
return "(" .. lua(t[1]) .. "):" .. lua(t[2], "Id") .. "(" .. lua(t, "_lhs", 3) .. ")" -- ./compiler/lua53.can:515
|
||||||
r = lua(t[start]) -- ./compiler/lua53.can:517
|
else -- ./compiler/lua53.can:515
|
||||||
for i = start + 1, # t, 1 do -- ./compiler/lua53.can:518
|
return lua(t[1]) .. ":" .. lua(t[2], "Id") .. "(" .. lua(t, "_lhs", 3) .. ")" -- ./compiler/lua53.can:517
|
||||||
r = r .. ("," .. (newlines and newline() or " ") .. lua(t[i])) -- ./compiler/lua53.can:519
|
end -- ./compiler/lua53.can:517
|
||||||
end -- ./compiler/lua53.can:519
|
end, -- ./compiler/lua53.can:517
|
||||||
else -- ./compiler/lua53.can:519
|
["_lhs"] = function(t, start, newlines) -- ./compiler/lua53.can:522
|
||||||
r = "" -- ./compiler/lua53.can:522
|
if start == nil then start = 1 end -- ./compiler/lua53.can:522
|
||||||
end -- ./compiler/lua53.can:522
|
local r -- ./compiler/lua53.can:523
|
||||||
return r -- ./compiler/lua53.can:524
|
if t[start] then -- ./compiler/lua53.can:524
|
||||||
end, -- ./compiler/lua53.can:524
|
r = lua(t[start]) -- ./compiler/lua53.can:525
|
||||||
["Id"] = function(t) -- ./compiler/lua53.can:527
|
for i = start + 1, # t, 1 do -- ./compiler/lua53.can:526
|
||||||
return t[1] -- ./compiler/lua53.can:528
|
r = r .. ("," .. (newlines and newline() or " ") .. lua(t[i])) -- ./compiler/lua53.can:527
|
||||||
end, -- ./compiler/lua53.can:528
|
end -- ./compiler/lua53.can:527
|
||||||
["Index"] = function(t) -- ./compiler/lua53.can:531
|
else -- ./compiler/lua53.can:527
|
||||||
return lua(t[1]) .. "[" .. lua(t[2]) .. "]" -- ./compiler/lua53.can:532
|
r = "" -- ./compiler/lua53.can:530
|
||||||
|
end -- ./compiler/lua53.can:530
|
||||||
|
return r -- ./compiler/lua53.can:532
|
||||||
end, -- ./compiler/lua53.can:532
|
end, -- ./compiler/lua53.can:532
|
||||||
["_opid"] = { -- ./compiler/lua53.can:536
|
["Id"] = function(t) -- ./compiler/lua53.can:535
|
||||||
["add"] = "+", -- ./compiler/lua53.can:537
|
return t[1] -- ./compiler/lua53.can:536
|
||||||
["sub"] = "-", -- ./compiler/lua53.can:537
|
end, -- ./compiler/lua53.can:536
|
||||||
["mul"] = "*", -- ./compiler/lua53.can:537
|
["Index"] = function(t) -- ./compiler/lua53.can:539
|
||||||
["div"] = "/", -- ./compiler/lua53.can:537
|
if t[1]["tag"] == "String" or t[1]["tag"] == "Table" then -- ./compiler/lua53.can:540
|
||||||
["idiv"] = "//", -- ./compiler/lua53.can:538
|
return "(" .. lua(t[1]) .. ")[" .. lua(t[2]) .. "]" -- ./compiler/lua53.can:541
|
||||||
["mod"] = "%", -- ./compiler/lua53.can:538
|
else -- ./compiler/lua53.can:541
|
||||||
["pow"] = "^", -- ./compiler/lua53.can:538
|
return lua(t[1]) .. "[" .. lua(t[2]) .. "]" -- ./compiler/lua53.can:543
|
||||||
["concat"] = "..", -- ./compiler/lua53.can:538
|
end -- ./compiler/lua53.can:543
|
||||||
["band"] = "&", -- ./compiler/lua53.can:539
|
end, -- ./compiler/lua53.can:543
|
||||||
["bor"] = "|", -- ./compiler/lua53.can:539
|
["_opid"] = { -- ./compiler/lua53.can:548
|
||||||
["bxor"] = "~", -- ./compiler/lua53.can:539
|
["add"] = "+", -- ./compiler/lua53.can:549
|
||||||
["shl"] = "<<", -- ./compiler/lua53.can:539
|
["sub"] = "-", -- ./compiler/lua53.can:549
|
||||||
["shr"] = ">>", -- ./compiler/lua53.can:539
|
["mul"] = "*", -- ./compiler/lua53.can:549
|
||||||
["eq"] = "==", -- ./compiler/lua53.can:540
|
["div"] = "/", -- ./compiler/lua53.can:549
|
||||||
["ne"] = "~=", -- ./compiler/lua53.can:540
|
["idiv"] = "//", -- ./compiler/lua53.can:550
|
||||||
["lt"] = "<", -- ./compiler/lua53.can:540
|
["mod"] = "%", -- ./compiler/lua53.can:550
|
||||||
["gt"] = ">", -- ./compiler/lua53.can:540
|
["pow"] = "^", -- ./compiler/lua53.can:550
|
||||||
["le"] = "<=", -- ./compiler/lua53.can:540
|
["concat"] = "..", -- ./compiler/lua53.can:550
|
||||||
["ge"] = ">=", -- ./compiler/lua53.can:540
|
["band"] = "&", -- ./compiler/lua53.can:551
|
||||||
["and"] = "and", -- ./compiler/lua53.can:541
|
["bor"] = "|", -- ./compiler/lua53.can:551
|
||||||
["or"] = "or", -- ./compiler/lua53.can:541
|
["bxor"] = "~", -- ./compiler/lua53.can:551
|
||||||
["unm"] = "-", -- ./compiler/lua53.can:541
|
["shl"] = "<<", -- ./compiler/lua53.can:551
|
||||||
["len"] = "#", -- ./compiler/lua53.can:541
|
["shr"] = ">>", -- ./compiler/lua53.can:551
|
||||||
["bnot"] = "~", -- ./compiler/lua53.can:541
|
["eq"] = "==", -- ./compiler/lua53.can:552
|
||||||
["not"] = "not" -- ./compiler/lua53.can:541
|
["ne"] = "~=", -- ./compiler/lua53.can:552
|
||||||
} -- ./compiler/lua53.can:541
|
["lt"] = "<", -- ./compiler/lua53.can:552
|
||||||
}, { ["__index"] = function(self, key) -- ./compiler/lua53.can:544
|
["gt"] = ">", -- ./compiler/lua53.can:552
|
||||||
error("don't know how to compile a " .. tostring(key) .. " to Lua 5.3") -- ./compiler/lua53.can:545
|
["le"] = "<=", -- ./compiler/lua53.can:552
|
||||||
end }) -- ./compiler/lua53.can:545
|
["ge"] = ">=", -- ./compiler/lua53.can:552
|
||||||
local code = lua(ast) .. newline() -- ./compiler/lua53.can:551
|
["and"] = "and", -- ./compiler/lua53.can:553
|
||||||
return requireStr .. code -- ./compiler/lua53.can:552
|
["or"] = "or", -- ./compiler/lua53.can:553
|
||||||
end -- ./compiler/lua53.can:552
|
["unm"] = "-", -- ./compiler/lua53.can:553
|
||||||
end -- ./compiler/lua53.can:552
|
["len"] = "#", -- ./compiler/lua53.can:553
|
||||||
local lua53 = _() or lua53 -- ./compiler/lua53.can:557
|
["bnot"] = "~", -- ./compiler/lua53.can:553
|
||||||
package["loaded"]["compiler.lua53"] = lua53 or true -- ./compiler/lua53.can:558
|
["not"] = "not" -- ./compiler/lua53.can:553
|
||||||
local function _() -- ./compiler/lua53.can:561
|
} -- ./compiler/lua53.can:553
|
||||||
local function _() -- ./compiler/lua53.can:563
|
}, { ["__index"] = function(self, key) -- ./compiler/lua53.can:556
|
||||||
|
error("don't know how to compile a " .. tostring(key) .. " to Lua 5.3") -- ./compiler/lua53.can:557
|
||||||
|
end }) -- ./compiler/lua53.can:557
|
||||||
|
local code = lua(ast) .. newline() -- ./compiler/lua53.can:563
|
||||||
|
return requireStr .. code -- ./compiler/lua53.can:564
|
||||||
|
end -- ./compiler/lua53.can:564
|
||||||
|
end -- ./compiler/lua53.can:564
|
||||||
|
local lua53 = _() or lua53 -- ./compiler/lua53.can:569
|
||||||
|
package["loaded"]["compiler.lua53"] = lua53 or true -- ./compiler/lua53.can:570
|
||||||
|
local function _() -- ./compiler/lua53.can:573
|
||||||
|
local function _() -- ./compiler/lua53.can:575
|
||||||
return function(code, ast, options) -- ./compiler/lua53.can:1
|
return function(code, ast, options) -- ./compiler/lua53.can:1
|
||||||
local lastInputPos = 1 -- last token position in the input code -- ./compiler/lua53.can:3
|
local lastInputPos = 1 -- last token position in the input code -- ./compiler/lua53.can:3
|
||||||
local prevLinePos = 1 -- last token position in the previous line of code in the input code -- ./compiler/lua53.can:4
|
local prevLinePos = 1 -- last token position in the previous line of code in the input code -- ./compiler/lua53.can:4
|
||||||
|
|
@ -1188,60 +1200,72 @@ end, -- ./compiler/lua53.can:494
|
||||||
return lua(t, "_statexpr", "Forin") -- ./compiler/lua53.can:498
|
return lua(t, "_statexpr", "Forin") -- ./compiler/lua53.can:498
|
||||||
end, -- ./compiler/lua53.can:498
|
end, -- ./compiler/lua53.can:498
|
||||||
["Call"] = function(t) -- ./compiler/lua53.can:504
|
["Call"] = function(t) -- ./compiler/lua53.can:504
|
||||||
return lua(t[1]) .. "(" .. lua(t, "_lhs", 2) .. ")" -- ./compiler/lua53.can:505
|
if t[1]["tag"] == "String" or t[1]["tag"] == "Table" then -- ./compiler/lua53.can:505
|
||||||
end, -- ./compiler/lua53.can:505
|
return "(" .. lua(t[1]) .. ")(" .. lua(t, "_lhs", 2) .. ")" -- ./compiler/lua53.can:506
|
||||||
["Invoke"] = function(t) -- ./compiler/lua53.can:509
|
else -- ./compiler/lua53.can:506
|
||||||
return lua(t[1]) .. ":" .. lua(t[2], "Id") .. "(" .. lua(t, "_lhs", 3) .. ")" -- ./compiler/lua53.can:510
|
return lua(t[1]) .. "(" .. lua(t, "_lhs", 2) .. ")" -- ./compiler/lua53.can:508
|
||||||
end, -- ./compiler/lua53.can:510
|
end -- ./compiler/lua53.can:508
|
||||||
["_lhs"] = function(t, start, newlines) -- ./compiler/lua53.can:514
|
end, -- ./compiler/lua53.can:508
|
||||||
if start == nil then start = 1 end -- ./compiler/lua53.can:514
|
["Invoke"] = function(t) -- ./compiler/lua53.can:513
|
||||||
local r -- ./compiler/lua53.can:515
|
if t[1]["tag"] == "String" or t[1]["tag"] == "Table" then -- ./compiler/lua53.can:514
|
||||||
if t[start] then -- ./compiler/lua53.can:516
|
return "(" .. lua(t[1]) .. "):" .. lua(t[2], "Id") .. "(" .. lua(t, "_lhs", 3) .. ")" -- ./compiler/lua53.can:515
|
||||||
r = lua(t[start]) -- ./compiler/lua53.can:517
|
else -- ./compiler/lua53.can:515
|
||||||
for i = start + 1, # t, 1 do -- ./compiler/lua53.can:518
|
return lua(t[1]) .. ":" .. lua(t[2], "Id") .. "(" .. lua(t, "_lhs", 3) .. ")" -- ./compiler/lua53.can:517
|
||||||
r = r .. ("," .. (newlines and newline() or " ") .. lua(t[i])) -- ./compiler/lua53.can:519
|
end -- ./compiler/lua53.can:517
|
||||||
end -- ./compiler/lua53.can:519
|
end, -- ./compiler/lua53.can:517
|
||||||
else -- ./compiler/lua53.can:519
|
["_lhs"] = function(t, start, newlines) -- ./compiler/lua53.can:522
|
||||||
r = "" -- ./compiler/lua53.can:522
|
if start == nil then start = 1 end -- ./compiler/lua53.can:522
|
||||||
end -- ./compiler/lua53.can:522
|
local r -- ./compiler/lua53.can:523
|
||||||
return r -- ./compiler/lua53.can:524
|
if t[start] then -- ./compiler/lua53.can:524
|
||||||
end, -- ./compiler/lua53.can:524
|
r = lua(t[start]) -- ./compiler/lua53.can:525
|
||||||
["Id"] = function(t) -- ./compiler/lua53.can:527
|
for i = start + 1, # t, 1 do -- ./compiler/lua53.can:526
|
||||||
return t[1] -- ./compiler/lua53.can:528
|
r = r .. ("," .. (newlines and newline() or " ") .. lua(t[i])) -- ./compiler/lua53.can:527
|
||||||
end, -- ./compiler/lua53.can:528
|
end -- ./compiler/lua53.can:527
|
||||||
["Index"] = function(t) -- ./compiler/lua53.can:531
|
else -- ./compiler/lua53.can:527
|
||||||
return lua(t[1]) .. "[" .. lua(t[2]) .. "]" -- ./compiler/lua53.can:532
|
r = "" -- ./compiler/lua53.can:530
|
||||||
|
end -- ./compiler/lua53.can:530
|
||||||
|
return r -- ./compiler/lua53.can:532
|
||||||
end, -- ./compiler/lua53.can:532
|
end, -- ./compiler/lua53.can:532
|
||||||
["_opid"] = { -- ./compiler/lua53.can:536
|
["Id"] = function(t) -- ./compiler/lua53.can:535
|
||||||
["add"] = "+", -- ./compiler/lua53.can:537
|
return t[1] -- ./compiler/lua53.can:536
|
||||||
["sub"] = "-", -- ./compiler/lua53.can:537
|
end, -- ./compiler/lua53.can:536
|
||||||
["mul"] = "*", -- ./compiler/lua53.can:537
|
["Index"] = function(t) -- ./compiler/lua53.can:539
|
||||||
["div"] = "/", -- ./compiler/lua53.can:537
|
if t[1]["tag"] == "String" or t[1]["tag"] == "Table" then -- ./compiler/lua53.can:540
|
||||||
["idiv"] = "//", -- ./compiler/lua53.can:538
|
return "(" .. lua(t[1]) .. ")[" .. lua(t[2]) .. "]" -- ./compiler/lua53.can:541
|
||||||
["mod"] = "%", -- ./compiler/lua53.can:538
|
else -- ./compiler/lua53.can:541
|
||||||
["pow"] = "^", -- ./compiler/lua53.can:538
|
return lua(t[1]) .. "[" .. lua(t[2]) .. "]" -- ./compiler/lua53.can:543
|
||||||
["concat"] = "..", -- ./compiler/lua53.can:538
|
end -- ./compiler/lua53.can:543
|
||||||
["band"] = "&", -- ./compiler/lua53.can:539
|
end, -- ./compiler/lua53.can:543
|
||||||
["bor"] = "|", -- ./compiler/lua53.can:539
|
["_opid"] = { -- ./compiler/lua53.can:548
|
||||||
["bxor"] = "~", -- ./compiler/lua53.can:539
|
["add"] = "+", -- ./compiler/lua53.can:549
|
||||||
["shl"] = "<<", -- ./compiler/lua53.can:539
|
["sub"] = "-", -- ./compiler/lua53.can:549
|
||||||
["shr"] = ">>", -- ./compiler/lua53.can:539
|
["mul"] = "*", -- ./compiler/lua53.can:549
|
||||||
["eq"] = "==", -- ./compiler/lua53.can:540
|
["div"] = "/", -- ./compiler/lua53.can:549
|
||||||
["ne"] = "~=", -- ./compiler/lua53.can:540
|
["idiv"] = "//", -- ./compiler/lua53.can:550
|
||||||
["lt"] = "<", -- ./compiler/lua53.can:540
|
["mod"] = "%", -- ./compiler/lua53.can:550
|
||||||
["gt"] = ">", -- ./compiler/lua53.can:540
|
["pow"] = "^", -- ./compiler/lua53.can:550
|
||||||
["le"] = "<=", -- ./compiler/lua53.can:540
|
["concat"] = "..", -- ./compiler/lua53.can:550
|
||||||
["ge"] = ">=", -- ./compiler/lua53.can:540
|
["band"] = "&", -- ./compiler/lua53.can:551
|
||||||
["and"] = "and", -- ./compiler/lua53.can:541
|
["bor"] = "|", -- ./compiler/lua53.can:551
|
||||||
["or"] = "or", -- ./compiler/lua53.can:541
|
["bxor"] = "~", -- ./compiler/lua53.can:551
|
||||||
["unm"] = "-", -- ./compiler/lua53.can:541
|
["shl"] = "<<", -- ./compiler/lua53.can:551
|
||||||
["len"] = "#", -- ./compiler/lua53.can:541
|
["shr"] = ">>", -- ./compiler/lua53.can:551
|
||||||
["bnot"] = "~", -- ./compiler/lua53.can:541
|
["eq"] = "==", -- ./compiler/lua53.can:552
|
||||||
["not"] = "not" -- ./compiler/lua53.can:541
|
["ne"] = "~=", -- ./compiler/lua53.can:552
|
||||||
} -- ./compiler/lua53.can:541
|
["lt"] = "<", -- ./compiler/lua53.can:552
|
||||||
}, { ["__index"] = function(self, key) -- ./compiler/lua53.can:544
|
["gt"] = ">", -- ./compiler/lua53.can:552
|
||||||
error("don't know how to compile a " .. tostring(key) .. " to Lua 5.3") -- ./compiler/lua53.can:545
|
["le"] = "<=", -- ./compiler/lua53.can:552
|
||||||
end }) -- ./compiler/lua53.can:545
|
["ge"] = ">=", -- ./compiler/lua53.can:552
|
||||||
|
["and"] = "and", -- ./compiler/lua53.can:553
|
||||||
|
["or"] = "or", -- ./compiler/lua53.can:553
|
||||||
|
["unm"] = "-", -- ./compiler/lua53.can:553
|
||||||
|
["len"] = "#", -- ./compiler/lua53.can:553
|
||||||
|
["bnot"] = "~", -- ./compiler/lua53.can:553
|
||||||
|
["not"] = "not" -- ./compiler/lua53.can:553
|
||||||
|
} -- ./compiler/lua53.can:553
|
||||||
|
}, { ["__index"] = function(self, key) -- ./compiler/lua53.can:556
|
||||||
|
error("don't know how to compile a " .. tostring(key) .. " to Lua 5.3") -- ./compiler/lua53.can:557
|
||||||
|
end }) -- ./compiler/lua53.can:557
|
||||||
UNPACK = function(list, i, j) -- ./compiler/luajit.can:1
|
UNPACK = function(list, i, j) -- ./compiler/luajit.can:1
|
||||||
return "unpack(" .. list .. (i and (", " .. i .. (j and (", " .. j) or "")) or "") .. ")" -- ./compiler/luajit.can:2
|
return "unpack(" .. list .. (i and (", " .. i .. (j and (", " .. j) or "")) or "") .. ")" -- ./compiler/luajit.can:2
|
||||||
end -- ./compiler/luajit.can:2
|
end -- ./compiler/luajit.can:2
|
||||||
|
|
@ -1275,11 +1299,11 @@ tags["_opid"]["bnot"] = function(right) -- ./compiler/luajit.can:31
|
||||||
addRequire("bit", "bnot", "bnot") -- ./compiler/luajit.can:32
|
addRequire("bit", "bnot", "bnot") -- ./compiler/luajit.can:32
|
||||||
return var("bnot") .. "(" .. lua(right) .. ")" -- ./compiler/luajit.can:33
|
return var("bnot") .. "(" .. lua(right) .. ")" -- ./compiler/luajit.can:33
|
||||||
end -- ./compiler/luajit.can:33
|
end -- ./compiler/luajit.can:33
|
||||||
local code = lua(ast) .. newline() -- ./compiler/lua53.can:551
|
local code = lua(ast) .. newline() -- ./compiler/lua53.can:563
|
||||||
return requireStr .. code -- ./compiler/lua53.can:552
|
return requireStr .. code -- ./compiler/lua53.can:564
|
||||||
end -- ./compiler/lua53.can:552
|
end -- ./compiler/lua53.can:564
|
||||||
end -- ./compiler/lua53.can:552
|
end -- ./compiler/lua53.can:564
|
||||||
local lua53 = _() or lua53 -- ./compiler/lua53.can:557
|
local lua53 = _() or lua53 -- ./compiler/lua53.can:569
|
||||||
return lua53 -- ./compiler/luajit.can:40
|
return lua53 -- ./compiler/luajit.can:40
|
||||||
end -- ./compiler/luajit.can:40
|
end -- ./compiler/luajit.can:40
|
||||||
local luajit = _() or luajit -- ./compiler/luajit.can:44
|
local luajit = _() or luajit -- ./compiler/luajit.can:44
|
||||||
|
|
@ -2806,16 +2830,16 @@ end, -- ./lib/lua-parser/parser.lua:450
|
||||||
["MulExpr"] = chainOp(V("UnaryExpr"), V("MulOp"), "MulExpr"), -- ./lib/lua-parser/parser.lua:519
|
["MulExpr"] = chainOp(V("UnaryExpr"), V("MulOp"), "MulExpr"), -- ./lib/lua-parser/parser.lua:519
|
||||||
["UnaryExpr"] = V("UnaryOp") * expect(V("UnaryExpr"), "UnaryExpr") / unaryOp + V("PowExpr"), -- ./lib/lua-parser/parser.lua:521
|
["UnaryExpr"] = V("UnaryOp") * expect(V("UnaryExpr"), "UnaryExpr") / unaryOp + V("PowExpr"), -- ./lib/lua-parser/parser.lua:521
|
||||||
["PowExpr"] = V("SimpleExpr") * (V("PowOp") * expect(V("UnaryExpr"), "PowExpr")) ^ - 1 / binaryOp, -- ./lib/lua-parser/parser.lua:522
|
["PowExpr"] = V("SimpleExpr") * (V("PowOp") * expect(V("UnaryExpr"), "PowExpr")) ^ - 1 / binaryOp, -- ./lib/lua-parser/parser.lua:522
|
||||||
["SimpleExpr"] = tagC("Number", V("Number")) + tagC("String", V("String")) + tagC("Nil", kw("nil")) + tagC("Boolean", kw("false") * Cc(false)) + tagC("Boolean", kw("true") * Cc(true)) + tagC("Dots", sym("...")) + V("FuncDef") + V("Table") + V("ShortFuncDef") + V("SuffixedExpr") + V("TableCompr") + V("StatExpr"), -- ./lib/lua-parser/parser.lua:535
|
["SimpleExpr"] = tagC("Number", V("Number")) + tagC("Nil", kw("nil")) + tagC("Boolean", kw("false") * Cc(false)) + tagC("Boolean", kw("true") * Cc(true)) + tagC("Dots", sym("...")) + V("FuncDef") + V("ShortFuncDef") + V("SuffixedExpr") + V("StatExpr"), -- ./lib/lua-parser/parser.lua:532
|
||||||
["StatExpr"] = (V("IfStat") + V("DoStat") + V("WhileStat") + V("RepeatStat") + V("ForStat")) / statToExpr, -- ./lib/lua-parser/parser.lua:537
|
["StatExpr"] = (V("IfStat") + V("DoStat") + V("WhileStat") + V("RepeatStat") + V("ForStat")) / statToExpr, -- ./lib/lua-parser/parser.lua:534
|
||||||
["FuncCall"] = Cmt(V("SuffixedExpr"), function(s, i, exp) -- ./lib/lua-parser/parser.lua:539
|
["FuncCall"] = Cmt(V("SuffixedExpr"), function(s, i, exp) -- ./lib/lua-parser/parser.lua:536
|
||||||
return exp["tag"] == "Call" or exp["tag"] == "Invoke", exp -- ./lib/lua-parser/parser.lua:539
|
return exp["tag"] == "Call" or exp["tag"] == "Invoke", exp -- ./lib/lua-parser/parser.lua:536
|
||||||
end), -- ./lib/lua-parser/parser.lua:539
|
end), -- ./lib/lua-parser/parser.lua:536
|
||||||
["VarExpr"] = Cmt(V("SuffixedExpr"), function(s, i, exp) -- ./lib/lua-parser/parser.lua:540
|
["VarExpr"] = Cmt(V("SuffixedExpr"), function(s, i, exp) -- ./lib/lua-parser/parser.lua:537
|
||||||
return exp["tag"] == "Id" or exp["tag"] == "Index", exp -- ./lib/lua-parser/parser.lua:540
|
return exp["tag"] == "Id" or exp["tag"] == "Index", exp -- ./lib/lua-parser/parser.lua:537
|
||||||
end), -- ./lib/lua-parser/parser.lua:540
|
end), -- ./lib/lua-parser/parser.lua:537
|
||||||
["SuffixedExpr"] = Cf(V("PrimaryExpr") * (V("Index") + V("Call")) ^ 0, makeIndexOrCall), -- ./lib/lua-parser/parser.lua:542
|
["SuffixedExpr"] = Cf(V("PrimaryExpr") * (V("Index") + V("Call")) ^ 0, makeIndexOrCall), -- ./lib/lua-parser/parser.lua:539
|
||||||
["PrimaryExpr"] = V("SelfId") * (V("SelfCall") + V("SelfIndex")) + V("Id") + tagC("Paren", sym("(") * expect(V("Expr"), "ExprParen") * expect(sym(")"), "CParenExpr")), -- ./lib/lua-parser/parser.lua:545
|
["PrimaryExpr"] = V("SelfId") * (V("SelfCall") + V("SelfIndex")) + V("Id") + tagC("Paren", sym("(") * expect(V("Expr"), "ExprParen") * expect(sym(")"), "CParenExpr")) + tagC("String", V("String")) + V("Table") + V("TableCompr"), -- ./lib/lua-parser/parser.lua:545
|
||||||
["Index"] = tagC("DotIndex", sym("." * - P(".")) * expect(V("StrId"), "NameIndex")) + tagC("ArrayIndex", sym("[" * - P(S("=["))) * expect(V("Expr"), "ExprIndex") * expect(sym("]"), "CBracketIndex")), -- ./lib/lua-parser/parser.lua:547
|
["Index"] = tagC("DotIndex", sym("." * - P(".")) * expect(V("StrId"), "NameIndex")) + tagC("ArrayIndex", sym("[" * - P(S("=["))) * expect(V("Expr"), "ExprIndex") * expect(sym("]"), "CBracketIndex")), -- ./lib/lua-parser/parser.lua:547
|
||||||
["Call"] = tagC("Invoke", Cg(sym(":" * - P(":")) * expect(V("StrId"), "NameMeth") * expect(V("FuncArgs"), "MethArgs"))) + tagC("Call", V("FuncArgs")), -- ./lib/lua-parser/parser.lua:549
|
["Call"] = tagC("Invoke", Cg(sym(":" * - P(":")) * expect(V("StrId"), "NameMeth") * expect(V("FuncArgs"), "MethArgs"))) + tagC("Call", V("FuncArgs")), -- ./lib/lua-parser/parser.lua:549
|
||||||
["SelfIndex"] = tagC("DotIndex", V("StrId")), -- ./lib/lua-parser/parser.lua:550
|
["SelfIndex"] = tagC("DotIndex", V("StrId")), -- ./lib/lua-parser/parser.lua:550
|
||||||
|
|
@ -2905,7 +2929,7 @@ return parser -- ./lib/lua-parser/parser.lua:685
|
||||||
end -- ./lib/lua-parser/parser.lua:685
|
end -- ./lib/lua-parser/parser.lua:685
|
||||||
local parser = _() or parser -- ./lib/lua-parser/parser.lua:689
|
local parser = _() or parser -- ./lib/lua-parser/parser.lua:689
|
||||||
package["loaded"]["lib.lua-parser.parser"] = parser or true -- ./lib/lua-parser/parser.lua:690
|
package["loaded"]["lib.lua-parser.parser"] = parser or true -- ./lib/lua-parser/parser.lua:690
|
||||||
local candran = { ["VERSION"] = "0.6.2" } -- candran.can:13
|
local candran = { ["VERSION"] = "0.7.0-dev" } -- candran.can:13
|
||||||
candran["default"] = { -- candran.can:17
|
candran["default"] = { -- candran.can:17
|
||||||
["target"] = "lua53", -- candran.can:18
|
["target"] = "lua53", -- candran.can:18
|
||||||
["indentation"] = "", -- candran.can:19
|
["indentation"] = "", -- candran.can:19
|
||||||
|
|
|
||||||
|
|
@ -502,12 +502,20 @@ return function(code, ast, options)
|
||||||
|
|
||||||
-- Call{ expr expr* }
|
-- Call{ expr expr* }
|
||||||
Call = (t)
|
Call = (t)
|
||||||
|
if t[1].tag == "String" or t[1].tag == "Table" then
|
||||||
|
return "("..lua(t[1]) .. ")(" .. lua(t, "_lhs", 2) .. ")"
|
||||||
|
else
|
||||||
return lua(t[1]) .. "(" .. lua(t, "_lhs", 2) .. ")"
|
return lua(t[1]) .. "(" .. lua(t, "_lhs", 2) .. ")"
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Invoke{ expr `String{ <string> } expr* }
|
-- Invoke{ expr `String{ <string> } expr* }
|
||||||
Invoke = (t)
|
Invoke = (t)
|
||||||
|
if t[1].tag == "String" or t[1].tag == "Table" then
|
||||||
|
return "("..lua(t[1]).."):"..lua(t[2], "Id").."("..lua(t, "_lhs", 3)..")"
|
||||||
|
else
|
||||||
return lua(t[1])..":"..lua(t[2], "Id").."("..lua(t, "_lhs", 3)..")"
|
return lua(t[1])..":"..lua(t[2], "Id").."("..lua(t, "_lhs", 3)..")"
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- lhs --
|
-- lhs --
|
||||||
|
|
@ -529,7 +537,11 @@ return function(code, ast, options)
|
||||||
end,
|
end,
|
||||||
-- Index{ expr expr }
|
-- Index{ expr expr }
|
||||||
Index = (t)
|
Index = (t)
|
||||||
|
if t[1].tag == "String" or t[1].tag == "Table" then
|
||||||
|
return "("..lua(t[1])..")["..lua(t[2]).."]"
|
||||||
|
else
|
||||||
return lua(t[1]).."["..lua(t[2]).."]"
|
return lua(t[1]).."["..lua(t[2]).."]"
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- opid --
|
-- opid --
|
||||||
|
|
|
||||||
|
|
@ -522,16 +522,13 @@ local G = { V"Lua",
|
||||||
PowExpr = V"SimpleExpr" * (V"PowOp" * expect(V"UnaryExpr", "PowExpr"))^-1 / binaryOp;
|
PowExpr = V"SimpleExpr" * (V"PowOp" * expect(V"UnaryExpr", "PowExpr"))^-1 / binaryOp;
|
||||||
|
|
||||||
SimpleExpr = tagC("Number", V"Number")
|
SimpleExpr = tagC("Number", V"Number")
|
||||||
+ tagC("String", V"String")
|
|
||||||
+ tagC("Nil", kw("nil"))
|
+ tagC("Nil", kw("nil"))
|
||||||
+ tagC("Boolean", kw("false") * Cc(false))
|
+ tagC("Boolean", kw("false") * Cc(false))
|
||||||
+ tagC("Boolean", kw("true") * Cc(true))
|
+ tagC("Boolean", kw("true") * Cc(true))
|
||||||
+ tagC("Dots", sym("..."))
|
+ tagC("Dots", sym("..."))
|
||||||
+ V"FuncDef"
|
+ V"FuncDef"
|
||||||
+ V"Table"
|
|
||||||
+ V"ShortFuncDef"
|
+ V"ShortFuncDef"
|
||||||
+ V"SuffixedExpr"
|
+ V"SuffixedExpr"
|
||||||
+ V"TableCompr"
|
|
||||||
+ V"StatExpr";
|
+ V"StatExpr";
|
||||||
|
|
||||||
StatExpr = (V"IfStat" + V"DoStat" + V"WhileStat" + V"RepeatStat" + V"ForStat") / statToExpr;
|
StatExpr = (V"IfStat" + V"DoStat" + V"WhileStat" + V"RepeatStat" + V"ForStat") / statToExpr;
|
||||||
|
|
@ -542,7 +539,10 @@ local G = { V"Lua",
|
||||||
SuffixedExpr = Cf(V"PrimaryExpr" * (V"Index" + V"Call")^0, makeIndexOrCall);
|
SuffixedExpr = Cf(V"PrimaryExpr" * (V"Index" + V"Call")^0, makeIndexOrCall);
|
||||||
PrimaryExpr = V"SelfId" * (V"SelfCall" + V"SelfIndex")
|
PrimaryExpr = V"SelfId" * (V"SelfCall" + V"SelfIndex")
|
||||||
+ V"Id"
|
+ V"Id"
|
||||||
+ tagC("Paren", sym("(") * expect(V"Expr", "ExprParen") * expect(sym(")"), "CParenExpr"));
|
+ tagC("Paren", sym("(") * expect(V"Expr", "ExprParen") * expect(sym(")"), "CParenExpr"))
|
||||||
|
+ tagC("String", V"String")
|
||||||
|
+ V"Table"
|
||||||
|
+ V"TableCompr";
|
||||||
Index = tagC("DotIndex", sym("." * -P".") * expect(V"StrId", "NameIndex"))
|
Index = tagC("DotIndex", sym("." * -P".") * expect(V"StrId", "NameIndex"))
|
||||||
+ tagC("ArrayIndex", sym("[" * -P(S"=[")) * expect(V"Expr", "ExprIndex") * expect(sym("]"), "CBracketIndex"));
|
+ tagC("ArrayIndex", sym("[" * -P(S"=[")) * expect(V"Expr", "ExprIndex") * expect(sym("]"), "CBracketIndex"));
|
||||||
Call = tagC("Invoke", Cg(sym(":" * -P":") * expect(V"StrId", "NameMeth") * expect(V"FuncArgs", "MethArgs")))
|
Call = tagC("Invoke", Cg(sym(":" * -P":") * expect(V"StrId", "NameMeth") * expect(V"FuncArgs", "MethArgs")))
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,85 @@ while a < 5
|
||||||
return a
|
return a
|
||||||
]], 5)
|
]], 5)
|
||||||
|
|
||||||
|
-- suffixable string litals, table, table comprehension
|
||||||
|
test("suffixable string litteral method", [[
|
||||||
|
return "foo":len()
|
||||||
|
]], 3)
|
||||||
|
test("suffixable string litteral method lua conflict", [[
|
||||||
|
local s = function() return "four" end
|
||||||
|
return s"foo":len()
|
||||||
|
]], 4)
|
||||||
|
test("suffixable string litteral dot index", [[
|
||||||
|
local a = "foo".len
|
||||||
|
return a("foo")
|
||||||
|
]], 3)
|
||||||
|
test("suffixable string litteral dot index lua conflict", [[
|
||||||
|
local s = function() return {len=4} end
|
||||||
|
local a = s"foo".len
|
||||||
|
return a
|
||||||
|
]], 4)
|
||||||
|
test("suffixable string litteral array index", [[
|
||||||
|
local a = "foo"["len"]
|
||||||
|
return a("foo")
|
||||||
|
]], 3)
|
||||||
|
test("suffixable string litteral dot index lua conflict", [[
|
||||||
|
local s = function() return {len=4} end
|
||||||
|
local a = s"foo"["len"]
|
||||||
|
return a
|
||||||
|
]], 4)
|
||||||
|
test("suffixable string litteral call", [[
|
||||||
|
local r, e = pcall(function() "foo"() end)
|
||||||
|
return not r and e:match("attempt to call a string value")
|
||||||
|
]], "attempt to call a string value")
|
||||||
|
test("suffixable string litteral call lua conflict", [[
|
||||||
|
local s = function() return function() return 4 end end
|
||||||
|
return s"foo"()
|
||||||
|
]], 4)
|
||||||
|
|
||||||
|
test("suffixable table litteral method", [[
|
||||||
|
return {a=3,len=function(t) return t.a end}:len()
|
||||||
|
]], 3)
|
||||||
|
test("suffixable table litteral method lua conflict", [[
|
||||||
|
local s = function() return "four" end
|
||||||
|
return s{a=3,len=function(t) return t.a end}:len()
|
||||||
|
]], 4)
|
||||||
|
test("suffixable table litteral dot index", [[
|
||||||
|
return {len=3}.len
|
||||||
|
]], 3)
|
||||||
|
test("suffixable table litteral dot index lua conflict", [[
|
||||||
|
local s = function() return {len=4} end
|
||||||
|
return s{len=3}.len
|
||||||
|
]], 4)
|
||||||
|
test("suffixable table litteral array index", [[
|
||||||
|
return {len=3}["len"]
|
||||||
|
]], 3)
|
||||||
|
test("suffixable table litteral dot index lua conflict", [[
|
||||||
|
local s = function() return {len=4} end
|
||||||
|
return s{len=3}["len"]
|
||||||
|
]], 4)
|
||||||
|
test("suffixable table litteral call", [[
|
||||||
|
local r, e = pcall(function() {}() end)
|
||||||
|
return not r and e:match("attempt to call a table value")
|
||||||
|
]], "attempt to call a table value")
|
||||||
|
test("suffixable table litteral call lua conflict", [[
|
||||||
|
local s = function() return function() return 4 end end
|
||||||
|
return s{}()
|
||||||
|
]], 4)
|
||||||
|
|
||||||
|
test("suffixable table comprehension method", [[
|
||||||
|
return [@len = function() return 3 end]:len()
|
||||||
|
]], 3)
|
||||||
|
test("suffixable table comprehension dot index", [[
|
||||||
|
return [@len = 3].len
|
||||||
|
]], 3)
|
||||||
|
test("suffixable table comprehension array index", [[
|
||||||
|
return [@len=3]["len"]
|
||||||
|
]], 3)
|
||||||
|
test("suffixable table comprehension call", [[
|
||||||
|
local r, e = pcall(function() []() end)
|
||||||
|
return not r and e:match("attempt to call a table value")
|
||||||
|
]], "attempt to call a table value")
|
||||||
|
|
||||||
-- results
|
-- results
|
||||||
local resultCounter = {}
|
local resultCounter = {}
|
||||||
local testCounter = 0
|
local testCounter = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue