# load-file-g.pkg
# Compiled by:
#
src/lib/x-kit/widget/xkit-widget.sublibstipulate
package vb = view_buffer; # view_buffer is from
src/lib/x-kit/widget/old/fancy/graphviz/text/view-buffer.pkg package u = approximate_ml_lex::user_declarations;
herein
generic package load_file_g (
io: api {
Input_Stream;
open_for_read: String -> Input_Stream;
close_input: Input_Stream -> Void;
read_n: (Input_Stream, Int) -> String;
}
): Load_File {
fun load_file (filename, range)
=
{ stream = io::open_for_read filename;
lexer = approximate_ml_lex::make_lexer
#
(\\ n = io::read_n (stream, n));
fun scan_file lines
=
scan_line ([], lines)
where
fun scan_line (toks, lines)
=
case (lexer())
#
u::EOF => (reverse toks) ! lines;
u::NL => scan_file ((reverse toks) ! lines);
u::TOK tok => scan_line (tok ! toks, lines);
u::COM lst => scan_list (lst, toks, lines);
u::STR lst => scan_list (lst, toks, lines);
esac
also
fun scan_list ([], toks, lines)
=>
scan_line (toks, lines);
scan_list (u::NL ! r, toks, lines)
=>
scan_list (r, [], (reverse toks) ! lines);
scan_list (u::TOK tok ! r, toks, lines)
=>
scan_list (r, tok ! toks, lines);
scan_list _
=>
raise exception DIE "load_file";
end;
end;
lines = scan_file [];
io::close_input stream;
case range
#
NULL =>
reverse lines;
THE { first, last }
=>
{ fun skip (0, lines) => lines;
skip (i, []) => [];
skip (i, _ ! lines) => skip (i - 1, lines);
end;
fun proj (0, _, lines) => lines;
proj (_, [], lines) => lines;
proj (i, l ! r, lines) => proj (i - 1, r, l ! lines);
end;
proj
( (last-first)+1,
skip ((length lines)-last, lines),
[]
);
};
esac;
}
except _ = [];
}; # generic package load_file_g
end;