aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-01-03 20:41:11 -0800
committerGraydon Hoare <[email protected]>2011-01-03 20:41:11 -0800
commitd1517471fbe45781a39afed6367944491ce8f4b1 (patch)
treea53686b741ec1e56159062d9dcc94dfb394cd08b /src/comp
parentAdd _str.starts_with and ends_with. (diff)
downloadrust-d1517471fbe45781a39afed6367944491ce8f4b1.tar.xz
rust-d1517471fbe45781a39afed6367944491ce8f4b1.zip
Split driver between parsing source files and crate files, by extension. Add dummy function for crate files.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/driver/rustc.rs14
-rw-r--r--src/comp/front/parser.rs9
2 files changed, 21 insertions, 2 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 6d4cd104..752ab999 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 1cf8af2d..dd5a6b50 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);