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