mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-29 16:24:43 +00:00
Estimated hours taken: 16 Branches: main Add support for "implementation-defined literals" $file, $line, $module, $pred, $grade which are replaced constants by the compiler. library/lexer.m: Add a new type of token. Read "$foo" as a `implementation_defined' token instead of two name tokens. library/term.m: library/term_io.m: Add a new type of constant, `implementation_defined'. library/parser.m: Handle `implementation_defined' tokens from the lexer. compiler/check_hlds.m: compiler/implementation_defined_literals.m: compiler/mercury_compile.m: Add a new pass to replace implementation-defined literals in program clauses. Call the new pass. compiler/notes/compiler_design.html: Document the new module. compiler/prog_data.m: Add a new option to `cons_id', namely `implementation_defined_const'. compiler/typecheck.m: Tell the typechecker the types of the supported implementation-defined literals. compiler/prog_io_util.m: Make `convert_bound_inst' fail if implementation-defined literals appear in inst definitions so that an error will be issued. compiler/bytecode_gen.m: compiler/ctgc.selector.m: compiler/dead_proc_elim.m: compiler/dependency_graph.m: compiler/erl_unify_gen.m: compiler/fact_table.m: compiler/higher_order.m: compiler/hlds_code_util.m: compiler/hlds_out.m: compiler/inst_check.m: compiler/mercury_to_mercury.m: compiler/mode_util.m: compiler/module_qual.m: compiler/prog_rep.m: compiler/prog_type.m: compiler/prog_util.m: compiler/rbmm.execution_path.m: compiler/unused_imports.m: compiler/xml_documentation.m: Conform to addition of `implementation_defined_const'. doc/reference_manual.texi: Document implementation-defined literals. NEWS: Announce the new feature. tests/hard_coded/Mmakefile: tests/hard_coded/impl_def_lex.exp: tests/hard_coded/impl_def_lex.m: tests/hard_coded/impl_def_lex_string.exp: tests/hard_coded/impl_def_lex_string.m: tests/hard_coded/impl_def_literal.exp: tests/hard_coded/impl_def_literal.m: tests/invalid/Mmakefile: tests/invalid/impl_def_literal_syntax.err_exp: tests/invalid/impl_def_literal_syntax.m: tests/invalid/undef_impl_def_literal.err_exp: tests/invalid/undef_impl_def_literal.m: Add test cases.
56 lines
1.6 KiB
Mathematica
56 lines
1.6 KiB
Mathematica
% Test the lexer reads implementation-defined literals from strings correctly.
|
|
|
|
:- module impl_def_lex_string.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module io.
|
|
:- import_module lexer.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
InitialPos = posn(1, 0, 0),
|
|
|
|
string_get_token_list("$f", TokensA, InitialPos, FinalPosA),
|
|
io.write({TokensA, FinalPosA}, !IO),
|
|
io.nl(!IO),
|
|
|
|
string_get_token_list("$foo", TokensB, InitialPos, FinalPosB),
|
|
io.write({TokensB, FinalPosB}, !IO),
|
|
io.nl(!IO),
|
|
|
|
% followed by non-lowercase character
|
|
string_get_token_list("$FOO", TokensC, InitialPos, FinalPosC),
|
|
io.write({TokensC, FinalPosC}, !IO),
|
|
io.nl(!IO),
|
|
|
|
% followed by eof
|
|
string_get_token_list("$", TokensD, InitialPos, FinalPosD),
|
|
io.write({TokensD, FinalPosD}, !IO),
|
|
io.nl(!IO),
|
|
|
|
% followed by graphic character
|
|
string_get_token_list("$!$", TokensE, InitialPos, FinalPosE),
|
|
io.write({TokensE, FinalPosE}, !IO),
|
|
io.nl(!IO),
|
|
|
|
string_get_token_list("$,", TokensF, InitialPos, FinalPosF),
|
|
io.write({TokensF, FinalPosF}, !IO),
|
|
io.nl(!IO),
|
|
|
|
string_get_token_list("$0", TokensG, InitialPos, FinalPosG),
|
|
io.write({TokensG, FinalPosG}, !IO),
|
|
io.nl(!IO).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
% vi:ft=mercury:ts=8:sts=4:sw=4:et
|