Skip to content

Commit

Permalink
support complex options (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
javierguerragiraldez authored Feb 21, 2020
1 parent c9516b0 commit 9bff16e
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion protoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,43 @@ function Lexer:quote(opt)
end
end

function Lexer:structure(opt)
self:whitespace()
if not self:test "{" then
return self:opterror(opt, 'opening curly brace expected')
end
local t = {}
while not self:test "}" do
local ident = self:full_ident "field name" -- TODO: full_ident?
self:test ":"
local value = self:constant()
self:test ","
self:line_end "opt"
t[ident] = value
end
return t
end

function Lexer:array(opt)
self:whitespace()
if not self:test "%[" then
return self:opterror(opt, 'opening square bracket expected')
end
local t = {}
while not self:test "]" do
local value = self:constant()
self:test ","
t[#t + 1] = value
end
return t
end

function Lexer:constant(opt)
local c = self:full_ident('constant', 'opt') or
self:number('opt') or
self:quote('opt')
self:quote('opt') or
self:structure('opt') or
self:array('opt')
if not c and not opt then
return self:error "constant expected"
end
Expand Down Expand Up @@ -563,6 +596,10 @@ function msg_body:oneof(lex, info)
ot[index] = oneof
end

function msg_body:option(lex, info)
toplevel.option(self, lex, default(info, 'options'))
end

end

function toplevel:message(lex, info)
Expand Down Expand Up @@ -684,6 +721,10 @@ function svr_body:rpc(lex, info)
insert_tab(t, rpc)
end

function svr_body:option(lex, info)
toplevel.option(self, lex, default(info, 'options')) -- TODO: should be deeper in the info?
end

function svr_body.stream(_, lex)
lex:error "stream not implement yet"
end
Expand Down

0 comments on commit 9bff16e

Please sign in to comment.