aboutsummaryrefslogtreecommitdiffstats
path: root/lib/parsetools
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parsetools')
-rw-r--r--lib/parsetools/src/leex.erl52
-rw-r--r--lib/parsetools/src/yecc.erl37
-rw-r--r--lib/parsetools/test/leex_SUITE.erl11
-rw-r--r--lib/parsetools/test/yecc_SUITE.erl10
4 files changed, 75 insertions, 35 deletions
diff --git a/lib/parsetools/src/leex.erl b/lib/parsetools/src/leex.erl
index 942e9928b1..cdf20461d9 100644
--- a/lib/parsetools/src/leex.erl
+++ b/lib/parsetools/src/leex.erl
@@ -73,12 +73,15 @@
%%% Interface to erl_compile.
compile(Input0, Output0,
- #options{warning = WarnLevel, verbose=Verbose, includes=Includes}) ->
+ #options{warning = WarnLevel, verbose=Verbose, includes=Includes,
+ specific=Specific}) ->
Input = assure_extension(shorten_filename(Input0), ".xrl"),
Output = assure_extension(shorten_filename(Output0), ".erl"),
Includefile = lists:sublist(Includes, 1),
+ Werror = proplists:get_bool(warnings_as_errors, Specific),
Opts = [{scannerfile,Output},{includefile,Includefile},{verbose,Verbose},
- {report_errors,true},{report_warnings,WarnLevel > 0}],
+ {report_errors,true},{report_warnings,WarnLevel > 0},
+ {warnings_as_errors, Werror}],
case file(Input, Opts) of
{ok, _} ->
ok;
@@ -107,7 +110,7 @@ file(File, Opts0) ->
St = try
{ok,REAs,Actions,Code,St2} = parse_file(St1),
{DFA,DF} = make_dfa(REAs, St2),
- case werr(St2) of
+ case werror(St2) of
false ->
St3 = out_file(St2, DFA, DF, Actions, Code),
case lists:member(dfa_graph, St3#leex.opts) of
@@ -259,9 +262,9 @@ leex_ret(St) ->
report_warnings(St),
Es = pack_errors(St#leex.errors),
Ws = pack_warnings(St#leex.warnings),
- Werr = werr(St),
+ Werror = werror(St),
if
- Werr ->
+ Werror ->
do_error_return(St, Es, Ws);
Es =:= [] ->
case member(return_warnings, St#leex.opts) of
@@ -278,9 +281,9 @@ do_error_return(St, Es, Ws) ->
false -> error
end.
-werr(St) ->
- member(warnings_as_errors, St#leex.opts)
- andalso length(St#leex.warnings) > 0.
+werror(St) ->
+ St#leex.warnings =/= []
+ andalso member(warnings_as_errors, St#leex.opts).
pack_errors([{File,_} | _] = Es) ->
[{File, flatmap(fun({_,E}) -> [E] end, sort(Es))}];
@@ -304,15 +307,24 @@ report_errors(St) ->
end, report_errors, St#leex.opts).
report_warnings(St) ->
- when_opt(fun () ->
- foreach(fun({File,{none,Mod,W}}) ->
- io:fwrite("~s: Warning: ~s\n",
- [File,Mod:format_error(W)]);
- ({File,{Line,Mod,W}}) ->
- io:fwrite("~s:~w: Warning: ~s\n",
- [File,Line,Mod:format_error(W)])
- end, sort(St#leex.warnings))
- end, report_warnings, St#leex.opts).
+ Werror = member(warnings_as_errors, St#leex.opts),
+ Prefix = case Werror of
+ true -> "";
+ false -> "Warning: "
+ end,
+ ReportWerror = Werror andalso member(report_errors, St#leex.opts),
+ ShouldReport = member(report_warnings, St#leex.opts) orelse ReportWerror,
+ when_bool(fun () ->
+ foreach(fun({File,{none,Mod,W}}) ->
+ io:fwrite("~s: ~s~s\n",
+ [File,Prefix,
+ Mod:format_error(W)]);
+ ({File,{Line,Mod,W}}) ->
+ io:fwrite("~s:~w: ~s~s\n",
+ [File,Line,Prefix,
+ Mod:format_error(W)])
+ end, sort(St#leex.warnings))
+ end, ShouldReport).
-spec add_error(_, #leex{}) -> no_return().
add_error(E, St) ->
@@ -360,6 +372,12 @@ when_opt(Do, Opt, Opts) ->
false -> ok
end.
+when_bool(Do, Bool) ->
+ case Bool of
+ true -> Do();
+ false -> ok
+ end.
+
verbose_print(St, Format, Args) ->
when_opt(fun () -> io:fwrite(Format, Args) end, verbose, St#leex.opts).
diff --git a/lib/parsetools/src/yecc.erl b/lib/parsetools/src/yecc.erl
index 72cff3af92..354d56527d 100644
--- a/lib/parsetools/src/yecc.erl
+++ b/lib/parsetools/src/yecc.erl
@@ -133,12 +133,15 @@
%%% Interface to erl_compile.
compile(Input0, Output0,
- #options{warning = WarnLevel, verbose=Verbose, includes=Includes}) ->
+ #options{warning = WarnLevel, verbose=Verbose, includes=Includes,
+ specific=Specific}) ->
Input = shorten_filename(Input0),
Output = shorten_filename(Output0),
Includefile = lists:sublist(Includes, 1),
+ Werror = proplists:get_bool(warnings_as_errors, Specific),
Opts = [{parserfile,Output}, {includefile,Includefile}, {verbose,Verbose},
- {report_errors, true}, {report_warnings, WarnLevel > 0}],
+ {report_errors, true}, {report_warnings, WarnLevel > 0},
+ {warnings_as_errors, Werror}],
case file(Input, Opts) of
{ok, _OutFile} ->
ok;
@@ -411,15 +414,15 @@ infile(Parent, Infilex, Options) ->
{error, Reason} ->
add_error(St0#yecc.infile, none, {file_error, Reason}, St0)
end,
- case {St#yecc.errors, werr(St)} of
+ case {St#yecc.errors, werror(St)} of
{[], false} -> ok;
_ -> _ = file:delete(St#yecc.outfile)
end,
Parent ! {self(), yecc_ret(St)}.
-werr(St) ->
- member(warnings_as_errors, St#yecc.options)
- andalso length(St#yecc.warnings) > 0.
+werror(St) ->
+ St#yecc.warnings =/= []
+ andalso member(warnings_as_errors, St#yecc.options).
outfile(St0) ->
case file:open(St0#yecc.outfile, [write, delayed_write]) of
@@ -783,9 +786,9 @@ yecc_ret(St0) ->
report_warnings(St),
Es = pack_errors(St#yecc.errors),
Ws = pack_warnings(St#yecc.warnings),
- Werr = werr(St),
+ Werror = werror(St),
if
- Werr ->
+ Werror ->
do_error_return(St, Es, Ws);
Es =:= [] ->
case member(return_warnings, St#yecc.options) of
@@ -849,14 +852,22 @@ report_errors(St) ->
end.
report_warnings(St) ->
- case member(report_warnings, St#yecc.options) of
+ Werror = member(warnings_as_errors, St#yecc.options),
+ Prefix = case Werror of
+ true -> "";
+ false -> "Warning: "
+ end,
+ ReportWerror = Werror andalso member(report_errors, St#yecc.options),
+ case member(report_warnings, St#yecc.options) orelse ReportWerror of
true ->
foreach(fun({File,{none,Mod,W}}) ->
- io:fwrite(<<"~s: Warning: ~s\n">>,
- [File,Mod:format_error(W)]);
+ io:fwrite(<<"~s: ~s~s\n">>,
+ [File,Prefix,
+ Mod:format_error(W)]);
({File,{Line,Mod,W}}) ->
- io:fwrite(<<"~s:~w: Warning: ~s\n">>,
- [File,Line,Mod:format_error(W)])
+ io:fwrite(<<"~s:~w: ~s~s\n">>,
+ [File,Line,Prefix,
+ Mod:format_error(W)])
end, sort(St#yecc.warnings));
false ->
ok
diff --git a/lib/parsetools/test/leex_SUITE.erl b/lib/parsetools/test/leex_SUITE.erl
index 48312445ef..1e50aedf07 100644
--- a/lib/parsetools/test/leex_SUITE.erl
+++ b/lib/parsetools/test/leex_SUITE.erl
@@ -152,6 +152,7 @@ file(Config) when is_list(Config) ->
?line writable(Dotfile),
file:delete(Dotfile),
+ ok = file:delete(Scannerfile),
Warn = <<"Definitions.1998\n"
"D = [0-9]\n"
"Rules.\n"
@@ -159,11 +160,15 @@ file(Config) when is_list(Config) ->
"Erlang code.\n">>,
ok = file:write_file(Filename, Warn),
error = leex:file(Filename, [warnings_as_errors]),
+ false = filelib:is_regular(Scannerfile),
error = leex:file(Filename, [return_warnings,warnings_as_errors]),
- {ok,Scannerfile,[{Filename,[{1,leex,ignored_characters}]}]} =
- leex:file(Filename, [return_warnings]),
+ false = filelib:is_regular(Scannerfile),
{error,_,[{Filename,[{1,leex,ignored_characters}]}]} =
- leex:file(Filename, [return_errors,warnings_as_errors]),
+ leex:file(Filename, [return_errors,warnings_as_errors]),
+ false = filelib:is_regular(Scannerfile),
+ {ok,Scannerfile,[{Filename,[{1,leex,ignored_characters}]}]} =
+ leex:file(Filename, [return_warnings]),
+ true = filelib:is_regular(Scannerfile),
file:delete(Filename),
ok.
diff --git a/lib/parsetools/test/yecc_SUITE.erl b/lib/parsetools/test/yecc_SUITE.erl
index 0133524950..a5f66b48e9 100644
--- a/lib/parsetools/test/yecc_SUITE.erl
+++ b/lib/parsetools/test/yecc_SUITE.erl
@@ -173,6 +173,7 @@ syntax(Config) when is_list(Config) ->
%% Report errors. Very simple test of format_error/1.
Ret = [return, {report, true}],
Filename = filename:join(Dir, "file.yrl"),
+ Parserfile = filename:join(Dir, "file.erl"),
Parserfile1 = filename:join(Dir, "a file"),
?line ok = file:write_file(Filename, <<"">>),
@@ -248,12 +249,17 @@ syntax(Config) when is_list(Config) ->
yecc:file(Filename, Ret),
%% Bad declaration with warnings_as_errors.
+ ok = file:delete(Parserfile),
error = yecc:file(Filename, [warnings_as_errors]),
+ false = filelib:is_regular(Parserfile),
error = yecc:file(Filename, [return_warnings,warnings_as_errors]),
- {ok,_,[{_,[{2,yecc,bad_declaration}]}]} =
- yecc:file(Filename, [return_warnings]),
+ false = filelib:is_regular(Parserfile),
{error,_,[{_,[{2,yecc,bad_declaration}]}]} =
yecc:file(Filename, [return_errors,warnings_as_errors]),
+ false = filelib:is_regular(Parserfile),
+ {ok,_,[{_,[{2,yecc,bad_declaration}]}]} =
+ yecc:file(Filename, [return_warnings]),
+ true = filelib:is_regular(Parserfile),
%% Bad declaration.
?line ok = file:write_file(Filename,