From d8010702e8615ba0777d36e89bb2d30e937b2f0a Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 30 May 2014 12:31:07 +0100 Subject: [PATCH] elua: initial stuff for the xgettext generator, check existence of all input files beforehand in the app, and other fixes --- src/bin/elua/apps/xgettext.lua | 32 ++++++++++++++++++--- src/bin/elua/modules/xgettext/generator.lua | 7 +++++ src/bin/elua/modules/xgettext/parser.lua | 3 ++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/bin/elua/modules/xgettext/generator.lua diff --git a/src/bin/elua/apps/xgettext.lua b/src/bin/elua/apps/xgettext.lua index 38a193f27e..eaaad2f378 100644 --- a/src/bin/elua/apps/xgettext.lua +++ b/src/bin/elua/apps/xgettext.lua @@ -6,6 +6,8 @@ local util = require("util") local cutil = require("cutil") local getopt = require("getopt") +local generator = require("xgettext.generator") + local VERSION = "1.0.0" local input_sources = {} @@ -326,9 +328,7 @@ for i, v in ipairs(input_sources) do local f = io.open(v) if f then for line in f:lines() do - if not line:lower():match("^.+%.lua$") then - input_files[#input_files + 1] = line - end + input_files[#input_files + 1] = line end end end @@ -344,12 +344,36 @@ args_nolua[#args_nolua + 1] = "--omit-header" args_nolua[#args_nolua + 1] = "--output=-" args_nolua[#args_nolua + 1] = false +local found_files = {} + +-- make sure all files exist first +for i, fname in ipairs(input_files) do + if fname ~= "-" and not excluded_files[fname] then + local ff = util.find_file(fname, search_dirs) + if not ff then + error(fname .. ": no such file or directory") + end + found_files[fname] = ff + end +end + local parsed_files = {} for i, fname in ipairs(input_files) do if not excluded_files[fname] then if onlylua or (not neverlua and fname:lower():match("^.+%.lua$")) then -- parse lua files here - local fpath = util.find_file(fname, search_dirs) + local fcontents, fpath + -- handle stdin if needed + if fname == "-" then + fpath, fcontents = "=stdin", io.stdin:read("*all") + else + fpath = found_files[fname] + local f = io.open(fpath, "r") + fcontents = f:read("*all") + f:close() + end + parsed_files[#parsed_files + 1] = generator.init(fpath, fcontents, + keywords) else args_nolua[#args_nolua] = fname local f = assert(cutil.popenv(hasxgettext, "r", diff --git a/src/bin/elua/modules/xgettext/generator.lua b/src/bin/elua/modules/xgettext/generator.lua new file mode 100644 index 0000000000..29ec7abf05 --- /dev/null +++ b/src/bin/elua/modules/xgettext/generator.lua @@ -0,0 +1,7 @@ +-- Elua xgettext: generator + +local parser = require("xgettext.parser") + +return { init = function(chunkname, input, keywords) + local ps = parser.init(chunkname, input, keywords) +end } \ No newline at end of file diff --git a/src/bin/elua/modules/xgettext/parser.lua b/src/bin/elua/modules/xgettext/parser.lua index a5420c0d8a..8fe21c12c0 100644 --- a/src/bin/elua/modules/xgettext/parser.lua +++ b/src/bin/elua/modules/xgettext/parser.lua @@ -134,4 +134,7 @@ end return { init = function (chunkname, input, keywords) local ls = lexer.init(chunkname, input) ls:get() + local coro = coroutine.wrap(parse, ls, keywords) + coro(ls, keywords) + return coro end } \ No newline at end of file