Compiler accepts input from stdin when source file is called "-"

This commit is contained in:
Brian Anderson 2011-07-30 15:50:16 -07:00
parent 2d5b651f49
commit 5f4b7e1ba7
4 changed files with 66 additions and 17 deletions

View file

@ -9,6 +9,7 @@ import syntax::parse::parser::parser;
import syntax::parse::parser::new_parser_from_file;
import syntax::parse::parser::parse_inner_attrs_and_next;
import syntax::parse::parser::parse_mod_items;
import syntax::parse::parser::SOURCE_FILE;
export eval_crate_directives_to_mod;
export mode_parse;
@ -55,7 +56,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
if cx.mode == mode_depend { cx.deps += ~[full_path]; ret; }
let p0 =
new_parser_from_file(cx.sess, cx.cfg, full_path, cx.chpos,
cx.byte_pos);
cx.byte_pos, SOURCE_FILE);
let inner_attrs = parse_inner_attrs_and_next(p0);
let mod_attrs = attrs + inner_attrs.inner;
let first_item_outer_attrs = inner_attrs.next;

View file

@ -58,10 +58,10 @@ type parser =
fn get_sess() -> parse_sess ;
};
fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str,
chpos: uint, byte_pos: uint) -> parser {
let ftype = SOURCE_FILE;
if str::ends_with(path, ".rc") { ftype = CRATE_FILE; }
fn new_parser_from_file(sess: parse_sess, cfg:
ast::crate_cfg, path: str,
chpos: uint, byte_pos: uint,
ftype: file_type) -> parser {
let srdr = ioivec::file_reader(path);
let src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
let filemap = codemap::new_filemap(path, chpos, byte_pos);
@ -2313,7 +2313,7 @@ fn parse_native_view(p: &parser) -> (@ast::view_item)[] {
fn parse_crate_from_source_file(input: &str, cfg: &ast::crate_cfg,
sess: &parse_sess) -> @ast::crate {
let p = new_parser_from_file(sess, cfg, input, 0u, 0u);
let p = new_parser_from_file(sess, cfg, input, 0u, 0u, SOURCE_FILE);
ret parse_crate_mod(p, cfg, sess);
}
@ -2430,7 +2430,7 @@ fn parse_crate_directives(p: &parser, term: token::token,
fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg,
sess: &parse_sess) -> @ast::crate {
let p = new_parser_from_file(sess, cfg, input, 0u, 0u);
let p = new_parser_from_file(sess, cfg, input, 0u, 0u, CRATE_FILE);
let lo = p.get_lo_pos();
let prefix = std::fs::dirname(p.get_filemap().name);
let leading_attrs = parse_inner_attrs_and_next(p);
@ -2455,6 +2455,21 @@ fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg,
attrs: crate_attrs,
config: p.get_cfg()});
}
fn parse_crate_from_file(input: &str, cfg: &ast::crate_cfg,
sess: &parse_sess) -> @ast::crate {
if str::ends_with(input, ".rc") {
parse_crate_from_crate_file(input, cfg, sess)
} else if str::ends_with(input, ".rs") {
parse_crate_from_source_file(input, cfg, sess)
} else {
codemap::emit_error(none,
"unknown input file type: " + input,
sess.cm);
fail
}
}
//
// Local Variables:
// mode: rust