Updated fennel master to current master branch.
This commit is contained in:
parent
b992fc3ab9
commit
a89f224708
1050
fennel.lua
1050
fennel.lua
File diff suppressed because it is too large
Load diff
46
lib/fennel
46
lib/fennel
|
@ -10,8 +10,9 @@ Usage: fennel [FLAG] [FILE]
|
|||
|
||||
Run fennel, a lisp programming language for the Lua runtime.
|
||||
|
||||
--repl : Launch an interactive repl session
|
||||
--compile FILES : Compile files and write their Lua to stdout
|
||||
--repl : Command to launch an interactive repl session
|
||||
--compile FILES : Command to compile files and write Lua to stdout
|
||||
--eval SOURCE (-e) : Command to evaluate source code and print the result
|
||||
|
||||
--no-searcher : Skip installing package.searchers entry
|
||||
--indent VAL : Indent compiler output with VAL
|
||||
|
@ -19,12 +20,13 @@ Run fennel, a lisp programming language for the Lua runtime.
|
|||
--add-fennel-path PATH : Add PATH to fennel.path for finding Fennel modules
|
||||
--globals G1[,G2...] : Allow these globals in addition to standard ones
|
||||
--globals-only G1[,G2] : Same as above, but exclude standard ones
|
||||
--check-unused-locals : Raise error when compiling code with unused locals
|
||||
--require-as-include : Inline required modules in the output
|
||||
--metadata : Enable function metadata, even in compiled output
|
||||
--no-metadata : Disable function metadata, even in REPL
|
||||
--correlate : Make Lua output line numbers match Fennel input
|
||||
|
||||
--eval SOURCE (-e) : Evaluate source code and print the result
|
||||
--load FILE (-l) : Load the specified FILE before executing the command
|
||||
--no-fennelrc : Skip loading ~/.fennelrc when launching repl
|
||||
|
||||
--help (-h) : Display this text
|
||||
--version (-v) : Show version
|
||||
|
@ -32,8 +34,8 @@ Run fennel, a lisp programming language for the Lua runtime.
|
|||
Metadata is typically considered a development feature and is not recommended
|
||||
for production. It is used for docstrings and enabled by default in the REPL.
|
||||
|
||||
When not given a flag, runs the file given as the first argument.
|
||||
When given neither flag nor file, launches a repl.
|
||||
When not given a command, runs the file given as the first argument.
|
||||
When given neither command nor file, launches a repl.
|
||||
|
||||
If ~/.fennelrc exists, loads it before launching a repl.]]
|
||||
|
||||
|
@ -73,9 +75,19 @@ for i=#arg, 1, -1 do
|
|||
local entry = table.remove(arg, i+1)
|
||||
fennel.path = entry .. ";" .. fennel.path
|
||||
table.remove(arg, i)
|
||||
elseif arg[i] == "--load" or arg[i] == "-l" then
|
||||
local file = table.remove(arg, i+1)
|
||||
dosafe(file, options, {})
|
||||
table.remove(arg, i)
|
||||
elseif arg[i] == "--no-fennelrc" then
|
||||
options.fennelrc = false
|
||||
table.remove(arg, i)
|
||||
elseif arg[i] == "--correlate" then
|
||||
options.correlate = true
|
||||
table.remove(arg, i)
|
||||
elseif arg[i] == "--check-unused-locals" then
|
||||
options.checkUnusedLocals = true
|
||||
table.remove(arg, i)
|
||||
elseif arg[i] == "--globals" then
|
||||
allowGlobals(table.remove(arg, i+1))
|
||||
for globalName in pairs(_G) do
|
||||
|
@ -146,16 +158,26 @@ if arg[1] == "--repl" or #arg == 0 then
|
|||
options.pp = pp
|
||||
end
|
||||
end
|
||||
local initFilename = (os.getenv("HOME") or "") .. "/.fennelrc"
|
||||
local init = io.open(initFilename, "rb")
|
||||
|
||||
tryReadline(options)
|
||||
|
||||
if init then
|
||||
init:close()
|
||||
-- pass in options so fennerlrc can make changes to it
|
||||
dosafe(initFilename, options, options)
|
||||
if options.fennelrc ~= false then
|
||||
local home = os.getenv("HOME")
|
||||
local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or home .. "/.config"
|
||||
local xdg_initfile = xdg_config_home .. "/fennel/fennelrc"
|
||||
local home_initfile = home .. "/.fennelrc"
|
||||
local init, initFilename = io.open(xdg_initfile, "rb"), xdg_initfile
|
||||
if not init then
|
||||
init, initFilename = io.open(home_initfile, "rb"), home_initfile
|
||||
end
|
||||
|
||||
if init then
|
||||
init:close()
|
||||
-- pass in options so fennerlrc can make changes to it
|
||||
dosafe(initFilename, options, {options})
|
||||
end
|
||||
end
|
||||
|
||||
print("Welcome to Fennel " .. fennel.version .. "!")
|
||||
if options.useMetadata ~= false then
|
||||
print("Use (doc something) to view documentation.")
|
||||
|
|
1050
lib/fennel.lua
1050
lib/fennel.lua
File diff suppressed because it is too large
Load diff
|
@ -15,9 +15,9 @@ do
|
|||
long_control_char_escapes = long
|
||||
end
|
||||
local function escape(str)
|
||||
local str = str:gsub("\\", "\\\\")
|
||||
local str = str:gsub("(%c)%f[0-9]", long_control_char_escapes)
|
||||
return str:gsub("%c", short_control_char_escapes)
|
||||
local str0 = str:gsub("\\", "\\\\")
|
||||
local str1 = str0:gsub("(%c)%f[0-9]", long_control_char_escapes)
|
||||
return str1:gsub("%c", short_control_char_escapes)
|
||||
end
|
||||
local function sequence_key_3f(k, len)
|
||||
return ((type(k) == "number") and (1 <= k) and (k <= len) and (math.floor(k) == k))
|
||||
|
@ -103,11 +103,14 @@ local function put_sequential_table(self, t, len)
|
|||
puts(self, "[")
|
||||
self.level = (self.level + 1)
|
||||
for i = 1, len do
|
||||
puts(self, " ")
|
||||
local _0_ = (1 + len)
|
||||
if ((1 < i) and (i < _0_)) then
|
||||
puts(self, " ")
|
||||
end
|
||||
put_value(self, t[i])
|
||||
end
|
||||
self.level = (self.level - 1)
|
||||
return puts(self, " ]")
|
||||
return puts(self, "]")
|
||||
end
|
||||
local function put_key(self, k)
|
||||
if ((type(k) == "string") and k:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then
|
||||
|
@ -136,10 +139,26 @@ local function put_kv_table(self, t, ordered_keys)
|
|||
return puts(self, "}")
|
||||
end
|
||||
local function put_table(self, t)
|
||||
local metamethod = nil
|
||||
do
|
||||
local _0_0 = t
|
||||
if _0_0 then
|
||||
local _1_0 = getmetatable(_0_0)
|
||||
if _1_0 then
|
||||
metamethod = _1_0.__fennelview
|
||||
else
|
||||
metamethod = _1_0
|
||||
end
|
||||
else
|
||||
metamethod = _0_0
|
||||
end
|
||||
end
|
||||
if (already_visited_3f(self, t) and self["detect-cycles?"]) then
|
||||
return puts(self, "#<table ", get_id(self, t), ">")
|
||||
elseif (self.level >= self.depth) then
|
||||
return puts(self, "{...}")
|
||||
elseif metamethod then
|
||||
return puts(self, metamethod(t, self.fennelview))
|
||||
elseif "else" then
|
||||
local non_seq_keys, len = get_nonsequential_keys(t)
|
||||
local id = get_id(self, t)
|
||||
|
@ -172,20 +191,23 @@ local function one_line(str)
|
|||
return ret
|
||||
end
|
||||
local function fennelview(x, options)
|
||||
local options = (options or {})
|
||||
local inspector = inspector
|
||||
local function _1_()
|
||||
if options["one-line"] then
|
||||
local options0 = (options or {})
|
||||
local inspector = nil
|
||||
local function _1_(_241)
|
||||
return fennelview(_241, options0)
|
||||
end
|
||||
local function _2_()
|
||||
if options0["one-line"] then
|
||||
return ""
|
||||
else
|
||||
return " "
|
||||
end
|
||||
end
|
||||
inspector = {["detect-cycles?"] = not (false == options["detect-cycles?"]), ["max-ids"] = {}, appearances = count_table_appearances(x, {}), buffer = {}, depth = (options.depth or 128), ids = {}, indent = (options.indent or _1_()), level = 0}
|
||||
inspector = {["detect-cycles?"] = not (false == options0["detect-cycles?"]), ["max-ids"] = {}, appearances = count_table_appearances(x, {}), buffer = {}, depth = (options0.depth or 128), fennelview = _1_, ids = {}, indent = (options0.indent or _2_()), level = 0}
|
||||
put_value(inspector, x)
|
||||
do
|
||||
local str = table.concat(inspector.buffer)
|
||||
if options["one-line"] then
|
||||
if options0["one-line"] then
|
||||
return one_line(str)
|
||||
else
|
||||
return str
|
||||
|
|
Loading…
Reference in a new issue