forked from enlightenment/efl
elua: extend the xgettext parser a bit
This commit is contained in:
parent
839ce0f651
commit
812a601548
|
@ -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 }
|
||||
end, syntax_error = syntax_error }
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue