elua: extend the xgettext parser a bit
authorDaniel Kolesa <d.kolesa@samsung.com>
Fri, 23 May 2014 14:43:12 +0000 (15:43 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:51 +0000 (15:48 +0100)
src/bin/elua/modules/xgettext/lexer.lua
src/bin/elua/modules/xgettext/parser.lua

index 5af0f34..d379e1d 100644 (file)
@@ -28,6 +28,10 @@ local lex_error = function(ls, msg, tok)
     error(msg, 0)
 end
 
+local syntax_error = function(ls, msg)
+    lex_error(ls, msg, ls.token.value or ls.token.name)
+end
+
 local next_char = function(ls)
     local c = ls.reader()
     ls.current = c
@@ -282,4 +286,4 @@ return { init = function(chunkname, input)
     ls.coro = coro
     coro(ls)
     return coro
-end }
\ No newline at end of file
+end, syntax_error = syntax_error }
\ No newline at end of file
index 6474a3c..69f9e59 100644 (file)
@@ -2,10 +2,62 @@
 
 local lexer = require("xgettext.lexer")
 
+local syntax_error = lexer.syntax_error
+
 local yield = coroutine.yield
 
 local saved_comments = {}
 
+local check_match = function(ls, a, b, line)
+    if ls.token.name ~= a then
+        if line == ls.line_number then
+            syntax_error(ls, "'" .. a .. "' expected")
+        else
+            syntax_error(ls, "'" .. a .. "' expected (to close '" .. b
+                .. "' at line " .. line .. ")")
+        end
+    end
+end
+
+local parse_arg = function(ls)
+    local plevel = 0
+end
+
+local parse_arglist = function(ls)
+    local tok  = ls.token
+    local rets = {}
+    while true do
+        rets[#rets + 1] = parse_arg(ls)
+        if tok.name == "," then
+            ls:get()
+        else
+            break
+        end
+    end
+end
+
+local parse_call = function(ls)
+    local tok = ls.token
+    if tok.name == "(" then
+        local line = ls.line_number
+        ls:get()
+        if tok.name == ")" then
+            ls:get()
+            return {}
+        end
+        local al = parse_arglist(ls)
+        check_match(ls, ")", "(", line)
+        ls:get()
+        return al
+    elseif tok.name == "<string>" then
+        local v = tok.value
+        ls:get()
+        return { v }
+    else
+        return nil
+    end
+end
+
 local parse = function(ls, keywords)
     yield()
     local tok = ls.token
@@ -14,6 +66,9 @@ local parse = function(ls, keywords)
             saved_comments[#saved_comments + 1] = tok.value
             ls:get()
         elseif tok.name == "<name>" and keywords[tok.value] then
+            local kw = keywords[tok.value]
+            ls:get()
+
             local cmt = saved_comments[#saved_comments]
             saved_comments = {}
         else