2011-06-15 11:19:50 -07:00
|
|
|
|
2011-05-17 20:41:41 +02:00
|
|
|
import std::vec;
|
|
|
|
import std::str;
|
2011-05-12 17:24:54 +02:00
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2011-07-05 11:48:19 +02:00
|
|
|
import syntax::ast;
|
|
|
|
import syntax::parse::token;
|
|
|
|
import syntax::parse::parser::parser;
|
|
|
|
import syntax::parse::parser::new_parser;
|
|
|
|
import syntax::parse::parser::parse_inner_attrs_and_next;
|
|
|
|
import syntax::parse::parser::parse_mod_items;
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-07-01 10:46:59 -07:00
|
|
|
export eval_crate_directives_to_mod;
|
|
|
|
export mode_parse;
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
tag eval_mode { mode_depend; mode_parse; }
|
2011-05-03 15:50:56 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
type ctx =
|
|
|
|
@rec(parser p,
|
|
|
|
eval_mode mode,
|
|
|
|
mutable vec[str] deps,
|
2011-07-05 11:48:19 +02:00
|
|
|
parser::parse_sess sess,
|
2011-06-15 11:19:50 -07:00
|
|
|
mutable uint chpos,
|
2011-06-30 17:29:54 -07:00
|
|
|
ast::crate_cfg cfg);
|
2011-02-24 15:54:55 -08:00
|
|
|
|
2011-07-05 17:50:14 -07:00
|
|
|
fn eval_crate_directives(ctx cx, &(@ast::crate_directive)[] cdirs,
|
2011-06-15 11:19:50 -07:00
|
|
|
str prefix, &mutable vec[@ast::view_item] view_items,
|
|
|
|
&mutable vec[@ast::item] items) {
|
2011-05-12 17:24:54 +02:00
|
|
|
for (@ast::crate_directive sub_cdir in cdirs) {
|
2011-06-30 17:29:54 -07:00
|
|
|
eval_crate_directive(cx, sub_cdir, prefix, view_items, items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-05 17:50:14 -07:00
|
|
|
fn eval_crate_directives_to_mod(ctx cx, &(@ast::crate_directive)[] cdirs,
|
|
|
|
str prefix) -> ast::_mod {
|
2011-05-16 18:21:22 -07:00
|
|
|
let vec[@ast::view_item] view_items = [];
|
|
|
|
let vec[@ast::item] items = [];
|
2011-06-30 17:29:54 -07:00
|
|
|
eval_crate_directives(cx, cdirs, prefix, view_items, items);
|
2011-05-11 16:30:48 +02:00
|
|
|
ret rec(view_items=view_items, items=items);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
|
2011-06-30 17:29:54 -07:00
|
|
|
fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
|
2011-06-15 11:19:50 -07:00
|
|
|
&mutable vec[@ast::view_item] view_items,
|
|
|
|
&mutable vec[@ast::item] items) {
|
2011-02-24 15:54:55 -08:00
|
|
|
alt (cdir.node) {
|
2011-06-28 18:15:39 -07:00
|
|
|
case (ast::cdir_src_mod(?id, ?file_opt, ?attrs)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
auto file_path = id + ".rs";
|
|
|
|
alt (file_opt) {
|
2011-06-15 11:19:50 -07:00
|
|
|
case (some(?f)) { file_path = f; }
|
|
|
|
case (none) { }
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
2011-06-29 17:54:05 -07:00
|
|
|
auto full_path = if (std::fs::path_is_absolute(file_path)) {
|
|
|
|
file_path
|
|
|
|
} else {
|
|
|
|
prefix + std::fs::path_sep() + file_path
|
|
|
|
};
|
2011-06-15 11:19:50 -07:00
|
|
|
if (cx.mode == mode_depend) { cx.deps += [full_path]; ret; }
|
|
|
|
auto p0 =
|
2011-07-05 11:48:19 +02:00
|
|
|
new_parser(cx.sess, cx.cfg, full_path, cx.chpos);
|
2011-06-16 15:31:59 -07:00
|
|
|
auto inner_attrs = parse_inner_attrs_and_next(p0);
|
2011-06-28 18:15:39 -07:00
|
|
|
auto mod_attrs = attrs + inner_attrs._0;
|
2011-06-16 14:59:51 -07:00
|
|
|
auto first_item_outer_attrs = inner_attrs._1;
|
2011-06-19 22:41:21 +02:00
|
|
|
auto m0 = parse_mod_items(p0, token::EOF, first_item_outer_attrs);
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-07-05 11:48:19 +02:00
|
|
|
auto i = syntax::parse::parser::mk_item
|
|
|
|
(p0, cdir.span.lo, cdir.span.hi, id, ast::item_mod(m0),
|
|
|
|
mod_attrs);
|
2011-06-19 22:41:21 +02:00
|
|
|
// Thread defids and chpos through the parsers
|
2011-04-08 18:44:20 +02:00
|
|
|
cx.chpos = p0.get_chpos();
|
2011-05-17 20:41:41 +02:00
|
|
|
vec::push[@ast::item](items, i);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
2011-06-28 18:15:39 -07:00
|
|
|
case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs, ?attrs)) {
|
2011-02-24 15:54:55 -08:00
|
|
|
auto path = id;
|
2011-06-15 11:19:50 -07:00
|
|
|
alt (dir_opt) { case (some(?d)) { path = d; } case (none) { } }
|
2011-06-29 17:54:05 -07:00
|
|
|
auto full_path = if (std::fs::path_is_absolute(path)) {
|
|
|
|
path
|
|
|
|
} else {
|
|
|
|
prefix + std::fs::path_sep() + path
|
|
|
|
};
|
2011-06-30 17:29:54 -07:00
|
|
|
auto m0 = eval_crate_directives_to_mod(cx, cdirs, full_path);
|
2011-06-19 22:41:21 +02:00
|
|
|
auto i = @rec(ident=id,
|
2011-06-28 18:15:39 -07:00
|
|
|
attrs=attrs,
|
2011-07-05 11:48:19 +02:00
|
|
|
id=cx.sess.next_id,
|
2011-06-19 22:41:21 +02:00
|
|
|
node=ast::item_mod(m0),
|
|
|
|
span=cdir.span);
|
2011-07-05 11:48:19 +02:00
|
|
|
cx.sess.next_id += 1;
|
2011-05-17 20:41:41 +02:00
|
|
|
vec::push[@ast::item](items, i);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
2011-05-12 17:24:54 +02:00
|
|
|
case (ast::cdir_view_item(?vi)) {
|
2011-05-17 20:41:41 +02:00
|
|
|
vec::push[@ast::view_item](view_items, vi);
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
2011-06-15 11:19:50 -07:00
|
|
|
case (ast::cdir_syntax(?pth)) { }
|
|
|
|
case (ast::cdir_auth(?pth, ?eff)) { }
|
2011-02-24 15:54:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
2011-03-25 15:07:27 -07:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2011-02-24 15:54:55 -08:00
|
|
|
// End:
|
|
|
|
//
|