mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
On second though, string and table calls are a bad idea
This commit is contained in:
parent
98a6a87962
commit
67f681a88a
3 changed files with 19 additions and 18 deletions
|
|
@ -257,7 +257,6 @@ _Not in the latest release, install the `candran-scm-1.rockspec` version if you
|
||||||
```lua
|
```lua
|
||||||
"some text":upper() -- same as ("some text"):upper() in Lua
|
"some text":upper() -- same as ("some text"):upper() in Lua
|
||||||
"string".upper -- the actual string.upper function. "string"["upper"] also works.
|
"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!
|
{thing = 3}.thing -- 3. Also works with tables!
|
||||||
[for i=0,5 do i*i end][3] -- 9. And table comprehensions!
|
[for i=0,5 do i*i end][3] -- 9. And table comprehensions!
|
||||||
|
|
@ -266,7 +265,7 @@ _Not in the latest release, install the `candran-scm-1.rockspec` version if you
|
||||||
someFunction"thing":upper() -- same as (someFunction("thing")):upper() (i.e., the way it would be parsed by Lua)
|
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.
|
String litterals, table litterals, and comprehensions can be suffixed with `:` method calls, `.` indexing, or `[` indexing, without needing to be enclosed in parantheses.
|
||||||
|
|
||||||
*Please note*, that "normal" functions calls have priority over this syntax, in order to maintain Lua compatibility.
|
*Please note*, that "normal" functions calls have priority over this syntax, in order to maintain Lua compatibility.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2838,10 +2838,12 @@ end), -- ./lib/lua-parser/parser.lua:536
|
||||||
["VarExpr"] = Cmt(V("SuffixedExpr"), function(s, i, exp) -- ./lib/lua-parser/parser.lua:537
|
["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:537
|
return exp["tag"] == "Id" or exp["tag"] == "Index", exp -- ./lib/lua-parser/parser.lua:537
|
||||||
end), -- ./lib/lua-parser/parser.lua:537
|
end), -- ./lib/lua-parser/parser.lua:537
|
||||||
["SuffixedExpr"] = Cf(V("PrimaryExpr") * (V("Index") + V("Call")) ^ 0, makeIndexOrCall), -- ./lib/lua-parser/parser.lua:539
|
["SuffixedExpr"] = Cf(V("PrimaryExpr") * (V("Index") + V("Invoke") + V("Call")) ^ 0 + V("NoCallPrimaryExpr") * - V("Call") * (V("Index") + V("Invoke") + V("Call")) ^ 0 + V("NoCallPrimaryExpr"), makeIndexOrCall), -- ./lib/lua-parser/parser.lua:541
|
||||||
["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
|
["PrimaryExpr"] = V("SelfId") * (V("SelfCall") + V("SelfIndex")) + V("Id") + tagC("Paren", sym("(") * expect(V("Expr"), "ExprParen") * expect(sym(")"), "CParenExpr")), -- ./lib/lua-parser/parser.lua:544
|
||||||
|
["NoCallPrimaryExpr"] = 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("Call", V("FuncArgs")), -- ./lib/lua-parser/parser.lua:548
|
||||||
|
["Invoke"] = tagC("Invoke", Cg(sym(":" * - P(":")) * expect(V("StrId"), "NameMeth") * expect(V("FuncArgs"), "MethArgs"))), -- ./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
|
||||||
["SelfCall"] = tagC("Invoke", Cg(V("StrId") * V("FuncArgs"))), -- ./lib/lua-parser/parser.lua:551
|
["SelfCall"] = tagC("Invoke", Cg(V("StrId") * V("FuncArgs"))), -- ./lib/lua-parser/parser.lua:551
|
||||||
["FuncDef"] = (kw("function") * V("FuncBody")), -- ./lib/lua-parser/parser.lua:553
|
["FuncDef"] = (kw("function") * V("FuncBody")), -- ./lib/lua-parser/parser.lua:553
|
||||||
|
|
|
||||||
|
|
@ -536,19 +536,19 @@ local G = { V"Lua",
|
||||||
FuncCall = Cmt(V"SuffixedExpr", function(s, i, exp) return exp.tag == "Call" or exp.tag == "Invoke", exp end);
|
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);
|
VarExpr = Cmt(V"SuffixedExpr", function(s, i, exp) return exp.tag == "Id" or exp.tag == "Index", exp end);
|
||||||
|
|
||||||
SuffixedExpr = Cf(V"PrimaryExpr" * (V"Index" + V"Call")^0, makeIndexOrCall);
|
SuffixedExpr = Cf(V"PrimaryExpr" * (V"Index" + V"Invoke" + V"Call")^0
|
||||||
PrimaryExpr = V"SelfId" * (V"SelfCall" + V"SelfIndex")
|
+ V"NoCallPrimaryExpr" * -V"Call" * (V"Index" + V"Invoke" + V"Call")^0
|
||||||
+ V"Id"
|
+ V"NoCallPrimaryExpr", makeIndexOrCall);
|
||||||
+ tagC("Paren", sym("(") * expect(V"Expr", "ExprParen") * expect(sym(")"), "CParenExpr"))
|
PrimaryExpr = V"SelfId" * (V"SelfCall" + V"SelfIndex")
|
||||||
+ tagC("String", V"String")
|
+ V"Id"
|
||||||
+ V"Table"
|
+ tagC("Paren", sym("(") * expect(V"Expr", "ExprParen") * expect(sym(")"), "CParenExpr"));
|
||||||
+ V"TableCompr";
|
NoCallPrimaryExpr = 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("Call", V"FuncArgs");
|
||||||
+ tagC("Call", V"FuncArgs");
|
Invoke = tagC("Invoke", Cg(sym(":" * -P":") * expect(V"StrId", "NameMeth") * expect(V"FuncArgs", "MethArgs")));
|
||||||
SelfIndex = tagC("DotIndex", V"StrId");
|
SelfIndex = tagC("DotIndex", V"StrId");
|
||||||
SelfCall = tagC("Invoke", Cg(V"StrId" * V"FuncArgs"));
|
SelfCall = tagC("Invoke", Cg(V"StrId" * V"FuncArgs"));
|
||||||
|
|
||||||
FuncDef = (kw("function") * V"FuncBody");
|
FuncDef = (kw("function") * V"FuncBody");
|
||||||
FuncArgs = sym("(") * commaSep(V"Expr", "ArgList")^-1 * expect(sym(")"), "CParenArgs")
|
FuncArgs = sym("(") * commaSep(V"Expr", "ArgList")^-1 * expect(sym(")"), "CParenArgs")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue