Преглед на файлове

ft: parse返回binary

master v1.2.0
SisMaker преди 4 години
родител
ревизия
36f0252f92
променени са 3 файла, в които са добавени 59 реда и са изтрити 9 реда
  1. +20
    -1
      src/genProto.erl
  2. +31
    -8
      src/protoParse.erl
  3. +8
    -0
      src/writeCs/gCsGen.erl

+ 20
- 1
src/genProto.erl Целия файл

@ -11,7 +11,25 @@
]).
convertFile(File) ->
protoParse:parseFile(File).
erlang:erase(),
erlang:put(pd_errlist, []),
erlang:put(pd_handler, []),
case filename:extension(File) == ".mpdf" of
true ->
io:format("Convert proto msg file: ~s ~n", [File]),
BaseName = filename:basename(File, ".mpdf"),
[ModIndex, ModName] = re:split(BaseName, "_"),
Index = binary_to_integer(ModIndex),
erlang:put(pd_messageid, Index * ?MsgIdSegSize + 1),
erlang:put(pd_handler, [{Index, ModName} | erlang:get(pd_handler)]),
erlang:put(pd_errcodeid, Index * ?MsgIdSegSize + 1),
SProto = protoParse:parseFile(File),
ErrCode = erlang:get(pd_errlist),
Handler = erlang:get(pd_handler),
{SProto, Handler, ErrCode};
_ ->
io:format("not proto msg file: ~s ~n", [File])
end.
convert([ProtoDir, HrlDir, ErlDir]) ->
convertDir(atom_to_list(ProtoDir), atom_to_list(HrlDir), atom_to_list(ErlDir)).
@ -21,6 +39,7 @@ convertDir() ->
convertDir(ProtoDir) ->
convertDir(ProtoDir, "./", "./").
convertDir(ProtoDir, HrlDir, ErlDir) ->
erlang:erase(),
erlang:put(pd_errlist, []),
erlang:put(pd_handler, []),
FunRead =

+ 31
- 8
src/protoParse.erl Целия файл

@ -56,7 +56,7 @@ parseParse(Input) when is_binary(Input) ->
(p_seq([p_label('name', fun 'name'/2), fun 'blank0'/2, p_label('structural', fun 'structural'/2)]))(I, D)
end,
fun(Node, _Idx) ->
Name = binary_to_list(iolist_to_binary(proplists:get_value(name, Node))),
Name = iolist_to_binary(proplists:get_value(name, Node)),
Structural = proplists:get_value(structural, Node),
MsgId = erlang:get(pd_messageid),
erlang:put(pd_messageid, MsgId + 1),
@ -80,8 +80,8 @@ parseParse(Input) when is_binary(Input) ->
(p_seq([p_label('datatype', fun 'typename'/2), fun 'blanks'/2, p_label('name', fun 'name'/2), fun 'blank0'/2, p_string(<<";">>)]))(I, D)
end,
fun(Node, _Idx) ->
DataType = binary_to_list(iolist_to_binary(proplists:get_value(datatype, Node))),
Name = binary_to_list(iolist_to_binary(proplists:get_value(name, Node))),
DataType = iolist_to_binary(proplists:get_value(datatype, Node)),
Name = iolist_to_binary(proplists:get_value(name, Node)),
{DataType, Name}
end).
@ -124,10 +124,10 @@ parseParse(Input) when is_binary(Input) ->
fun(Node, _Idx) ->
ErrNameList = proplists:get_value('errname', Node),
ErrCodeStrList = proplists:get_value('errcode_str', Node),
ErrName = binary_to_list(iolist_to_binary(ErrNameList)),
Desc = binary_to_list(iolist_to_binary(ErrCodeStrList)),
ErrName = iolist_to_binary(ErrNameList),
Desc = iolist_to_binary(ErrCodeStrList),
ErrList = erlang:get(pd_errlist),
UpErrName = string:to_upper(ErrName),
UpErrName = toUpperStr(ErrName),
case UpErrName =/= [] andalso lists:keyfind(UpErrName, 1, ErrList) == false of
true ->
ErrCodeId = erlang:get(pd_errcodeid),
@ -458,7 +458,7 @@ p_charclass(Class) ->
{Head, Tail} = erlang:split_binary(Inp, Length),
{Head, Tail, p_advance_index(Head, Index)};
_ ->
{fail, {expected, {character_class, binary_to_list(Class)}, Index}}
{fail, {expected, {character_class, Class}, Index}}
end
end.
-endif.
@ -473,7 +473,7 @@ p_regexp(Regexp) ->
{Head, Tail} = erlang:split_binary(Inp, Length),
{Head, Tail, p_advance_index(Head, Index)};
_ ->
{fail, {expected, {regexp, binary_to_list(Regexp)}, Index}}
{fail, {expected, {regexp, Regexp}, Index}}
end
end.
-endif.
@ -499,3 +499,26 @@ p_advance_index(MatchedInput, Index) when is_integer(MatchedInput) -> % single c
$\n -> {{line, Line + 1}, {column, 1}};
_ -> {{line, Line}, {column, Col + 1}}
end.
toUpperStr(ListStr) when is_list(ListStr) ->
[
begin
case C >= $a andalso C =< $z of
true ->
C - 32;
_ ->
C
end
end || C <- ListStr
];
toUpperStr(BinStr) when is_binary(BinStr) ->
<<
begin
case C >= $a andalso C =< $z of
true ->
<<(C - 32)>>;
_ ->
<<C>>
end
end || <<C:8>> <= BinStr
>>.

+ 8
- 0
src/writeCs/gCsGen.erl Целия файл

@ -0,0 +1,8 @@
-module(gCsGen).
-export([
genCs/4
]).
genCs(_SortedSProtoList, _SortedErrList, _HrlDir, _ErlDir) ->
ok.

Зареждане…
Отказ
Запис