about summary refs log tree commit diff
path: root/src/comp/syntax/parse/parser.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-07-11 17:21:02 -0700
committerBrian Anderson <banderson@mozilla.com>2011-07-11 17:46:24 -0700
commite45819ad70f338b942fda745ef7127bde7c3577a (patch)
tree58bc1a5614c4514d17b307af35ce600992b9d075 /src/comp/syntax/parse/parser.rs
parent67ecda63420a815cb89522be8e83690c38bef118 (diff)
downloadrust-e45819ad70f338b942fda745ef7127bde7c3577a.tar.gz
rust-e45819ad70f338b942fda745ef7127bde7c3577a.zip
Add parser::parse_crate_from_source_str
The fuzzer wants to be able to do stuff like this
Diffstat (limited to 'src/comp/syntax/parse/parser.rs')
-rw-r--r--src/comp/syntax/parse/parser.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 7a1cb6edaed..59b0884704c 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -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;