mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
Fixed package searcher overriding the Lua one
This commit is contained in:
parent
91f72e6d17
commit
2d297db687
5 changed files with 108 additions and 100 deletions
|
|
@ -395,7 +395,7 @@ at the top of your main Lua file. If a Candran is found when you call ```require
|
||||||
file will be loaded.
|
file will be loaded.
|
||||||
|
|
||||||
* ```candran.searcher(modpath)``` : Candran package searcher function. Use the existing package.path.
|
* ```candran.searcher(modpath)``` : Candran package searcher function. Use the existing package.path.
|
||||||
* ```candran.setup()``` : Register the Candran package searcher.
|
* ```candran.setup()``` : Register the Candran package searcher, and return the `candran` table.
|
||||||
|
|
||||||
##### Available compiler & preprocessor options
|
##### Available compiler & preprocessor options
|
||||||
You can give arbitrary options which will be gived to the preprocessor, but Candran already provide and uses these with their associated default values:
|
You can give arbitrary options which will be gived to the preprocessor, but Candran already provide and uses these with their associated default values:
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ end
|
||||||
|
|
||||||
--- Candran package searcher function. Use the existing package.path.
|
--- Candran package searcher function. Use the existing package.path.
|
||||||
function candran.searcher(modpath)
|
function candran.searcher(modpath)
|
||||||
local filepath = util.search(modpath)
|
local filepath = util.search(modpath, {"can"})
|
||||||
if not filepath then
|
if not filepath then
|
||||||
return "\n\tno candran file in package.path"
|
return "\n\tno candran file in package.path"
|
||||||
end
|
end
|
||||||
|
|
@ -244,6 +244,7 @@ function candran.setup()
|
||||||
else
|
else
|
||||||
table.insert(package.searchers, 2, candran.searcher)
|
table.insert(package.searchers, 2, candran.searcher)
|
||||||
end
|
end
|
||||||
|
return candran
|
||||||
end
|
end
|
||||||
|
|
||||||
return candran
|
return candran
|
||||||
|
|
|
||||||
13
candran.lua
13
candran.lua
|
|
@ -2855,10 +2855,10 @@ end + P("--") * (P(1) - P("\
|
||||||
["ShortStr"] = P("\"") * Cs((V("EscSeq") + (P(1) - S("\"\
|
["ShortStr"] = P("\"") * Cs((V("EscSeq") + (P(1) - S("\"\
|
||||||
"))) ^ 0) * expect(P("\""), "Quote") + P("'") * Cs((V("EscSeq") + (P(1) - S("'\
|
"))) ^ 0) * expect(P("\""), "Quote") + P("'") * Cs((V("EscSeq") + (P(1) - S("'\
|
||||||
"))) ^ 0) * expect(P("'"), "Quote"),
|
"))) ^ 0) * expect(P("'"), "Quote"),
|
||||||
["EscSeq"] = P("\\") / "" * (P("a") / "\7" + P("b") / "\8" + P("f") / "\12" + P("n") / "\
|
["EscSeq"] = P("\\") / "" * (P("a") / "" + P("b") / "" + P("f") / "" + P("n") / "\
|
||||||
" + P("r") / "\13" + P("t") / "\9" + P("v") / "\11" + P("\
|
" + P("r") / "\r" + P("t") / " " + P("v") / "" + P("\
|
||||||
") / "\
|
") / "\
|
||||||
" + P("\13") / "\
|
" + P("\r") / "\
|
||||||
" + P("\\") / "\\" + P("\"") / "\"" + P("'") / "'" + P("z") * space ^ 0 / "" + digit * digit ^ - 2 / tonumber / string["char"] + P("x") * expect(C(xdigit * xdigit), "HexEsc") * Cc(16) / tonumber / string["char"] + P("u") * expect("{", "OBraceUEsc") * expect(C(xdigit ^ 1), "DigitUEsc") * Cc(16) * expect("}", "CBraceUEsc") / tonumber / (utf8 and utf8["char"] or string["char"]) + throw("EscSeq")),
|
" + P("\\") / "\\" + P("\"") / "\"" + P("'") / "'" + P("z") * space ^ 0 / "" + digit * digit ^ - 2 / tonumber / string["char"] + P("x") * expect(C(xdigit * xdigit), "HexEsc") * Cc(16) / tonumber / string["char"] + P("u") * expect("{", "OBraceUEsc") * expect(C(xdigit ^ 1), "DigitUEsc") * Cc(16) * expect("}", "CBraceUEsc") / tonumber / (utf8 and utf8["char"] or string["char"]) + throw("EscSeq")),
|
||||||
["LongStr"] = V("Open") * C((P(1) - V("CloseEq")) ^ 0) * expect(V("Close"), "CloseLStr") / function(s, eqs)
|
["LongStr"] = V("Open") * C((P(1) - V("CloseEq")) ^ 0) * expect(V("Close"), "CloseLStr") / function(s, eqs)
|
||||||
return s
|
return s
|
||||||
|
|
@ -2975,7 +2975,7 @@ env["write"](f:read("*a"))
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
env["write"] = function(...)
|
env["write"] = function(...)
|
||||||
env["output"] = env["output"] .. (table["concat"]({ ... }, "\9") .. "\
|
env["output"] = env["output"] .. (table["concat"]({ ... }, " ") .. "\
|
||||||
")
|
")
|
||||||
end
|
end
|
||||||
env["placeholder"] = function(name)
|
env["placeholder"] = function(name)
|
||||||
|
|
@ -3082,10 +3082,10 @@ end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
candran["searcher"] = function(modpath)
|
candran["searcher"] = function(modpath)
|
||||||
local filepath = util["search"](modpath)
|
local filepath = util["search"](modpath, { "can" })
|
||||||
if not filepath then
|
if not filepath then
|
||||||
return "\
|
return "\
|
||||||
\9no candran file in package.path"
|
no candran file in package.path"
|
||||||
end
|
end
|
||||||
return candran["loadfile"](filepath)
|
return candran["loadfile"](filepath)
|
||||||
end
|
end
|
||||||
|
|
@ -3095,5 +3095,6 @@ table["insert"](package["loaders"], 2, candran["searcher"])
|
||||||
else
|
else
|
||||||
table["insert"](package["searchers"], 2, candran["searcher"])
|
table["insert"](package["searchers"], 2, candran["searcher"])
|
||||||
end
|
end
|
||||||
|
return candran
|
||||||
end
|
end
|
||||||
return candran
|
return candran
|
||||||
|
|
|
||||||
186
ideas.txt
186
ideas.txt
|
|
@ -1,90 +1,96 @@
|
||||||
List of potential ideas.
|
List of potential ideas.
|
||||||
|
|
||||||
To be implemented, theese need to:
|
To be implemented, theese need to:
|
||||||
* aesthetically fit into the current Candran/Lua syntax. We can add a few weird glyphs here and there, but our goal *is not* to become a punctuation inventory like MoonScript.
|
* aesthetically fit into the current Candran/Lua syntax. We can add a few weird glyphs here and there, but our goal *is not* to become a punctuation inventory like MoonScript.
|
||||||
* vanilla Lua code *must* produce functionaly identical code after going through the Candran compiler, so make sure the additions:
|
* vanilla Lua code *must* produce functionaly identical code after going through the Candran compiler, so make sure the additions:
|
||||||
* are invalid vanilla Lua syntax.
|
* are invalid vanilla Lua syntax.
|
||||||
* are not ambigous with any vanilla Lua syntax.
|
* are not ambigous with any vanilla Lua syntax.
|
||||||
* be significantly useful compared to existing Candran/Lua code.
|
* be significantly useful compared to existing Candran/Lua code.
|
||||||
* be useful without having to rewrite APIs specifically for Candran. Candran intends to make Lua easier, not supersede it.
|
* be useful without having to rewrite APIs specifically for Candran. Candran intends to make Lua easier, not supersede it.
|
||||||
|
|
||||||
Example currently rejected ideas:
|
Example currently rejected ideas:
|
||||||
* Python-style function decorators (implemented in Candran 0.1.0):
|
* Python-style function decorators (implemented in Candran 0.1.0):
|
||||||
Useless 95% of the time because most Lua APIs applying something to a function are used like applySomething(someArg,func) instead of func=applySomething(someArg)(func).
|
Useless 95% of the time because most Lua APIs applying something to a function are used like applySomething(someArg,func) instead of func=applySomething(someArg)(func).
|
||||||
This could be adapted, but this will mean unecessary named functions in the environment and it will only works when the decorator returns the functions.
|
This could be adapted, but this will mean unecessary named functions in the environment and it will only works when the decorator returns the functions.
|
||||||
In this state, these didn't provide anothing useful over short anonymous functions.
|
In this state, these didn't provide anothing useful over short anonymous functions.
|
||||||
* Whitespace significance.
|
* Whitespace significance.
|
||||||
Doesn't fit with Lua's verbose keywords.
|
Doesn't fit with Lua's verbose keywords.
|
||||||
|
|
||||||
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.
|
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, CoffeeScript, and Lilia (https://love2d.org/forums/viewtopic.php?f=3&t=82650&sid=b6d9a8dec64afcc1c67806cb5ba65458).
|
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.
|
Please note that the following ideas are just random though and won't be necessarly implemented, and some won't even work together.
|
||||||
|
|
||||||
Feel free to open issues about ideas you find useful or want to improve. Otherwise, I will only implements them when I really need them or am bored.
|
Feel free to open issues about ideas you find useful or want to improve. Otherwise, I will only implements them when I really need them or am bored.
|
||||||
|
|
||||||
Actually, open issues for everything. I know of a couple persons using Candran but have no idea what they like and want with it.
|
Actually, open issues for everything. I know of a couple persons using Candran but have no idea what they like and want with it.
|
||||||
|
|
||||||
* class keyword
|
* class keyword
|
||||||
class Thing(parents...)
|
class Thing(parents...)
|
||||||
foo = "bar"
|
foo = "bar"
|
||||||
|
|
||||||
new = :()
|
new = :()
|
||||||
stuff()
|
stuff()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local a = new Thing()
|
local a = new Thing()
|
||||||
->
|
->
|
||||||
(TODO: define how classes work. May even use ClassCommons)
|
(TODO: define how classes work. May even use ClassCommons)
|
||||||
|
|
||||||
* try / except|catch / finally / else / other keywords
|
* try / except|catch / finally / else / other keywords
|
||||||
try
|
try
|
||||||
error("hey")
|
error("hey")
|
||||||
catch err
|
catch err
|
||||||
print(err)
|
print(err)
|
||||||
finally
|
finally
|
||||||
clean()
|
clean()
|
||||||
end
|
end
|
||||||
|
|
||||||
* Safe navigation operator
|
* Safe navigation operator
|
||||||
local name = articles?[0].author?.name (?[] and ?. index opeators)
|
local name = articles?[0].author?.name (?[] and ?. index opeators)
|
||||||
or
|
or
|
||||||
local zip = lottery.drawWinner?().address?.zipcode (expr? existence test suffix)
|
local zip = lottery.drawWinner?().address?.zipcode (expr? existence test suffix)
|
||||||
|
|
||||||
See http://coffeescript.org/#existential-operator
|
See http://coffeescript.org/#existential-operator
|
||||||
|
|
||||||
* static type checking
|
* static type checking
|
||||||
local a = externalFunc() -- unknown
|
local a = externalFunc() -- unknown
|
||||||
if a == "hey" then
|
if a == "hey" then
|
||||||
-- a = string
|
-- a = string
|
||||||
a:sub(5,3) -- ok
|
a:sub(5,3) -- ok
|
||||||
a:exit() -- error!
|
a:exit() -- error!
|
||||||
else
|
else
|
||||||
-- a = unknown
|
-- a = unknown
|
||||||
a:exit() -- ok
|
a:exit() -- ok
|
||||||
end
|
end
|
||||||
|
|
||||||
Will need to define stuff for a lot of Lua libraries (see the work already done by TypedLua).
|
Will need to define stuff for a lot of Lua libraries (see the work already done by TypedLua).
|
||||||
|
|
||||||
While we're talking about static analysis, what about forking luacheck into candrancheck? Or at least make the line mapping work.
|
While we're talking about static analysis, what about forking luacheck into candrancheck? Or at least make the line mapping work.
|
||||||
|
|
||||||
* array slicing
|
* array slicing
|
||||||
local b = a[3:5:1]
|
local b = a[3:5:1]
|
||||||
|
|
||||||
* Destructuring assignment
|
* Destructuring assignment
|
||||||
local pos = { x = 5, y = 12 }
|
local pos = { x = 5, y = 12 }
|
||||||
|
|
||||||
local {x, y} = pos -- x, y = pos.x, pos.y
|
local {x, y} = pos -- x, y = pos.x, pos.y
|
||||||
local {x = x, y = y} = pos
|
local {a, b, x = x, y = y} = pos -- x, y = pos.x, pos.y, a = pos[1], b = pos[2]
|
||||||
local {:x, :y} = pos -- shorthand for the above line
|
local {a, b, :x, :y} = pos -- shorthand for the above line. Or .x, .y
|
||||||
local [x, y] = pos -- x, y = pos[0], pos[1]
|
local {:x.u} = pos OR {:x:u} OR {.x.u} -- u = pos.x.u
|
||||||
local x, y $= pos
|
local [x, y] = pos -- x, y = pos[0], pos[1]
|
||||||
|
local x, y $= pos
|
||||||
And in implicit assignments:
|
|
||||||
for i, {x, y} in ipairs(positions) do
|
And in implicit assignments:
|
||||||
|
for i, {x, y} in ipairs(positions) do
|
||||||
* Other potential inspiration
|
|
||||||
https://www.ruby-lang.org/fr/
|
* String interpolation
|
||||||
|
Delimited by ``:
|
||||||
Well done, you're at the end of the file!
|
`Hi, my name is ${@name}` -- -> "blaba" .. tostring(@name)
|
||||||
|
Also allows multi-line with this maybe?
|
||||||
|
|
||||||
|
* Other potential inspiration
|
||||||
|
https://www.ruby-lang.org/fr/
|
||||||
|
|
||||||
|
Well done, you're at the end of the file!
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package = "candran"
|
package = "candran"
|
||||||
|
|
||||||
version = "0.6.0-1"
|
version = "0.6.1-1"
|
||||||
|
|
||||||
description = {
|
description = {
|
||||||
summary = "A simple Lua dialect and preprocessor.",
|
summary = "A simple Lua dialect and preprocessor.",
|
||||||
|
|
@ -17,7 +17,7 @@ description = {
|
||||||
|
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/Reuh/candran",
|
url = "git://github.com/Reuh/candran",
|
||||||
tag = "v0.6.0"
|
tag = "v0.6.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies = {
|
dependencies = {
|
||||||
Loading…
Add table
Add a link
Reference in a new issue