Updated fennel master to current master branch.

This commit is contained in:
Alexander Griffith 2020-03-07 20:41:37 -05:00
parent b992fc3ab9
commit a89f224708
4 changed files with 1167 additions and 1023 deletions

1040
fennel.lua

File diff suppressed because it is too large Load diff

View file

@ -10,8 +10,9 @@ Usage: fennel [FLAG] [FILE]
Run fennel, a lisp programming language for the Lua runtime. Run fennel, a lisp programming language for the Lua runtime.
--repl : Launch an interactive repl session --repl : Command to launch an interactive repl session
--compile FILES : Compile files and write their Lua to stdout --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 --no-searcher : Skip installing package.searchers entry
--indent VAL : Indent compiler output with VAL --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 --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 G1[,G2...] : Allow these globals in addition to standard ones
--globals-only G1[,G2] : Same as above, but exclude 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 --require-as-include : Inline required modules in the output
--metadata : Enable function metadata, even in compiled output --metadata : Enable function metadata, even in compiled output
--no-metadata : Disable function metadata, even in REPL --no-metadata : Disable function metadata, even in REPL
--correlate : Make Lua output line numbers match Fennel input --correlate : Make Lua output line numbers match Fennel input
--load FILE (-l) : Load the specified FILE before executing the command
--eval SOURCE (-e) : Evaluate source code and print the result --no-fennelrc : Skip loading ~/.fennelrc when launching repl
--help (-h) : Display this text --help (-h) : Display this text
--version (-v) : Show version --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 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. 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 not given a command, runs the file given as the first argument.
When given neither flag nor file, launches a repl. When given neither command nor file, launches a repl.
If ~/.fennelrc exists, loads it before launching 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) local entry = table.remove(arg, i+1)
fennel.path = entry .. ";" .. fennel.path fennel.path = entry .. ";" .. fennel.path
table.remove(arg, i) 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 elseif arg[i] == "--correlate" then
options.correlate = true options.correlate = true
table.remove(arg, i) table.remove(arg, i)
elseif arg[i] == "--check-unused-locals" then
options.checkUnusedLocals = true
table.remove(arg, i)
elseif arg[i] == "--globals" then elseif arg[i] == "--globals" then
allowGlobals(table.remove(arg, i+1)) allowGlobals(table.remove(arg, i+1))
for globalName in pairs(_G) do for globalName in pairs(_G) do
@ -146,16 +158,26 @@ if arg[1] == "--repl" or #arg == 0 then
options.pp = pp options.pp = pp
end end
end end
local initFilename = (os.getenv("HOME") or "") .. "/.fennelrc"
local init = io.open(initFilename, "rb")
tryReadline(options) tryReadline(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 if init then
init:close() init:close()
-- pass in options so fennerlrc can make changes to it -- pass in options so fennerlrc can make changes to it
dosafe(initFilename, options, options) dosafe(initFilename, options, {options})
end end
end
print("Welcome to Fennel " .. fennel.version .. "!") print("Welcome to Fennel " .. fennel.version .. "!")
if options.useMetadata ~= false then if options.useMetadata ~= false then
print("Use (doc something) to view documentation.") print("Use (doc something) to view documentation.")

File diff suppressed because it is too large Load diff

View file

@ -15,9 +15,9 @@ do
long_control_char_escapes = long long_control_char_escapes = long
end end
local function escape(str) local function escape(str)
local str = str:gsub("\\", "\\\\") local str0 = str:gsub("\\", "\\\\")
local str = str:gsub("(%c)%f[0-9]", long_control_char_escapes) local str1 = str0:gsub("(%c)%f[0-9]", long_control_char_escapes)
return str:gsub("%c", short_control_char_escapes) return str1:gsub("%c", short_control_char_escapes)
end end
local function sequence_key_3f(k, len) local function sequence_key_3f(k, len)
return ((type(k) == "number") and (1 <= k) and (k <= len) and (math.floor(k) == k)) return ((type(k) == "number") and (1 <= k) and (k <= len) and (math.floor(k) == k))
@ -103,7 +103,10 @@ local function put_sequential_table(self, t, len)
puts(self, "[") puts(self, "[")
self.level = (self.level + 1) self.level = (self.level + 1)
for i = 1, len do for i = 1, len do
local _0_ = (1 + len)
if ((1 < i) and (i < _0_)) then
puts(self, " ") puts(self, " ")
end
put_value(self, t[i]) put_value(self, t[i])
end end
self.level = (self.level - 1) self.level = (self.level - 1)
@ -136,10 +139,26 @@ local function put_kv_table(self, t, ordered_keys)
return puts(self, "}") return puts(self, "}")
end end
local function put_table(self, t) 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 if (already_visited_3f(self, t) and self["detect-cycles?"]) then
return puts(self, "#<table ", get_id(self, t), ">") return puts(self, "#<table ", get_id(self, t), ">")
elseif (self.level >= self.depth) then elseif (self.level >= self.depth) then
return puts(self, "{...}") return puts(self, "{...}")
elseif metamethod then
return puts(self, metamethod(t, self.fennelview))
elseif "else" then elseif "else" then
local non_seq_keys, len = get_nonsequential_keys(t) local non_seq_keys, len = get_nonsequential_keys(t)
local id = get_id(self, t) local id = get_id(self, t)
@ -172,20 +191,23 @@ local function one_line(str)
return ret return ret
end end
local function fennelview(x, options) local function fennelview(x, options)
local options = (options or {}) local options0 = (options or {})
local inspector = inspector local inspector = nil
local function _1_() local function _1_(_241)
if options["one-line"] then return fennelview(_241, options0)
end
local function _2_()
if options0["one-line"] then
return "" return ""
else else
return " " return " "
end end
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) put_value(inspector, x)
do do
local str = table.concat(inspector.buffer) local str = table.concat(inspector.buffer)
if options["one-line"] then if options0["one-line"] then
return one_line(str) return one_line(str)
else else
return str return str