about summary refs log tree commit diff
path: root/src/libsyntax/util/parser_testing.rs
diff options
context:
space:
mode:
authorJohn Clements <clements@racket-lang.org>2013-05-16 17:42:08 -0700
committerJohn Clements <clements@racket-lang.org>2013-05-20 11:49:21 -0700
commitfc4f304ef9916d691166592b3e49998594535c57 (patch)
tree0ffb6923b5bc5f54e44c8ee254d40bd20759c806 /src/libsyntax/util/parser_testing.rs
parentb621820dc4727677f14bee0ac5e2fa5e424ed22e (diff)
downloadrust-fc4f304ef9916d691166592b3e49998594535c57.tar.gz
rust-fc4f304ef9916d691166592b3e49998594535c57.zip
hygiene infrastructure.
- added a hash table to memoize rename and mark operations.
- added rename, mark, and resolve fold fns
Diffstat (limited to 'src/libsyntax/util/parser_testing.rs')
-rw-r--r--src/libsyntax/util/parser_testing.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs
index 9ab77803576..12c28f096f6 100644
--- a/src/libsyntax/util/parser_testing.rs
+++ b/src/libsyntax/util/parser_testing.rs
@@ -8,22 +8,16 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::serialize::Encodable;
-use std;
-use core::io;
 use core::option::{Option,None};
 use core::int;
 use core::num::NumCast;
-use codemap::{dummy_sp, CodeMap, BytePos, spanned};
-use opt_vec;
+use codemap::CodeMap;
 use ast;
-use abi;
-use ast_util::mk_ident;
 use parse::parser::Parser;
-use parse::token::{ident_interner, mk_ident_interner, mk_fresh_ident_interner};
-use diagnostic::{span_handler, mk_span_handler, mk_handler, Emitter};
+use parse::token::{ident_interner, mk_fresh_ident_interner};
+use diagnostic::{mk_handler, mk_span_handler};
 
-use syntax::parse::{ParseSess,new_parse_sess,string_to_filemap,filemap_to_tts};
+use syntax::parse::{ParseSess,string_to_filemap,filemap_to_tts};
 use syntax::parse::{new_parser_from_source_str};
 
 // add known names to interner for testing
@@ -71,10 +65,15 @@ pub fn string_to_tts_and_sess (source_str : @~str) -> (~[ast::token_tree],@mut P
     (filemap_to_tts(ps,string_to_filemap(ps,source_str,~"bogofile")),ps)
 }
 
+pub fn string_to_parser_and_sess(source_str: @~str) -> (Parser,@mut ParseSess) {
+    let ps = mk_testing_parse_sess();
+    (new_parser_from_source_str(ps,~[],~"bogofile",source_str),ps)
+}
+
 // map string to parser (via tts)
 pub fn string_to_parser(source_str: @~str) -> Parser {
-    let ps = mk_testing_parse_sess();
-    new_parser_from_source_str(ps,~[],~"bogofile",source_str)
+    let (p,_) = string_to_parser_and_sess(source_str);
+    p
 }
 
 pub fn string_to_crate (source_str : @~str) -> @ast::crate {
@@ -86,10 +85,17 @@ pub fn string_to_expr (source_str : @~str) -> @ast::expr {
     string_to_parser(source_str).parse_expr()
 }
 
+// parse a string, return an item
 pub fn string_to_item (source_str : @~str) -> Option<@ast::item> {
     string_to_parser(source_str).parse_item(~[])
 }
 
+// parse a string, return an item and the ParseSess
+pub fn string_to_item_and_sess (source_str : @~str) -> (Option<@ast::item>,@mut ParseSess) {
+    let (p,ps) = string_to_parser_and_sess(source_str);
+    (p.parse_item(~[]),ps)
+}
+
 pub fn string_to_stmt (source_str : @~str) -> @ast::stmt {
     string_to_parser(source_str).parse_stmt(~[])
 }