2012-01-17 17:44:32 -08:00
|
|
|
#[doc = "AST-parsing helpers"];
|
|
|
|
|
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-15 14:56:58 -08:00
|
|
|
export from_file, from_str;
|
|
|
|
|
|
|
|
fn new_parse_sess() -> parser::parse_sess {
|
|
|
|
let cm = codemap::new_codemap();
|
|
|
|
let sess = @{
|
|
|
|
cm: cm,
|
2012-01-18 18:35:55 -08:00
|
|
|
mutable next_id: 1,
|
2012-01-22 17:24:55 -07:00
|
|
|
diagnostic: diagnostic::mk_handler(cm, none),
|
|
|
|
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(
|
|
|
|
"-", source, [], new_parse_sess())
|
|
|
|
}
|