elua: initial stuff for the xgettext generator, check existence of all input files...
authorDaniel Kolesa <d.kolesa@samsung.com>
Fri, 30 May 2014 11:31:07 +0000 (12:31 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:52 +0000 (15:48 +0100)
src/bin/elua/apps/xgettext.lua
src/bin/elua/modules/xgettext/generator.lua [new file with mode: 0644]
src/bin/elua/modules/xgettext/parser.lua

index 38a193f..eaaad2f 100644 (file)
@@ -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 (file)
index 0000000..29ec7ab
--- /dev/null
@@ -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
index a5420c0..8fe21c1 100644 (file)
@@ -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