klarna / erlavro

Avro support for Erlang/Elixir (http://avro.apache.org/)
Apache License 2.0
131 stars 39 forks source link

Idl parser #90

Open seriyps opened 5 years ago

seriyps commented 5 years ago

Some draft for idl parser. Should fix #68 at some point.

Just as a quick example of how does the parse tree looks:

> File = "test/data/protocol_with_typedefs.avdl",
> rp( (fun(F) -> {ok, B} = file:read_file(F), {ok, T, _} =  avro_idl_lexer:string(binary_to_list(B)), avro_idl_parser:parse(T) end)(File) ).
{ok,{annotated,{annotation,"namespace","org.erlang.www"},
               {protocol,"MyProto",
                         [{import,idl,"foo.avdl"},
                          {import,protocol,"bar.avpr"},
                          {import,schema,"baz.avsc"},
                          {enum,"MyEnum1",["VAR11","VAR12","VAR13"]},
                          {enum,"MyEnum2",["VAR21","VAR22","VAR23"]},
                          {fixed,"MyFix",10},
                          {record,"MyRec",
                                  [{field,"my_int",int,undefined},
                                   {field,"my_string",string,"wasd"},
                                   {field,"my_float",float,12.34},
                                   {field,"my_bool",boolean,false},
                                   {field,"my_custom",{custom,"MyFix"},undefined},                                                                           
                                   {field,"my_union",{union,[boolean,null]},null},                                                                           
                                   {field,"my_date",date,123456},
                                   {field,"my_decimal",{decimal,5,2},1222},
                                   {field,"my_int_array",{array,int},undefined},                                                                             
                                   {field,"my_int_array_def",{array,int},[1,2,3]},                                                                           
                                   {field,"my_str_array_def",
                                          {array,string},
                                          ["123","456","cdf"]},
                                   {field,"my_map",{map,float},#{"a" => 1.23,"b" => 45.67}}]},                                                               
                          {annotated,{annotation,"namespace","org.erlang.ftp"},                                                                              
                                     {record,"MyAnnotated",
                                             [{field,"error",
                                                     {custom,"org.erlang.www.MyError"},                                                                      
                                                     undefined}]}},
                          {error,"MyError",
                                 [{field,"code",{custom,"MyEnum2"},undefined},
                                  {field,"description",string,undefined}]},
                          {function,"mul",
                                    [{arg,"arg1",int,undefined},{arg,"arg2",float,1.0}],                                                                     
                                    float,undefined},
                          {function,"append",
                                    [{arg,"arg1",bytes,undefined},{arg,"arg2",string,"tail"}],                                                               
                                    {custom,"MyFix"},
                                    {throws,"MyError"}},
                          {function,"gen_server_cast",
                                    [{arg,"opts",{map,float},undefined}],
                                    void,oneway},
                          {function,"ping",[],{custom,"MyEnum1"},undefined}]}}} 
coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 599


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/avro_idl.erl 70 72 97.22%
<!-- Total: 75 77 97.4% -->
Totals Coverage Status
Change from base Build 591: -29.7%
Covered Lines: 2870
Relevant Lines: 4085

💛 - Coveralls
CLAassistant commented 3 years ago

CLA assistant check
All committers have signed the CLA.