Files
mercury/tests/invalid/bad_foreign_export_enum.m
Julien Fischer 077101dd00 Improve error reporting for more foreign language interface pragmas.
The first argument of all foreign language interface pragmas specifies the
foreign language.  Define a separate predicate that can be used to parse
this for all of them and use that predicate for foreign_{enum,export_enum,
import_module,export} pragmas.  (The others will be converted in a separate
change.)

Report all of the syntax errors occurring in foreign_{export_enum,import_module,
export) pragmas, not just the first one.

Improve test coverage for syntax errors occurring in the above pragmas.

compiler/parse_pragma.m:
     Rename parse_foreign_language/2 and re-purpose the existing name for
     a new predicate that parses a foreign language, possibly returning
     an error spec.

     Report all syntax errors that occur in foreign_{export_enum,import_module,
     export} pragmas.

     Add a comment noting some additional checks we could perform for
     foreign_export pragmas.

     For foreign_import_module pragmas, generate separate error messages
     for an incorrect number of arguments and an invalid module name.

     Use the correct error context in a number of places.

     Re-word some error messages.

compiler/parse_mutable.m:
     Conform to the above change to parse_foreign_language.

tests/invalid/Mmakefile:
     Add the new tests.

tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
    New tests for syntax errors in these pragmas.
2016-05-25 16:00:50 +10:00

34 lines
689 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%---------------------------------------------------------------------------%
:- module bad_foreign_export_enum.
:- interface.
:- type fruit
---> orange
; lemon
; apple.
:- implementation.
% Wrong number of arguments.
%
:- pragma foreign_export_enum("C").
% Invalid foreign language.
%
:- pragma foreign_export_enum("InvalidLanguage", fruit/0).
% Second arg is not name / arity.
%
:- pragma foreign_export_enum("C", fruit).
:- pragma foreign_export_enum(
"InvalidLanguage",
fruit,
1234,
5678
).