Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

… message
  • Loading branch information...
commit b6e3021a3b98c508d9b9cfb7310b00a96f565049 1 parent 2715966
@freke authored
View
41 src/protobuffs_compile.erl
@@ -125,18 +125,18 @@ output_source (Basename, Messages, Enums, Options) ->
%% @hidden
parse_file(FileName) ->
{ok, InFile} = protobuffs_io:open(FileName, [read]),
- String = parse_file(InFile,[]),
+ String = parse_file(InFile,[],1),
ok = file:close(InFile),
{ok,String}.
%% @hidden
-parse_file(InFile,Acc) ->
- case protobuffs_io:request(InFile) of
- {ok,Token,_EndLine} ->
- parse_file(InFile,Acc ++ [Token]);
+parse_file(InFile,Acc,Line) ->
+ case protobuffs_io:request(InFile,Line) of
+ {ok,Token,EndLine} ->
+ parse_file(InFile,Acc ++ [Token],EndLine);
{error,token} ->
exit(scanning_error);
- {eof,_} ->
+ {eof,EndLine} ->
Acc
end.
@@ -144,18 +144,23 @@ generate_output(TokenizedString,Basename,Options) ->
generate_output(Options, Basename, TokenizedString, fun output/4).
generate_output(Options, Basename, TokenizedString, OutputFunction) ->
- {ok, FirstParsed} = parse_string(TokenizedString),
- ImportPaths = ["./", "src/"
- | proplists:get_value(imports_dir, Options, [])],
- Parsed = parse_imports(FirstParsed,
- ImportPaths),
- Collected = protobuffs_compile_lib:collect_full_messages(Parsed),
- Messages = protobuffs_compile_lib:resolve_types(Collected#collected.msg,
- Collected#collected.enum),
- OutputFunction(Basename,
- Messages,
- Collected#collected.enum,
- Options).
+ case parse_string(TokenizedString) of
+ {ok, FirstParsed} ->
+ ImportPaths = ["./", "src/"
+ | proplists:get_value(imports_dir, Options, [])],
+ Parsed = parse_imports(FirstParsed,
+ ImportPaths),
+ Collected = protobuffs_compile_lib:collect_full_messages(Parsed),
+ Messages = protobuffs_compile_lib:resolve_types(Collected#collected.msg,
+ Collected#collected.enum),
+ OutputFunction(Basename,
+ Messages,
+ Collected#collected.enum,
+ Options);
+ {error,{Line_number, Module, Message}} ->
+ error_logger:error_report({Line_number, Module, Message,TokenizedString}),
+ exit(1)
+ end.
create_forms(Basename, Messages, Enums) ->
{_,Binary,_} = code:get_object_code(pokemon_pb),
View
6 src/protobuffs_io.erl
@@ -27,7 +27,7 @@
-module(protobuffs_io).
--export([open/2,path_open/3,close/1,format/3,request/1,write_file/2]).
+-export([open/2,path_open/3,close/1,format/3,request/2,write_file/2]).
open(File, Options) ->
file:open(File,Options).
@@ -41,8 +41,8 @@ close(FileRef) ->
format(FileRef, FormatString, WriteFields) ->
io:format(FileRef, FormatString, WriteFields).
-request(InFile) ->
- io:request(InFile,{get_until,prompt,protobuffs_scanner,token,[1]}).
+request(InFile,Line) ->
+ io:request(InFile,{get_until,prompt,protobuffs_scanner,token,[Line]}).
write_file(File, Bytes) ->
file:write_file(File,Bytes).
View
1  src/protobuffs_parser.yrl
@@ -32,6 +32,7 @@ g_element -> g_var integer g_var integer ';' : {'$1', unwrap('$2'), unwrap('$
g_element -> g_var integer g_var g_var ';' : {'$1', unwrap('$2'), '$4'}.
g_element -> g_var g_var '=' g_value ';' : {'$1', '$2', '$4'}.
g_element -> g_message : '$1'.
+g_element -> g_message ';' : '$1'.
g_var -> var : unwrap('$1').
View
3  test/erlang_protobuffs_SUITE.erl
@@ -138,9 +138,9 @@ test_proto_files(Config) ->
DataDir = (?config(data_dir, Config)),
NumTests = (?config(num_tests, Config)),
PrivDir = (?config(priv_dir, Config)),
+ test_server:format("~n===Out ~p===~n", [?config(priv_dir,Config)]),
ProtoFiles = filelib:wildcard(filename:join([DataDir, "proto", "*.proto"])),
ScanProtoFiles = [Filename || Filename <- ProtoFiles , scan_file(DataDir, PrivDir, Filename)],
- test_server:format("~n===Out ~p===~n", [?config(priv_dir,Config)]),
Tests = lists:map(fun(Filename) ->
list_to_atom("proper_protobuffs_" ++
filename:basename(Filename,".proto"))
@@ -227,6 +227,7 @@ run_test(NumTests, Testname, Acc) ->
end.
scan_file(DataDir, PrivDir, Filename) ->
+ test_server:format("~n===Scan file ~p===~n", [Filename]),
Path = filename:absname(Filename),
Options = [{imports_dir,
[filename:join([DataDir, "proto"]),
View
2  test/erlang_protobuffs_SUITE_data/proto/enum.proto
@@ -5,7 +5,7 @@ message EnumMsg {
value3 = -1;
value4 = -2147483647;
value5 = 2147483648;
- }
+ };
optional Values value = 1;
}
View
2  test/protobuffs_proper.erl
@@ -531,3 +531,5 @@ proper_protobuffs_mixedCase() ->
Decoded = mixedCase_pb:decode_mixedcase(mixedCase_pb:encode_mixedcase(Input)),
compare_messages(Input, Decoded)
end).
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.