Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed parsing of optional ';' after '}', and better error parse error…

… message
  • Loading branch information...
commit b6e3021a3b98c508d9b9cfb7310b00a96f565049 1 parent 2715966
David Åberg authored
41 src/protobuffs_compile.erl
@@ -125,18 +125,18 @@ output_source (Basename, Messages, Enums, Options) ->
125 125 %% @hidden
126 126 parse_file(FileName) ->
127 127 {ok, InFile} = protobuffs_io:open(FileName, [read]),
128   - String = parse_file(InFile,[]),
  128 + String = parse_file(InFile,[],1),
129 129 ok = file:close(InFile),
130 130 {ok,String}.
131 131
132 132 %% @hidden
133   -parse_file(InFile,Acc) ->
134   - case protobuffs_io:request(InFile) of
135   - {ok,Token,_EndLine} ->
136   - parse_file(InFile,Acc ++ [Token]);
  133 +parse_file(InFile,Acc,Line) ->
  134 + case protobuffs_io:request(InFile,Line) of
  135 + {ok,Token,EndLine} ->
  136 + parse_file(InFile,Acc ++ [Token],EndLine);
137 137 {error,token} ->
138 138 exit(scanning_error);
139   - {eof,_} ->
  139 + {eof,EndLine} ->
140 140 Acc
141 141 end.
142 142
@@ -144,18 +144,23 @@ generate_output(TokenizedString,Basename,Options) ->
144 144 generate_output(Options, Basename, TokenizedString, fun output/4).
145 145
146 146 generate_output(Options, Basename, TokenizedString, OutputFunction) ->
147   - {ok, FirstParsed} = parse_string(TokenizedString),
148   - ImportPaths = ["./", "src/"
149   - | proplists:get_value(imports_dir, Options, [])],
150   - Parsed = parse_imports(FirstParsed,
151   - ImportPaths),
152   - Collected = protobuffs_compile_lib:collect_full_messages(Parsed),
153   - Messages = protobuffs_compile_lib:resolve_types(Collected#collected.msg,
154   - Collected#collected.enum),
155   - OutputFunction(Basename,
156   - Messages,
157   - Collected#collected.enum,
158   - Options).
  147 + case parse_string(TokenizedString) of
  148 + {ok, FirstParsed} ->
  149 + ImportPaths = ["./", "src/"
  150 + | proplists:get_value(imports_dir, Options, [])],
  151 + Parsed = parse_imports(FirstParsed,
  152 + ImportPaths),
  153 + Collected = protobuffs_compile_lib:collect_full_messages(Parsed),
  154 + Messages = protobuffs_compile_lib:resolve_types(Collected#collected.msg,
  155 + Collected#collected.enum),
  156 + OutputFunction(Basename,
  157 + Messages,
  158 + Collected#collected.enum,
  159 + Options);
  160 + {error,{Line_number, Module, Message}} ->
  161 + error_logger:error_report({Line_number, Module, Message,TokenizedString}),
  162 + exit(1)
  163 + end.
159 164
160 165 create_forms(Basename, Messages, Enums) ->
161 166 {_,Binary,_} = code:get_object_code(pokemon_pb),
6 src/protobuffs_io.erl
@@ -27,7 +27,7 @@
27 27
28 28 -module(protobuffs_io).
29 29
30   --export([open/2,path_open/3,close/1,format/3,request/1,write_file/2]).
  30 +-export([open/2,path_open/3,close/1,format/3,request/2,write_file/2]).
31 31
32 32 open(File, Options) ->
33 33 file:open(File,Options).
@@ -41,8 +41,8 @@ close(FileRef) ->
41 41 format(FileRef, FormatString, WriteFields) ->
42 42 io:format(FileRef, FormatString, WriteFields).
43 43
44   -request(InFile) ->
45   - io:request(InFile,{get_until,prompt,protobuffs_scanner,token,[1]}).
  44 +request(InFile,Line) ->
  45 + io:request(InFile,{get_until,prompt,protobuffs_scanner,token,[Line]}).
46 46
47 47 write_file(File, Bytes) ->
48 48 file:write_file(File,Bytes).
1  src/protobuffs_parser.yrl
@@ -32,6 +32,7 @@ g_element -> g_var integer g_var integer ';' : {'$1', unwrap('$2'), unwrap('$
32 32 g_element -> g_var integer g_var g_var ';' : {'$1', unwrap('$2'), '$4'}.
33 33 g_element -> g_var g_var '=' g_value ';' : {'$1', '$2', '$4'}.
34 34 g_element -> g_message : '$1'.
  35 +g_element -> g_message ';' : '$1'.
35 36
36 37 g_var -> var : unwrap('$1').
37 38
3  test/erlang_protobuffs_SUITE.erl
@@ -138,9 +138,9 @@ test_proto_files(Config) ->
138 138 DataDir = (?config(data_dir, Config)),
139 139 NumTests = (?config(num_tests, Config)),
140 140 PrivDir = (?config(priv_dir, Config)),
  141 + test_server:format("~n===Out ~p===~n", [?config(priv_dir,Config)]),
141 142 ProtoFiles = filelib:wildcard(filename:join([DataDir, "proto", "*.proto"])),
142 143 ScanProtoFiles = [Filename || Filename <- ProtoFiles , scan_file(DataDir, PrivDir, Filename)],
143   - test_server:format("~n===Out ~p===~n", [?config(priv_dir,Config)]),
144 144 Tests = lists:map(fun(Filename) ->
145 145 list_to_atom("proper_protobuffs_" ++
146 146 filename:basename(Filename,".proto"))
@@ -227,6 +227,7 @@ run_test(NumTests, Testname, Acc) ->
227 227 end.
228 228
229 229 scan_file(DataDir, PrivDir, Filename) ->
  230 + test_server:format("~n===Scan file ~p===~n", [Filename]),
230 231 Path = filename:absname(Filename),
231 232 Options = [{imports_dir,
232 233 [filename:join([DataDir, "proto"]),
2  test/erlang_protobuffs_SUITE_data/proto/enum.proto
@@ -5,7 +5,7 @@ message EnumMsg {
5 5 value3 = -1;
6 6 value4 = -2147483647;
7 7 value5 = 2147483648;
8   - }
  8 + };
9 9
10 10 optional Values value = 1;
11 11 }
2  test/protobuffs_proper.erl
@@ -531,3 +531,5 @@ proper_protobuffs_mixedCase() ->
531 531 Decoded = mixedCase_pb:decode_mixedcase(mixedCase_pb:encode_mixedcase(Input)),
532 532 compare_messages(Input, Decoded)
533 533 end).
  534 +
  535 +

0 comments on commit b6e3021

Please sign in to comment.
Something went wrong with that request. Please try again.