2012-01-17 19:44:32 -06:00
|
|
|
#[doc = "AST-parsing helpers"];
|
|
|
|
|
2012-01-26 02:35:07 -06:00
|
|
|
import rustc::driver::driver;
|
|
|
|
import rustc::driver::session;
|
2012-01-16 15:22:25 -06:00
|
|
|
import rustc::driver::diagnostic;
|
|
|
|
import rustc::syntax::ast;
|
|
|
|
import rustc::syntax::codemap;
|
|
|
|
import rustc::syntax::parse::parser;
|
|
|
|
|
2012-01-26 02:35:07 -06:00
|
|
|
export from_file, from_str, from_file_sess, from_str_sess;
|
2012-01-15 16:56:58 -06:00
|
|
|
|
|
|
|
fn new_parse_sess() -> parser::parse_sess {
|
|
|
|
let cm = codemap::new_codemap();
|
2012-01-24 23:42:54 -06:00
|
|
|
let handler = diagnostic::mk_handler(none);
|
2012-01-15 16:56:58 -06:00
|
|
|
let sess = @{
|
|
|
|
cm: cm,
|
2012-01-18 20:35:55 -06:00
|
|
|
mutable next_id: 1,
|
2012-01-24 23:42:54 -06:00
|
|
|
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
|
2012-01-22 18:24:55 -06:00
|
|
|
mutable chpos: 0u,
|
|
|
|
mutable byte_pos: 0u
|
2012-01-15 16:56:58 -06:00
|
|
|
};
|
|
|
|
ret sess;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_file(file: str) -> @ast::crate {
|
2012-01-16 20:28:35 -06:00
|
|
|
parser::parse_crate_from_file(
|
2012-01-15 16:56:58 -06:00
|
|
|
file, [], new_parse_sess())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_str(source: str) -> @ast::crate {
|
|
|
|
parser::parse_crate_from_source_str(
|
2012-01-25 16:53:45 -06:00
|
|
|
"-", @source, [], new_parse_sess())
|
2012-01-15 16:56:58 -06:00
|
|
|
}
|
2012-01-26 02:35:07 -06:00
|
|
|
|
|
|
|
fn from_file_sess(sess: session::session, file: str) -> @ast::crate {
|
|
|
|
parser::parse_crate_from_file(file, cfg(sess), sess.parse_sess)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_str_sess(sess: session::session, source: str) -> @ast::crate {
|
|
|
|
parser::parse_crate_from_source_str(
|
|
|
|
"-", @source, cfg(sess), sess.parse_sess)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cfg(sess: session::session) -> ast::crate_cfg {
|
|
|
|
driver::default_configuration(sess, "rustdoc", "<anon>")
|
|
|
|
}
|