Skip to content

Commit

Permalink
Add parser::parse_crate_from_source_str
Browse files Browse the repository at this point in the history
The fuzzer wants to be able to do stuff like this
  • Loading branch information
brson committed Jul 12, 2011
1 parent 67ecda6 commit e45819a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/comp/syntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,24 @@ fn parse_crate_from_source_file(&str input, &ast::crate_cfg cfg,
&codemap::codemap cm) -> @ast::crate {
auto sess = @rec(cm=cm, mutable next_id=0);
auto p = new_parser_from_file(sess, cfg, input, 0u);
ret parse_crate_mod(p, cfg);
}

fn parse_crate_from_source_str(&str name, &str source, &ast::crate_cfg cfg,
&codemap::codemap cm) -> @ast::crate {
auto sess = @rec(cm=cm, mutable next_id=0);
auto ftype = SOURCE_FILE;
auto filemap = codemap::new_filemap(name, 0u);
sess.cm.files += [filemap];
auto itr = @interner::mk(str::hash, str::eq);
auto rdr = lexer::new_reader(sess.cm, source, filemap, itr);
auto p = new_parser(sess, cfg, rdr, ftype);
ret parse_crate_mod(p, cfg);
}

// Parses a source module as a crate
fn parse_crate_mod(&parser p, &ast::crate_cfg cfg) -> @ast::crate {

auto lo = p.get_lo_pos();
auto crate_attrs = parse_inner_attrs_and_next(p);
auto first_item_outer_attrs = crate_attrs._1;
Expand Down

0 comments on commit e45819a

Please sign in to comment.