diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 6d4cd104e77..752ab999197 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -13,10 +13,22 @@ import std.option.none; import std._str; import std._vec; +impure fn parse_input(session.session sess, + parser.parser p, + str input) -> @front.ast.crate { + if (_str.ends_with(input, ".rc")) { + ret parser.parse_crate_from_crate_file(p); + } else if (_str.ends_with(input, ".rs")) { + ret parser.parse_crate_from_source_file(p); + } + sess.err("unknown unput file type: " + input); + fail; +} + impure fn compile_input(session.session sess, str input, str output, bool shared) { auto p = parser.new_parser(sess, 0, input); - auto crate = parser.parse_crate(p); + auto crate = parse_input(sess, p, input); crate = resolve.resolve_crate(sess, crate); crate = typeck.check_crate(sess, crate); trans.trans_crate(sess, crate, output, shared); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 1cf8af2d425..dd5a6b50d75 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1738,7 +1738,14 @@ impure fn parse_use_and_imports(parser p) -> vec[ast.use_or_import] { } } -impure fn parse_crate(parser p) -> @ast.crate { +impure fn parse_crate_from_crate_file(parser p) -> @ast.crate { + auto lo = p.get_span(); + auto hi = lo; + auto m = parse_mod_items(p, token.EOF); + ret @spanned(lo, hi, rec(module=m)); +} + +impure fn parse_crate_from_source_file(parser p) -> @ast.crate { auto lo = p.get_span(); auto hi = lo; auto m = parse_mod_items(p, token.EOF);