Permalink
Browse files

Added ability to parse protobuf spec from a string rather than a file.

  • Loading branch information...
1 parent b800ec0 commit 530e76fbfe1ab4190d65b56ce1a96451a73112fa @esstrifork esstrifork committed Jun 28, 2011
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/protobuffs_compile.erl
View
@@ -24,7 +24,7 @@
%% OTHER DEALINGS IN THE SOFTWARE.
-module(protobuffs_compile).
-export([scan_file/1, scan_file/2, generate_source/1, generate_source/2]).
--export([parse/1]).
+-export([parse/1, parse_text/1]).
-record(collected,{enum=[], msg=[], extensions=[]}).
@@ -158,6 +158,10 @@ parse(FileName) ->
file:close(InFile)
end.
+parse_text(Text) ->
+ Tokens = tokenize_text(Text),
+ protobuffs_parser:parse(Tokens).
+
%% @hidden
tokenize_file(InFile) ->
tokenize_file(InFile, []).
@@ -174,6 +178,17 @@ tokenize_file(InFile, Acc) ->
end.
%% @hidden
+tokenize_text(Text) ->
+ case protobuffs_scanner:tokens([], Text ++ [$\ | eof]) of
+ {done, {ok,Tokens,_EndLine}, eof} ->
+ Tokens;
+ {done, {error, {_,_,Reason}, LineNo}, _} ->
+ error({scanning_error, Reason, {line,LineNo}});
+ _ ->
+ error(scanning_error)
+ end.
+
+%% @hidden
filter_forms(Msgs, Enums, [{attribute,L,file,{_,_}}|Tail], Basename, Acc) ->
filter_forms(Msgs, Enums, Tail, Basename, [{attribute,L,file,{"src/" ++ Basename ++ ".erl",L}}|Acc]);

0 comments on commit 530e76f

Please sign in to comment.