aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTuncer Ayaz <[email protected]>2011-05-28 15:15:26 +0200
committerTuncer Ayaz <[email protected]>2011-06-01 11:41:59 +0200
commit69a2b05f717b9688dfb5c1aeb874499caf1026dd (patch)
tree9f246235b35083c96d0b1d4760ec04a50bbd4aa3
parent8f9203ccd0c64cb4b03792e5599b27af26e2fcde (diff)
downloadotp-69a2b05f717b9688dfb5c1aeb874499caf1026dd.tar.gz
otp-69a2b05f717b9688dfb5c1aeb874499caf1026dd.tar.bz2
otp-69a2b05f717b9688dfb5c1aeb874499caf1026dd.zip
yecc: add warnings_as_errors option
-rw-r--r--lib/parsetools/doc/src/yecc.xml4
-rw-r--r--lib/parsetools/src/yecc.erl28
-rw-r--r--lib/parsetools/test/yecc_SUITE.erl8
3 files changed, 32 insertions, 8 deletions
diff --git a/lib/parsetools/doc/src/yecc.xml b/lib/parsetools/doc/src/yecc.xml
index 81f1550b0a..c712609cf4 100644
--- a/lib/parsetools/doc/src/yecc.xml
+++ b/lib/parsetools/doc/src/yecc.xml
@@ -95,6 +95,10 @@
<item>This is a short form for both <c>report_errors</c> and
<c>report_warnings</c>.
</item>
+ <tag><c>warnings_as_errors</c></tag>
+ <item>
+ <p>Causes warnings to be treated as errors.</p>
+ </item>
<tag><c>{return_errors, bool()}</c>.</tag>
<item>If this flag is set, <c>{error, Errors, Warnings}</c>
is returned when there are errors. Default is
diff --git a/lib/parsetools/src/yecc.erl b/lib/parsetools/src/yecc.erl
index 4119e2631b..72cff3af92 100644
--- a/lib/parsetools/src/yecc.erl
+++ b/lib/parsetools/src/yecc.erl
@@ -278,8 +278,8 @@ options(Options0) when is_list(Options0) ->
(T) -> [T]
end, Options0),
options(Options, [file_attributes, includefile, parserfile,
- report_errors, report_warnings, return_errors,
- return_warnings, time, verbose], [])
+ report_errors, report_warnings, warnings_as_errors,
+ return_errors, return_warnings, time, verbose], [])
catch error: _ -> badarg
end;
options(Option) ->
@@ -333,6 +333,7 @@ default_option(includefile) -> [];
default_option(parserfile) -> [];
default_option(report_errors) -> true;
default_option(report_warnings) -> true;
+default_option(warnings_as_errors) -> false;
default_option(return_errors) -> false;
default_option(return_warnings) -> false;
default_option(time) -> false;
@@ -341,6 +342,7 @@ default_option(verbose) -> false.
atom_option(file_attributes) -> {file_attributes, true};
atom_option(report_errors) -> {report_errors, true};
atom_option(report_warnings) -> {report_warnings, true};
+atom_option(warnings_as_errors) -> {warnings_as_errors,true};
atom_option(return_errors) -> {return_errors, true};
atom_option(return_warnings) -> {return_warnings, true};
atom_option(time) -> {time, true};
@@ -409,12 +411,16 @@ infile(Parent, Infilex, Options) ->
{error, Reason} ->
add_error(St0#yecc.infile, none, {file_error, Reason}, St0)
end,
- case St#yecc.errors of
- [] -> ok;
+ case {St#yecc.errors, werr(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.
+
outfile(St0) ->
case file:open(St0#yecc.outfile, [write, delayed_write]) of
{ok, Outport} ->
@@ -777,17 +783,23 @@ yecc_ret(St0) ->
report_warnings(St),
Es = pack_errors(St#yecc.errors),
Ws = pack_warnings(St#yecc.warnings),
+ Werr = werr(St),
if
+ Werr ->
+ do_error_return(St, Es, Ws);
Es =:= [] ->
case member(return_warnings, St#yecc.options) of
true -> {ok, St#yecc.outfile, Ws};
false -> {ok, St#yecc.outfile}
end;
true ->
- case member(return_errors, St#yecc.options) of
- true -> {error, Es, Ws};
- false -> error
- end
+ do_error_return(St, Es, Ws)
+ end.
+
+do_error_return(St, Es, Ws) ->
+ case member(return_errors, St#yecc.options) of
+ true -> {error, Es, Ws};
+ false -> error
end.
check_expected(St0) ->
diff --git a/lib/parsetools/test/yecc_SUITE.erl b/lib/parsetools/test/yecc_SUITE.erl
index 1de87b3bff..0133524950 100644
--- a/lib/parsetools/test/yecc_SUITE.erl
+++ b/lib/parsetools/test/yecc_SUITE.erl
@@ -247,6 +247,14 @@ syntax(Config) when is_list(Config) ->
?line {ok,_,[{_,[{2,yecc,bad_declaration}]}]} =
yecc:file(Filename, Ret),
+ %% Bad declaration with warnings_as_errors.
+ error = yecc:file(Filename, [warnings_as_errors]),
+ error = yecc:file(Filename, [return_warnings,warnings_as_errors]),
+ {ok,_,[{_,[{2,yecc,bad_declaration}]}]} =
+ yecc:file(Filename, [return_warnings]),
+ {error,_,[{_,[{2,yecc,bad_declaration}]}]} =
+ yecc:file(Filename, [return_errors,warnings_as_errors]),
+
%% Bad declaration.
?line ok = file:write_file(Filename,
<<"Nonterminals nt. Terminals t.