~technomancy/antifennel

ref: c436ed1418acd1cecf63db41326617101688afa1 antifennel/antifennel.lua -rw-r--r-- 803 bytes
c436ed14Phil Hagelberg Avoid conflicts with reserved fennel names in identifiers. 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local fennel = require('fennel')
local view = require('fennelview')

if os.getenv("FNL") then -- prefer Fennel to Lua when both exist
   table.insert(package.loaders or package.searchers, 1, fennel.searcher)
else
   table.insert(package.loaders or package.searchers, fennel.searcher)
end

local lex_setup = require('lang.lexer')
local parse = require('lang.parser')
local lua_ast = require('lang.lua_ast')
local reader = require('lang.reader')

local compiler = require('anticompiler')

local function compile(rdr, filename)
   local ls = lex_setup(rdr, filename)
   local ast_builder = lua_ast.New()
   local ast_tree = parse(ast_builder, ls)
   return compiler(ast_tree, filename)
end

local filename = arg[1]
for _,code in ipairs(compile(reader.file(filename), filename)) do
   print(view(code))
end