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