Skip to content

Commit 8bc76e8

Browse files
committed
---
yaml --- r: 54395 b: refs/heads/snap-stage3 c: f2e47cd h: refs/heads/master i: 54393: 20ef8e6 54391: d0c8e14 v: v3
1 parent 4c3f02a commit 8bc76e8

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 556143c488f8b8b2ac25ac29efdf030017cba7d7
4+
refs/heads/snap-stage3: f2e47cddf835af49a925d91639d7fefb8c23d08f
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn parse_input(sess: Session, +cfg: ast::crate_cfg, input: input)
150150
-> @ast::crate {
151151
match input {
152152
file_input(ref file) => {
153-
parse::parse_crate_from_file(&(*file), cfg, sess.parse_sess)
153+
parse::parse_crate_from_file_using_tts(&(*file), cfg, sess.parse_sess)
154154
}
155155
str_input(ref src) => {
156156
// FIXME (#2319): Don't really want to box the source string

branches/snap-stage3/src/libsyntax/parse/mod.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ pub fn parse_crate_from_file(
9494
// why is there no p.abort_if_errors here?
9595
}
9696

97+
pub fn parse_crate_from_file_using_tts(
98+
input: &Path,
99+
cfg: ast::crate_cfg,
100+
sess: @mut ParseSess
101+
) -> @ast::crate {
102+
let p = new_parser_from_file(sess, /*bad*/ copy cfg, input);
103+
let tts = p.parse_all_token_trees();
104+
new_parser_from_tts(sess,cfg,tts).parse_crate_mod(/*bad*/ copy cfg)
105+
// why is there no p.abort_if_errors here?
106+
}
107+
108+
109+
97110
pub fn parse_crate_from_source_str(
98111
name: ~str,
99112
source: @~str,
@@ -317,17 +330,46 @@ mod test {
317330
use std;
318331
use core::io;
319332
use core::option::None;
333+
use ast;
320334

321335
#[test] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str {
322336
do io::with_str_writer |writer| {
323337
val.encode(~std::json::Encoder(writer));
324338
}
325339
}
326340

341+
fn string_to_crate (source_str : @~str) -> @ast::crate {
342+
parse_crate_from_source_str(
343+
~"bogofile",
344+
source_str,
345+
~[],
346+
new_parse_sess(None))
347+
}
348+
349+
fn string_to_tt_to_crate (source_str : @~str) -> @ast::crate {
350+
let tts = parse_tts_from_source_str(
351+
~"bogofile",
352+
source_str,
353+
~[],
354+
new_parse_sess(None));
355+
new_parser_from_tts(new_parse_sess(None),~[],tts)
356+
.parse_crate_mod(~[])
357+
}
358+
359+
// make sure that parsing from TTs produces the same result
360+
// as parsing from strings
361+
#[test] fn tts_produce_the_same_result () {
362+
let source_str = @~"fn foo (x : int) { x; }";
363+
assert_eq!(string_to_tt_to_crate(source_str),
364+
string_to_crate(source_str));
365+
}
366+
367+
// check the contents of the tt manually:
327368
#[test] fn alltts () {
369+
let source_str = @~"fn foo (x : int) { x; }";
328370
let tts = parse_tts_from_source_str(
329371
~"bogofile",
330-
@~"fn foo (x : int) { x; }",
372+
source_str,
331373
~[],
332374
new_parse_sess(None));
333375
assert_eq!(

0 commit comments

Comments
 (0)