mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 19:33:46 +00:00
tests/hard_coded/lexer_zero.m:
Document what the expected outputs correspond.
tests/hard_coded/lexer_zero.exp4:
Add an expected output for this test for spf grades.
59 lines
1.8 KiB
Mathematica
59 lines
1.8 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
% The .exp file is the C backends with double-precision floats.
|
|
% The .exp2 file is for the Java backend.
|
|
% The .exp3 file is for the C# backend.
|
|
% The .exp4 file is for the C backend with single-precision floats.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module lexer_zero.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module lexer.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
% Read from the current input stream.
|
|
lexer.get_token_list(Tokens, !IO),
|
|
write_token_list(Tokens, !IO),
|
|
io.nl(!IO),
|
|
|
|
% Read from a string.
|
|
io.open_input("lexer_zero.inp", OpenRes, !IO),
|
|
(
|
|
OpenRes = ok(Stream),
|
|
io.read_file_as_string(Stream, ReadRes, !IO),
|
|
(
|
|
ReadRes = ok(String),
|
|
Posn0 = posn(1, 0, 0),
|
|
lexer.string_get_token_list(String, StringTokens, Posn0, _Posn),
|
|
write_token_list(StringTokens, !IO)
|
|
;
|
|
ReadRes = error(_, Error),
|
|
io.write_line(Error, !IO)
|
|
),
|
|
io.close_input(Stream, !IO)
|
|
;
|
|
OpenRes = error(Error),
|
|
io.write_line(Error, !IO)
|
|
).
|
|
|
|
:- pred write_token_list(token_list::in, io::di, io::uo) is det.
|
|
|
|
write_token_list(token_nil, !IO).
|
|
write_token_list(token_cons(Token, Context, List), !IO) :-
|
|
io.write_int(Context, !IO),
|
|
io.write_string(": ", !IO),
|
|
io.write_line(Token, !IO),
|
|
write_token_list(List, !IO).
|