diff options
| author | John Clements <clements@racket-lang.org> | 2013-03-06 12:38:13 -0800 |
|---|---|---|
| committer | John Clements <clements@racket-lang.org> | 2013-03-29 10:53:00 -0700 |
| commit | f2e47cddf835af49a925d91639d7fefb8c23d08f (patch) | |
| tree | 62981d328a127ee25ea41164605d41e36acefebf /src/libsyntax/parse | |
| parent | 556143c488f8b8b2ac25ac29efdf030017cba7d7 (diff) | |
| download | rust-f2e47cddf835af49a925d91639d7fefb8c23d08f.tar.gz rust-f2e47cddf835af49a925d91639d7fefb8c23d08f.zip | |
change to parsing using tts
also, updates test cases a bit
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index ba7a9624c18..10d3de4acee 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -94,6 +94,19 @@ pub fn parse_crate_from_file( // why is there no p.abort_if_errors here? } +pub fn parse_crate_from_file_using_tts( + input: &Path, + cfg: ast::crate_cfg, + sess: @mut ParseSess +) -> @ast::crate { + let p = new_parser_from_file(sess, /*bad*/ copy cfg, input); + let tts = p.parse_all_token_trees(); + new_parser_from_tts(sess,cfg,tts).parse_crate_mod(/*bad*/ copy cfg) + // why is there no p.abort_if_errors here? +} + + + pub fn parse_crate_from_source_str( name: ~str, source: @~str, @@ -317,6 +330,7 @@ mod test { use std; use core::io; use core::option::None; + use ast; #[test] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str { do io::with_str_writer |writer| { @@ -324,10 +338,38 @@ mod test { } } + fn string_to_crate (source_str : @~str) -> @ast::crate { + parse_crate_from_source_str( + ~"bogofile", + source_str, + ~[], + new_parse_sess(None)) + } + + fn string_to_tt_to_crate (source_str : @~str) -> @ast::crate { + let tts = parse_tts_from_source_str( + ~"bogofile", + source_str, + ~[], + new_parse_sess(None)); + new_parser_from_tts(new_parse_sess(None),~[],tts) + .parse_crate_mod(~[]) + } + + // make sure that parsing from TTs produces the same result + // as parsing from strings + #[test] fn tts_produce_the_same_result () { + let source_str = @~"fn foo (x : int) { x; }"; + assert_eq!(string_to_tt_to_crate(source_str), + string_to_crate(source_str)); + } + + // check the contents of the tt manually: #[test] fn alltts () { + let source_str = @~"fn foo (x : int) { x; }"; let tts = parse_tts_from_source_str( ~"bogofile", - @~"fn foo (x : int) { x; }", + source_str, ~[], new_parse_sess(None)); assert_eq!( |
