diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-28 12:38:53 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-28 13:17:33 -0800 |
| commit | fc06114ddfd2bcdbc4f29076c226a7a1d66ea8d6 (patch) | |
| tree | bd9de2c450f23b8ff0e09130ab59d784ace5b5e3 /src/libsyntax/parse | |
| parent | 669fbddc4435a9ab152332df06a7fcca789c8059 (diff) | |
| parent | 8179e268efd86ae5c1bcf21b4f8d4e01eea7c193 (diff) | |
| download | rust-fc06114ddfd2bcdbc4f29076c226a7a1d66ea8d6.tar.gz rust-fc06114ddfd2bcdbc4f29076c226a7a1d66ea8d6.zip | |
Merge remote-tracking branch 'brson/companion' into incoming
Conflicts: src/compiletest/compiletest.rs src/libcargo/cargo.rs src/libcore/core.rs src/librustc/rustc.rs src/librustdoc/rustdoc.rc
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/eval.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 178 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 285 |
6 files changed, 125 insertions, 411 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 3cb6b08d976..4f7bfb0d4e9 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -20,21 +20,9 @@ enum cmnt_style { } impl cmnt_style : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &cmnt_style) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &cmnt_style) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &cmnt_style) -> bool { - (self as uint) != ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &cmnt_style) -> bool { ((*self) as uint) != ((*other) as uint) } diff --git a/src/libsyntax/parse/eval.rs b/src/libsyntax/parse/eval.rs index 78a47ec09c7..cdfd8a9bcec 100644 --- a/src/libsyntax/parse/eval.rs +++ b/src/libsyntax/parse/eval.rs @@ -5,6 +5,7 @@ use codemap::span; export eval_crate_directives_to_mod; export eval_src_mod; +export eval_src_mod_from_path; type ctx = @{sess: parse::parse_sess, @@ -84,15 +85,23 @@ fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { } } -fn eval_src_mod(cx: ctx, prefix: &Path, id: ast::ident, +fn eval_src_mod(cx: ctx, prefix: &Path, outer_attrs: ~[ast::attribute], - sp: span) -> (ast::item_, ~[ast::attribute]) { + id: ast::ident, sp: span + ) -> (ast::item_, ~[ast::attribute]) { let file_path = Path(cdir_path_opt( cx.sess.interner.get(id) + ~".rs", outer_attrs)); - let full_path = if file_path.is_absolute { - copy file_path + eval_src_mod_from_path(cx, prefix, &file_path, outer_attrs, sp) +} + +fn eval_src_mod_from_path(cx: ctx, prefix: &Path, path: &Path, + outer_attrs: ~[ast::attribute], + sp: span + ) -> (ast::item_, ~[ast::attribute]) { + let full_path = if path.is_absolute { + copy *path } else { - prefix.push_many(file_path.components) + prefix.push_many(path.components) }; let p0 = new_sub_parser_from_file(cx.sess, cx.cfg, @@ -121,7 +130,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path, items: &mut ~[@ast::item]) { match cdir.node { ast::cdir_src_mod(vis, id, attrs) => { - let (m, mod_attrs) = eval_src_mod(cx, prefix, id, attrs, cdir.span); + let (m, mod_attrs) = eval_src_mod(cx, prefix, attrs, id, cdir.span); let i = mk_item(cx, cdir.span.lo, cdir.span.hi, /* FIXME (#2543) */ copy id, m, vis, mod_attrs); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs new file mode 100644 index 00000000000..a7c5f20fedf --- /dev/null +++ b/src/libsyntax/parse/mod.rs @@ -0,0 +1,28 @@ + +#[legacy_exports] +mod lexer; +#[legacy_exports] +mod parser; +#[legacy_exports] +mod token; +#[legacy_exports] +mod comments; +#[legacy_exports] +mod attr; +#[legacy_exports] + +/// Common routines shared by parser mods +#[legacy_exports] +mod common; + +/// Functions dealing with operator precedence +#[legacy_exports] +mod prec; + +/// Routines the parser uses to classify AST nodes +#[legacy_exports] +mod classify; + +/// Reporting obsolete syntax +#[legacy_exports] +mod obsolete; diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index a6a7736e3d0..07ce7f4a268 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -29,21 +29,9 @@ pub enum ObsoleteSyntax { } impl ObsoleteSyntax : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &ObsoleteSyntax) -> bool { - self as uint == (*other) as uint - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &ObsoleteSyntax) -> bool { (*self) as uint == (*other) as uint } - #[cfg(stage0)] - pure fn ne(other: &ObsoleteSyntax) -> bool { - !self.eq(other) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &ObsoleteSyntax) -> bool { !(*self).eq(other) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e4d77e7da09..d95f4fb3f75 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,9 +27,8 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_by_implicit_ref, bind_by_value, bind_by_move, bitand, bitor, bitxor, blk, blk_check_mode, box, by_copy, by_move, by_ref, by_val, capture_clause, - capture_item, cdir_dir_mod, cdir_src_mod, cdir_view_item, - class_immutable, class_mutable, - crate, crate_cfg, crate_directive, decl, decl_item, decl_local, + capture_item, class_immutable, class_mutable, + crate, crate_cfg, decl, decl_item, decl_local, default_blk, deref, div, enum_def, enum_variant_kind, expl, expr, expr_, expr_addr_of, expr_match, expr_again, expr_assert, expr_assign, expr_assign_op, expr_binary, expr_block, expr_break, @@ -2967,17 +2966,10 @@ impl Parser { fn parse_item_mod(outer_attrs: ~[ast::attribute]) -> item_info { let id_span = self.span; let id = self.parse_ident(); - if self.token == token::SEMI { + let info_ = if self.token == token::SEMI { self.bump(); // This mod is in an external file. Let's go get it! - let eval_ctx = @{ - sess: self.sess, - cfg: self.cfg - }; - let prefix = Path(self.sess.cm.span_to_filename(copy self.span)); - let prefix = prefix.dir_path(); - let (m, attrs) = eval::eval_src_mod(eval_ctx, &prefix, id, - outer_attrs, id_span); + let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span); (id, m, Some(move attrs)) } else { self.expect(token::LBRACE); @@ -2985,6 +2977,83 @@ impl Parser { let m = self.parse_mod_items(token::RBRACE, inner_attrs.next); self.expect(token::RBRACE); (id, item_mod(m), Some(inner_attrs.inner)) + }; + + // XXX: Transitionary hack to do the template work inside core + // (int-template, iter-trait). If there's a 'merge' attribute + // on the mod, then we'll go and suck in another file and merge + // its contents + match ::attr::first_attr_value_str_by_name(outer_attrs, ~"merge") { + Some(path) => { + let prefix = Path( + self.sess.cm.span_to_filename(copy self.span)); + let prefix = prefix.dir_path(); + let path = Path(path); + let (new_mod_item, new_attrs) = self.eval_src_mod_from_path( + prefix, path, ~[], id_span); + + let (main_id, main_mod_item, main_attrs) = info_; + let main_attrs = main_attrs.get(); + + let (main_mod, new_mod) = + match (main_mod_item, new_mod_item) { + (item_mod(m), item_mod(n)) => (m, n), + _ => self.bug(~"parsed mod item should be mod") + }; + let merged_mod = { + view_items: main_mod.view_items + new_mod.view_items, + items: main_mod.items + new_mod.items + }; + + let merged_attrs = main_attrs + new_attrs; + (main_id, item_mod(merged_mod), Some(merged_attrs)) + } + None => info_ + } + } + + fn eval_src_mod(id: ast::ident, + outer_attrs: ~[ast::attribute], + id_sp: span) -> (ast::item_, ~[ast::attribute]) { + let prefix = Path(self.sess.cm.span_to_filename(copy self.span)); + let prefix = prefix.dir_path(); + let default_path = self.sess.interner.get(id) + ~".rs"; + let file_path = match ::attr::first_attr_value_str_by_name( + outer_attrs, ~"path") { + + Some(d) => d, + None => default_path + }; + + let file_path = Path(file_path); + self.eval_src_mod_from_path(prefix, file_path, + outer_attrs, id_sp) + } + + fn eval_src_mod_from_path(prefix: Path, path: Path, + outer_attrs: ~[ast::attribute], + id_sp: span + ) -> (ast::item_, ~[ast::attribute]) { + + let full_path = if path.is_absolute { + path + } else { + prefix.push_many(path.components) + }; + let p0 = + new_sub_parser_from_file(self.sess, self.cfg, + &full_path, id_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; + let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); + return (ast::item_mod(m0), mod_attrs); + + fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { + match ::attr::first_attr_value_str_by_name(attrs, ~"path") { + Some(d) => d, + None => default + } } } @@ -3702,8 +3771,7 @@ impl Parser { let first_item_outer_attrs = crate_attrs.next; let m = self.parse_mod_items(token::EOF, first_item_outer_attrs); return @spanned(lo, self.span.lo, - {directives: ~[], - module: m, + {module: m, attrs: crate_attrs.inner, config: self.cfg}); } @@ -3714,94 +3782,12 @@ impl Parser { _ => self.fatal(~"expected string literal") } } - - // Logic for parsing crate files (.rc) - // - // Each crate file is a sequence of directives. - // - // Each directive imperatively extends its environment with 0 or more - // items. - fn parse_crate_directive(first_outer_attr: ~[attribute]) -> - crate_directive { - - // Collect the next attributes - let outer_attrs = vec::append(first_outer_attr, - self.parse_outer_attributes()); - // In a crate file outer attributes are only going to apply to mods - let expect_mod = vec::len(outer_attrs) > 0u; - - let lo = self.span.lo; - let vis = self.parse_visibility(); - if expect_mod || self.is_keyword(~"mod") { - - self.expect_keyword(~"mod"); - - let id = self.parse_ident(); - match self.token { - // mod x = "foo.rs"; - token::SEMI => { - let mut hi = self.span.hi; - self.bump(); - return spanned(lo, hi, cdir_src_mod(vis, id, outer_attrs)); - } - // mod x = "foo_dir" { ...directives... } - token::LBRACE => { - self.bump(); - let inner_attrs = self.parse_inner_attrs_and_next(); - let mod_attrs = vec::append(outer_attrs, inner_attrs.inner); - let next_outer_attr = inner_attrs.next; - let cdirs = self.parse_crate_directives(token::RBRACE, - next_outer_attr); - let mut hi = self.span.hi; - self.expect(token::RBRACE); - return spanned(lo, hi, - cdir_dir_mod(vis, id, cdirs, mod_attrs)); - } - _ => self.unexpected() - } - } else if self.is_view_item() { - let vi = self.parse_view_item(outer_attrs, vis); - return spanned(lo, vi.span.hi, cdir_view_item(vi)); - } - return self.fatal(~"expected crate directive"); - } - - fn parse_crate_directives(term: token::Token, - first_outer_attr: ~[attribute]) -> - ~[@crate_directive] { - - // This is pretty ugly. If we have an outer attribute then we can't - // accept seeing the terminator next, so if we do see it then fail the - // same way parse_crate_directive would - if vec::len(first_outer_attr) > 0u && self.token == term { - self.expect_keyword(~"mod"); - } - - let mut cdirs: ~[@crate_directive] = ~[]; - let mut first_outer_attr = first_outer_attr; - while self.token != term { - let cdir = @self.parse_crate_directive(first_outer_attr); - cdirs.push(cdir); - first_outer_attr = ~[]; - } - return cdirs; - } } impl restriction : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &restriction) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &restriction) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &restriction) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &restriction) -> bool { !(*self).eq(other) } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 7b15f00d761..99c12be4980 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -465,294 +465,13 @@ fn reserved_keyword_table() -> HashMap<~str, ()> { } impl binop : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &binop) -> bool { - (self as uint) == ((*other) as uint) - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &binop) -> bool { ((*self) as uint) == ((*other) as uint) } - #[cfg(stage0)] - pure fn ne(other: &binop) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &binop) -> bool { !(*self).eq(other) } } impl Token : cmp::Eq { - #[cfg(stage0)] - pure fn eq(other: &Token) -> bool { - match self { - EQ => { - match (*other) { - EQ => true, - _ => false - } - } - LT => { - match (*other) { - LT => true, - _ => false - } - } - LE => { - match (*other) { - LE => true, - _ => false - } - } - EQEQ => { - match (*other) { - EQEQ => true, - _ => false - } - } - NE => { - match (*other) { - NE => true, - _ => false - } - } - GE => { - match (*other) { - GE => true, - _ => false - } - } - GT => { - match (*other) { - GT => true, - _ => false - } - } - ANDAND => { - match (*other) { - ANDAND => true, - _ => false - } - } - OROR => { - match (*other) { - OROR => true, - _ => false - } - } - NOT => { - match (*other) { - NOT => true, - _ => false - } - } - TILDE => { - match (*other) { - TILDE => true, - _ => false - } - } - BINOP(e0a) => { - match (*other) { - BINOP(e0b) => e0a == e0b, - _ => false - } - } - BINOPEQ(e0a) => { - match (*other) { - BINOPEQ(e0b) => e0a == e0b, - _ => false - } - } - AT => { - match (*other) { - AT => true, - _ => false - } - } - DOT => { - match (*other) { - DOT => true, - _ => false - } - } - DOTDOT => { - match (*other) { - DOTDOT => true, - _ => false - } - } - ELLIPSIS => { - match (*other) { - ELLIPSIS => true, - _ => false - } - } - COMMA => { - match (*other) { - COMMA => true, - _ => false - } - } - SEMI => { - match (*other) { - SEMI => true, - _ => false - } - } - COLON => { - match (*other) { - COLON => true, - _ => false - } - } - MOD_SEP => { - match (*other) { - MOD_SEP => true, - _ => false - } - } - RARROW => { - match (*other) { - RARROW => true, - _ => false - } - } - LARROW => { - match (*other) { - LARROW => true, - _ => false - } - } - DARROW => { - match (*other) { - DARROW => true, - _ => false - } - } - FAT_ARROW => { - match (*other) { - FAT_ARROW => true, - _ => false - } - } - LPAREN => { - match (*other) { - LPAREN => true, - _ => false - } - } - RPAREN => { - match (*other) { - RPAREN => true, - _ => false - } - } - LBRACKET => { - match (*other) { - LBRACKET => true, - _ => false - } - } - RBRACKET => { - match (*other) { - RBRACKET => true, - _ => false - } - } - LBRACE => { - match (*other) { - LBRACE => true, - _ => false - } - } - RBRACE => { - match (*other) { - RBRACE => true, - _ => false - } - } - POUND => { - match (*other) { - POUND => true, - _ => false - } - } - DOLLAR => { - match (*other) { - DOLLAR => true, - _ => false - } - } - LIT_INT(e0a, e1a) => { - match (*other) { - LIT_INT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - LIT_UINT(e0a, e1a) => { - match (*other) { - LIT_UINT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - LIT_INT_UNSUFFIXED(e0a) => { - match (*other) { - LIT_INT_UNSUFFIXED(e0b) => e0a == e0b, - _ => false - } - } - LIT_FLOAT(e0a, e1a) => { - match (*other) { - LIT_FLOAT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - LIT_FLOAT_UNSUFFIXED(e0a) => { - match (*other) { - LIT_FLOAT_UNSUFFIXED(e0b) => e0a == e0b, - _ => false - } - } - LIT_STR(e0a) => { - match (*other) { - LIT_STR(e0b) => e0a == e0b, - _ => false - } - } - IDENT(e0a, e1a) => { - match (*other) { - IDENT(e0b, e1b) => e0a == e0b && e1a == e1b, - _ => false - } - } - UNDERSCORE => { - match (*other) { - UNDERSCORE => true, - _ => false - } - } - INTERPOLATED(_) => { - match (*other) { - INTERPOLATED(_) => true, - _ => false - } - } - DOC_COMMENT(e0a) => { - match (*other) { - DOC_COMMENT(e0b) => e0a == e0b, - _ => false - } - } - EOF => { - match (*other) { - EOF => true, - _ => false - } - } - } - } - #[cfg(stage1)] - #[cfg(stage2)] pure fn eq(&self, other: &Token) -> bool { match (*self) { EQ => { @@ -1021,10 +740,6 @@ impl Token : cmp::Eq { } } } - #[cfg(stage0)] - pure fn ne(other: &Token) -> bool { !self.eq(other) } - #[cfg(stage1)] - #[cfg(stage2)] pure fn ne(&self, other: &Token) -> bool { !(*self).eq(other) } } |
