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)
|
error(msg, 0)
|
||||||
end
|
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 next_char = function(ls)
|
||||||
local c = ls.reader()
|
local c = ls.reader()
|
||||||
ls.current = c
|
ls.current = c
|
||||||
|
@ -282,4 +286,4 @@ return { init = function(chunkname, input)
|
||||||
ls.coro = coro
|
ls.coro = coro
|
||||||
coro(ls)
|
coro(ls)
|
||||||
return coro
|
return coro
|
||||||
end }
|
end, syntax_error = syntax_error }
|
|
@ -2,10 +2,62 @@
|
||||||
|
|
||||||
local lexer = require("xgettext.lexer")
|
local lexer = require("xgettext.lexer")
|
||||||
|
|
||||||
|
local syntax_error = lexer.syntax_error
|
||||||
|
|
||||||
local yield = coroutine.yield
|
local yield = coroutine.yield
|
||||||
|
|
||||||
local saved_comments = {}
|
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)
|
local parse = function(ls, keywords)
|
||||||
yield()
|
yield()
|
||||||
local tok = ls.token
|
local tok = ls.token
|
||||||
|
@ -14,6 +66,9 @@ local parse = function(ls, keywords)
|
||||||
saved_comments[#saved_comments + 1] = tok.value
|
saved_comments[#saved_comments + 1] = tok.value
|
||||||
ls:get()
|
ls:get()
|
||||||
elseif tok.name == "<name>" and keywords[tok.value] then
|
elseif tok.name == "<name>" and keywords[tok.value] then
|
||||||
|
local kw = keywords[tok.value]
|
||||||
|
ls:get()
|
||||||
|
|
||||||
local cmt = saved_comments[#saved_comments]
|
local cmt = saved_comments[#saved_comments]
|
||||||
saved_comments = {}
|
saved_comments = {}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue