From 67f681a88a60ce0124d3369644cbceadff3cc183 Mon Sep 17 00:00:00 2001 From: Reuh Date: Thu, 30 Aug 2018 18:31:06 +0200 Subject: [PATCH] On second though, string and table calls are a bad idea --- README.md | 3 +-- candran.lua | 8 +++++--- lib/lua-parser/parser.lua | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f98e724..58c3672 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,6 @@ _Not in the latest release, install the `candran-scm-1.rockspec` version if you ```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! @@ -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) ``` -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. diff --git a/candran.lua b/candran.lua index fb8a8a9..31fbb23 100644 --- a/candran.lua +++ b/candran.lua @@ -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 return exp["tag"] == "Id" or exp["tag"] == "Index", exp -- ./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 -["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 +["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")), -- ./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 -["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 ["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 diff --git a/lib/lua-parser/parser.lua b/lib/lua-parser/parser.lua index 1cdbecf..c9d390d 100644 --- a/lib/lua-parser/parser.lua +++ b/lib/lua-parser/parser.lua @@ -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); 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); - 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"; - Index = tagC("DotIndex", sym("." * -P".") * expect(V"StrId", "NameIndex")) - + 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"))) - + tagC("Call", V"FuncArgs"); - SelfIndex = tagC("DotIndex", V"StrId"); - SelfCall = tagC("Invoke", Cg(V"StrId" * V"FuncArgs")); + 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); + PrimaryExpr = V"SelfId" * (V"SelfCall" + V"SelfIndex") + + V"Id" + + tagC("Paren", sym("(") * expect(V"Expr", "ExprParen") * expect(sym(")"), "CParenExpr")); + NoCallPrimaryExpr = tagC("String", V"String") + V"Table" + V"TableCompr"; + Index = tagC("DotIndex", sym("." * -P".") * expect(V"StrId", "NameIndex")) + + tagC("ArrayIndex", sym("[" * -P(S"=[")) * expect(V"Expr", "ExprIndex") * expect(sym("]"), "CBracketIndex")); + Call = tagC("Call", V"FuncArgs"); + Invoke = tagC("Invoke", Cg(sym(":" * -P":") * expect(V"StrId", "NameMeth") * expect(V"FuncArgs", "MethArgs"))); + SelfIndex = tagC("DotIndex", V"StrId"); + SelfCall = tagC("Invoke", Cg(V"StrId" * V"FuncArgs")); FuncDef = (kw("function") * V"FuncBody"); FuncArgs = sym("(") * commaSep(V"Expr", "ArgList")^-1 * expect(sym(")"), "CParenArgs")