diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-07-11 15:00:40 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-07-17 15:46:43 -0700 |
| commit | db020ab63cd51dd4a25cba2d00117f016128762b (patch) | |
| tree | 2b6f1e99ba4356f3e3bf5338332c278d2a85109b /src/libsyntax/parse | |
| parent | b5729bd60095fb5ca884936775e031cf19900760 (diff) | |
| download | rust-db020ab63cd51dd4a25cba2d00117f016128762b.tar.gz rust-db020ab63cd51dd4a25cba2d00117f016128762b.zip | |
rustc: Implement and enforce instance coherence
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/common.rs | 39 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 7 |
4 files changed, 70 insertions, 9 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 995feff0b70..fb28f952629 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -9,7 +9,21 @@ export parser_attr; // extensions, which both begin with token.POUND type attr_or_ext = option<either<~[ast::attribute], @ast::expr>>; -impl parser_attr for parser { +trait parser_attr { + fn parse_outer_attrs_or_ext(first_item_attrs: ~[ast::attribute]) + -> attr_or_ext; + fn parse_outer_attributes() -> ~[ast::attribute]; + fn parse_attribute(style: ast::attr_style) -> ast::attribute; + fn parse_attribute_naked(style: ast::attr_style, lo: uint) -> + ast::attribute; + fn parse_inner_attrs_and_next() -> + {inner: ~[ast::attribute], next: ~[ast::attribute]}; + fn parse_meta_item() -> @ast::meta_item; + fn parse_meta_seq() -> ~[@ast::meta_item]; + fn parse_optional_meta() -> ~[@ast::meta_item]; +} + +impl parser_attr of parser_attr for parser { fn parse_outer_attrs_or_ext(first_item_attrs: ~[ast::attribute]) -> attr_or_ext diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 79ac3aeaf8b..9126bbb3be4 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -22,9 +22,44 @@ fn token_to_str(reader: reader, ++token: token::token) -> ~str { token::to_str(*reader.interner(), token) } -// This should be done with traits, once traits work -impl parser_common for parser { +trait parser_common { + fn unexpected_last(t: token::token) -> !; + fn unexpected() -> !; + fn expect(t: token::token); + fn parse_ident() -> ast::ident; + fn parse_path_list_ident() -> ast::path_list_ident; + fn parse_value_ident() -> ast::ident; + fn eat(tok: token::token) -> bool; + // A sanity check that the word we are asking for is a known keyword + fn require_keyword(word: ~str); + fn token_is_keyword(word: ~str, ++tok: token::token) -> bool; + fn is_keyword(word: ~str) -> bool; + fn is_any_keyword(tok: token::token) -> bool; + fn eat_keyword(word: ~str) -> bool; + fn expect_keyword(word: ~str); + fn is_restricted_keyword(word: ~str) -> bool; + fn check_restricted_keywords(); + fn check_restricted_keywords_(w: ~str); + fn expect_gt(); + fn parse_seq_to_before_gt<T: copy>(sep: option<token::token>, + f: fn(parser) -> T) -> ~[T]; + fn parse_seq_to_gt<T: copy>(sep: option<token::token>, + f: fn(parser) -> T) -> ~[T]; + fn parse_seq_lt_gt<T: copy>(sep: option<token::token>, + f: fn(parser) -> T) -> spanned<~[T]>; + fn parse_seq_to_end<T: copy>(ket: token::token, sep: seq_sep, + f: fn(parser) -> T) -> ~[T]; + fn parse_seq_to_before_end<T: copy>(ket: token::token, sep: seq_sep, + f: fn(parser) -> T) -> ~[T]; + fn parse_unspanned_seq<T: copy>(bra: token::token, + ket: token::token, + sep: seq_sep, + f: fn(parser) -> T) -> ~[T]; + fn parse_seq<T: copy>(bra: token::token, ket: token::token, sep: seq_sep, + f: fn(parser) -> T) -> spanned<~[T]>; +} +impl parser_common of parser_common for parser { fn unexpected_last(t: token::token) -> ! { self.span_fatal( copy self.last_span, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 74210f74d4d..c7687bf2b98 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2188,14 +2188,23 @@ class parser { } } + fn token_is_pound_or_doc_comment(++tok: token::token) -> bool { + alt tok { + token::POUND | token::DOC_COMMENT(_) { true } + _ { false } + } + } + fn parse_single_class_item(vis: visibility) -> @class_member { - if self.eat_keyword(~"let") { + if (self.eat_keyword(~"let") || + self.token_is_keyword(~"mut", copy self.token) || + !self.is_any_keyword(copy self.token)) && + !self.token_is_pound_or_doc_comment(self.token) { let a_var = self.parse_instance_var(vis); self.expect(token::SEMI); ret a_var; - } - else { + } else { let m = self.parse_method(vis); ret @{node: class_method(m), span: m.span}; } @@ -2510,7 +2519,7 @@ class parser { self.parse_item_trait() } else if self.eat_keyword(~"impl") { self.parse_item_impl() - } else if self.eat_keyword(~"class") { + } else if self.eat_keyword(~"class") || self.eat_keyword(~"struct") { self.parse_item_class() } else if !self.is_any_keyword(copy self.token) && self.look_ahead(1) == token::NOT diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 949b078d8f0..a39b74eaca3 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -313,8 +313,11 @@ fn restricted_keyword_table() -> hashmap<~str, ()> { ~"if", ~"iface", ~"impl", ~"import", ~"let", ~"log", ~"loop", ~"mod", ~"mut", - ~"new", ~"owned", - ~"pure", ~"ret", + ~"new", + ~"owned", + ~"pure", + ~"ret", + ~"struct", ~"true", ~"trait", ~"type", ~"unchecked", ~"unsafe", ~"while" |
