Skip to content

Commit

Permalink
change to parsing using tts
Browse files Browse the repository at this point in the history
also, updates test cases a bit
  • Loading branch information
jbclements committed Mar 29, 2013
1 parent 556143c commit f2e47cd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn parse_input(sess: Session, +cfg: ast::crate_cfg, input: input)
-> @ast::crate {
match input {
file_input(ref file) => {
parse::parse_crate_from_file(&(*file), cfg, sess.parse_sess)
parse::parse_crate_from_file_using_tts(&(*file), cfg, sess.parse_sess)
}
str_input(ref src) => {
// FIXME (#2319): Don't really want to box the source string
Expand Down
44 changes: 43 additions & 1 deletion src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -317,17 +330,46 @@ 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| {
val.encode(~std::json::Encoder(writer));
}
}

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!(
Expand Down

5 comments on commit f2e47cd

@bors
Copy link
Contributor

@bors bors commented on f2e47cd Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jbclements
at jbclements@f2e47cd

@bors
Copy link
Contributor

@bors bors commented on f2e47cd Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jbclements/rust/change-to-tt-based-parsing = f2e47cd into auto

@bors
Copy link
Contributor

@bors bors commented on f2e47cd Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jbclements/rust/change-to-tt-based-parsing = f2e47cd merged ok, testing candidate = 6153aae

@bors
Copy link
Contributor

@bors bors commented on f2e47cd Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f2e47cd Apr 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 6153aae

Please sign in to comment.