diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-07-30 15:50:16 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-02 10:39:09 -0700 |
| commit | 5f4b7e1ba7121955ce4805cd55a51bc856d1f5b2 (patch) | |
| tree | 5d790b7fe89820389d627f072743d2b1bd24e6b9 /src/comp/syntax/parse | |
| parent | 2d5b651f4981b85d0e3864d8df6bd0953578e1f4 (diff) | |
| download | rust-5f4b7e1ba7121955ce4805cd55a51bc856d1f5b2.tar.gz rust-5f4b7e1ba7121955ce4805cd55a51bc856d1f5b2.zip | |
Compiler accepts input from stdin when source file is called "-"
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/eval.rs | 3 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 27 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index 08a60404172..c5bf0f2586b 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -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; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 9c929390bd2..58146b950ea 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -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 |
