Remove unused file_type enum from the parser

This commit is contained in:
Brian Anderson 2012-11-18 15:55:03 -08:00
parent 74b2e99797
commit 371be3c6c4
8 changed files with 24 additions and 38 deletions

View File

@ -37,7 +37,7 @@ use codemap::span;
use ext::base::ext_ctxt;
use ast::tt_delim;
use parse::lexer::{new_tt_reader, reader};
use parse::parser::{Parser, SOURCE_FILE};
use parse::parser::Parser;
use parse::common::parser_common;
use pipes::parse_proto::proto_parser;
@ -52,7 +52,7 @@ fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, None, tt);
let rdr = tt_rdr as reader;
let rust_parser = Parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let rust_parser = Parser(sess, cfg, rdr.dup());
let proto = rust_parser.parse_proto(cx.str_of(id));

View File

@ -60,8 +60,7 @@ fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let file = expr_to_str(cx, args[0], ~"include_str! requires a string");
let p = parse::new_sub_parser_from_file(
cx.parse_sess(), cx.cfg(),
&res_rel_file(cx, sp, &Path(file)),
parse::parser::SOURCE_FILE, sp);
&res_rel_file(cx, sp, &Path(file)), sp);
return p.parse_expr();
}

View File

@ -2,7 +2,7 @@ use codemap::span;
use ext::base::ext_ctxt;
use ast::tt_delim;
use parse::lexer::{new_tt_reader, reader};
use parse::parser::{Parser, SOURCE_FILE};
use parse::parser::Parser;
use parse::common::parser_common;
fn expand_trace_macros(cx: ext_ctxt, sp: span,
@ -13,7 +13,7 @@ fn expand_trace_macros(cx: ext_ctxt, sp: span,
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, None, tt);
let rdr = tt_rdr as reader;
let rust_parser = Parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let rust_parser = Parser(sess, cfg, rdr.dup());
let arg = cx.str_of(rust_parser.parse_ident());
match arg {
@ -21,7 +21,7 @@ fn expand_trace_macros(cx: ext_ctxt, sp: span,
~"false" => cx.set_trace_macros(false),
_ => cx.span_fatal(sp, ~"trace_macros! only accepts `true` or `false`")
}
let rust_parser = Parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let rust_parser = Parser(sess, cfg, rdr.dup());
let result = rust_parser.parse_expr();
base::mr_expr(result)
}

View File

@ -3,7 +3,7 @@ use parse::token;
use parse::token::{Token, EOF, to_str, nonterminal};
use parse::lexer::*; //resolve bug?
//import parse::lexer::{reader, tt_reader, tt_reader_as_reader};
use parse::parser::{Parser, SOURCE_FILE};
use parse::parser::Parser;
//import parse::common::parser_common;
use parse::common::*; //resolve bug?
use parse::parse_sess;
@ -355,7 +355,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
}
rdr.next_token();
} else /* bb_eis.len() == 1 */ {
let rust_parser = Parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let rust_parser = Parser(sess, cfg, rdr.dup());
let ei = bb_eis.pop();
match ei.elts[ei.idx].node {

View File

@ -4,7 +4,7 @@ use ast::{ident, matcher_, matcher, match_tok,
match_nonterminal, match_seq, tt_delim};
use parse::lexer::{new_tt_reader, reader};
use parse::token::{FAT_ARROW, SEMI, LBRACE, RBRACE, nt_matchers, nt_tt};
use parse::parser::{Parser, SOURCE_FILE};
use parse::parser::Parser;
use macro_parser::{parse, parse_or_else, success, failure, named_match,
matched_seq, matched_nonterminal, error};
use std::map::HashMap;
@ -88,7 +88,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
let trncbr = new_tt_reader(s_d, itr, Some(named_matches),
~[rhs]);
let p = Parser(cx.parse_sess(), cx.cfg(),
trncbr as reader, SOURCE_FILE);
trncbr as reader);
let e = p.parse_expr();
return mr_expr(e);
}

View File

@ -62,8 +62,7 @@ fn parse_crate_from_file(input: &Path, cfg: ast::crate_cfg,
fn parse_crate_from_crate_file(input: &Path, cfg: ast::crate_cfg,
sess: parse_sess) -> @ast::crate {
let p = new_crate_parser_from_file(sess, cfg, input,
parser::CRATE_FILE);
let p = new_crate_parser_from_file(sess, cfg, input);
let lo = p.span.lo;
let prefix = input.dir_path();
let leading_attrs = p.parse_inner_attrs_and_next();
@ -85,8 +84,7 @@ fn parse_crate_from_crate_file(input: &Path, cfg: ast::crate_cfg,
fn parse_crate_from_source_file(input: &Path, cfg: ast::crate_cfg,
sess: parse_sess) -> @ast::crate {
let p = new_crate_parser_from_file(sess, cfg, input,
parser::SOURCE_FILE);
let p = new_crate_parser_from_file(sess, cfg, input);
let r = p.parse_crate_mod(cfg);
return r;
}
@ -156,23 +154,21 @@ fn next_node_id(sess: parse_sess) -> node_id {
fn new_parser_from_source_str(sess: parse_sess, cfg: ast::crate_cfg,
+name: ~str, +ss: codemap::FileSubstr,
source: @~str) -> Parser {
let ftype = parser::SOURCE_FILE;
let filemap = sess.cm.new_filemap_w_substr(name, ss, source);
let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap,
sess.interner);
return Parser(sess, cfg, srdr as reader, ftype);
return Parser(sess, cfg, srdr as reader);
}
fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg,
path: &Path,
ftype: parser::file_type) -> Result<Parser, ~str> {
path: &Path) -> Result<Parser, ~str> {
match io::read_whole_file_str(path) {
result::Ok(move src) => {
let filemap = sess.cm.new_filemap(path.to_str(), @move src);
let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap,
sess.interner);
Ok(Parser(sess, cfg, srdr as reader, ftype))
Ok(Parser(sess, cfg, srdr as reader))
}
result::Err(move e) => Err(move e)
@ -182,9 +178,8 @@ fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg,
/// Create a new parser for an entire crate, handling errors as appropriate
/// if the file doesn't exist
fn new_crate_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg,
path: &Path,
ftype: parser::file_type) -> Parser {
match new_parser_from_file(sess, cfg, path, ftype) {
path: &Path) -> Parser {
match new_parser_from_file(sess, cfg, path) {
Ok(move parser) => move parser,
Err(move e) => {
sess.span_diagnostic.handler().fatal(e)
@ -195,9 +190,8 @@ fn new_crate_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg,
/// Create a new parser based on a span from an existing parser. Handles
/// error messages correctly when the file does not exist.
fn new_sub_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg,
path: &Path, ftype: parser::file_type,
sp: span) -> Parser {
match new_parser_from_file(sess, cfg, path, ftype) {
path: &Path, sp: span) -> Parser {
match new_parser_from_file(sess, cfg, path) {
Ok(move parser) => move parser,
Err(move e) => {
sess.span_diagnostic.span_fatal(sp, e)
@ -209,5 +203,5 @@ fn new_parser_from_tt(sess: parse_sess, cfg: ast::crate_cfg,
tt: ~[ast::token_tree]) -> Parser {
let trdr = lexer::new_tt_reader(sess.span_diagnostic, sess.interner,
None, tt);
return Parser(sess, cfg, trdr as reader, parser::SOURCE_FILE)
return Parser(sess, cfg, trdr as reader)
}

View File

@ -1,4 +1,4 @@
use parser::{Parser, SOURCE_FILE};
use parser::Parser;
use attr::parser_attr;
use ast_util::mk_sp;
use codemap::span;
@ -67,7 +67,7 @@ fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &Option<Path>)
debug!("found companion mod");
// XXX: Using a dummy span, but this code will go away soon
let p0 = new_sub_parser_from_file(cx.sess, cx.cfg,
modpath, SOURCE_FILE,
modpath,
ast_util::dummy_sp());
let inner_attrs = p0.parse_inner_attrs_and_next();
let m0 = p0.parse_mod_items(token::EOF, inner_attrs.next);
@ -96,7 +96,7 @@ fn eval_src_mod(cx: ctx, prefix: &Path, id: ast::ident,
};
let p0 =
new_sub_parser_from_file(cx.sess, cx.cfg,
&full_path, SOURCE_FILE, sp);
&full_path, sp);
let inner_attrs = p0.parse_inner_attrs_and_next();
let mod_attrs = vec::append(outer_attrs, inner_attrs.inner);
let first_item_outer_attrs = inner_attrs.next;

View File

@ -70,10 +70,7 @@ use ast::{_mod, add, arg, arm, attribute,
expr_vstore_fixed, expr_vstore_slice, expr_vstore_box,
expr_vstore_uniq, TyFn, Onceness, Once, Many};
export file_type;
export Parser;
export CRATE_FILE;
export SOURCE_FILE;
// FIXME (#3726): #ast expects to find this here but it's actually
// defined in `parse` Fixing this will be easier when we have export
@ -92,8 +89,6 @@ enum restriction {
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
}
enum file_type { CRATE_FILE, SOURCE_FILE, }
enum class_member {
field_member(@struct_field),
method_member(@method)
@ -180,7 +175,7 @@ pure fn maybe_append(+lhs: ~[attribute], rhs: Option<~[attribute]>)
/* ident is handled by common.rs */
fn Parser(sess: parse_sess, cfg: ast::crate_cfg,
+rdr: reader, ftype: file_type) -> Parser {
+rdr: reader) -> Parser {
let tok0 = rdr.next_token();
let span0 = tok0.sp;
@ -191,7 +186,6 @@ fn Parser(sess: parse_sess, cfg: ast::crate_cfg,
interner: move interner,
sess: sess,
cfg: cfg,
file_type: ftype,
token: tok0.tok,
span: span0,
last_span: span0,
@ -210,7 +204,6 @@ fn Parser(sess: parse_sess, cfg: ast::crate_cfg,
struct Parser {
sess: parse_sess,
cfg: crate_cfg,
file_type: file_type,
mut token: token::Token,
mut span: span,
mut last_span: span,