diff options
-rw-r--r-- | grammar.ron | 2 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 18 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items/traits.rs | 17 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 4 | ||||
-rw-r--r-- | tests/data/parser/inline/0007_unsafe_trait.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0007_unsafe_trait.txt | 11 | ||||
-rw-r--r-- | tests/data/parser/inline/0008_unsafe_impl.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0008_unsafe_impl.txt | 11 | ||||
-rw-r--r-- | tools/src/bin/collect-tests.rs | 15 |
9 files changed, 74 insertions, 6 deletions
diff --git a/grammar.ron b/grammar.ron index 0717b7a76..c2fcc44f5 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -91,6 +91,8 @@ Grammar( | |||
91 | "USE_ITEM", | 91 | "USE_ITEM", |
92 | "STATIC_ITEM", | 92 | "STATIC_ITEM", |
93 | "CONST_ITEM", | 93 | "CONST_ITEM", |
94 | "TRAIT_ITEM", | ||
95 | "IMPL_ITEM", | ||
94 | 96 | ||
95 | "EXTERN_BLOCK", | 97 | "EXTERN_BLOCK", |
96 | "ENUM_VARIANT", | 98 | "ENUM_VARIANT", |
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 6d6fabbd7..3612802e1 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs | |||
@@ -3,6 +3,7 @@ use super::*; | |||
3 | mod structs; | 3 | mod structs; |
4 | mod use_item; | 4 | mod use_item; |
5 | mod consts; | 5 | mod consts; |
6 | mod traits; | ||
6 | 7 | ||
7 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { | 8 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { |
8 | attributes::inner_attributes(p); | 9 | attributes::inner_attributes(p); |
@@ -80,6 +81,22 @@ fn item(p: &mut Parser) { | |||
80 | CONST_ITEM | 81 | CONST_ITEM |
81 | } | 82 | } |
82 | }, | 83 | }, |
84 | // TODO: auto trait | ||
85 | // test unsafe_trait | ||
86 | // unsafe trait T {} | ||
87 | UNSAFE_KW if la == TRAIT_KW => { | ||
88 | p.bump(); | ||
89 | traits::trait_item(p); | ||
90 | TRAIT_ITEM | ||
91 | } | ||
92 | // TODO: default impl | ||
93 | // test unsafe_impl | ||
94 | // unsafe impl Foo {} | ||
95 | UNSAFE_KW if la == IMPL_KW => { | ||
96 | p.bump(); | ||
97 | traits::impl_item(p); | ||
98 | IMPL_ITEM | ||
99 | } | ||
83 | MOD_KW => { | 100 | MOD_KW => { |
84 | mod_item(p); | 101 | mod_item(p); |
85 | MOD_ITEM | 102 | MOD_ITEM |
@@ -131,6 +148,7 @@ fn extern_block(p: &mut Parser) { | |||
131 | p.bump(); | 148 | p.bump(); |
132 | p.expect(R_CURLY); | 149 | p.expect(R_CURLY); |
133 | } | 150 | } |
151 | |||
134 | fn mod_item(p: &mut Parser) { | 152 | fn mod_item(p: &mut Parser) { |
135 | assert!(p.at(MOD_KW)); | 153 | assert!(p.at(MOD_KW)); |
136 | p.bump(); | 154 | p.bump(); |
diff --git a/src/parser/event_parser/grammar/items/traits.rs b/src/parser/event_parser/grammar/items/traits.rs new file mode 100644 index 000000000..3bef9639f --- /dev/null +++ b/src/parser/event_parser/grammar/items/traits.rs | |||
@@ -0,0 +1,17 @@ | |||
1 | use super::*; | ||
2 | |||
3 | pub(super) fn trait_item(p: &mut Parser) { | ||
4 | assert!(p.at(TRAIT_KW)); | ||
5 | p.bump(); | ||
6 | p.expect(IDENT); | ||
7 | p.expect(L_CURLY); | ||
8 | p.expect(R_CURLY); | ||
9 | } | ||
10 | |||
11 | pub(super) fn impl_item(p: &mut Parser) { | ||
12 | assert!(p.at(IMPL_KW)); | ||
13 | p.bump(); | ||
14 | p.expect(IDENT); | ||
15 | p.expect(L_CURLY); | ||
16 | p.expect(R_CURLY); | ||
17 | } | ||
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index c182aea78..22c615831 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -92,6 +92,8 @@ pub enum SyntaxKind { | |||
92 | USE_ITEM, | 92 | USE_ITEM, |
93 | STATIC_ITEM, | 93 | STATIC_ITEM, |
94 | CONST_ITEM, | 94 | CONST_ITEM, |
95 | TRAIT_ITEM, | ||
96 | IMPL_ITEM, | ||
95 | EXTERN_BLOCK, | 97 | EXTERN_BLOCK, |
96 | ENUM_VARIANT, | 98 | ENUM_VARIANT, |
97 | NAMED_FIELD, | 99 | NAMED_FIELD, |
@@ -207,6 +209,8 @@ impl SyntaxKind { | |||
207 | USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, | 209 | USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, |
208 | STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, | 210 | STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" }, |
209 | CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, | 211 | CONST_ITEM => &SyntaxInfo { name: "CONST_ITEM" }, |
212 | TRAIT_ITEM => &SyntaxInfo { name: "TRAIT_ITEM" }, | ||
213 | IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" }, | ||
210 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 214 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
211 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 215 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
212 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 216 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
diff --git a/tests/data/parser/inline/0007_unsafe_trait.rs b/tests/data/parser/inline/0007_unsafe_trait.rs new file mode 100644 index 000000000..04e021550 --- /dev/null +++ b/tests/data/parser/inline/0007_unsafe_trait.rs | |||
@@ -0,0 +1 @@ | |||
unsafe trait T {} | |||
diff --git a/tests/data/parser/inline/0007_unsafe_trait.txt b/tests/data/parser/inline/0007_unsafe_trait.txt new file mode 100644 index 000000000..d6f6a4cfa --- /dev/null +++ b/tests/data/parser/inline/0007_unsafe_trait.txt | |||
@@ -0,0 +1,11 @@ | |||
1 | FILE@[0; 18) | ||
2 | TRAIT_ITEM@[0; 18) | ||
3 | UNSAFE_KW@[0; 6) | ||
4 | WHITESPACE@[6; 7) | ||
5 | TRAIT_KW@[7; 12) | ||
6 | WHITESPACE@[12; 13) | ||
7 | IDENT@[13; 14) "T" | ||
8 | WHITESPACE@[14; 15) | ||
9 | L_CURLY@[15; 16) | ||
10 | R_CURLY@[16; 17) | ||
11 | WHITESPACE@[17; 18) | ||
diff --git a/tests/data/parser/inline/0008_unsafe_impl.rs b/tests/data/parser/inline/0008_unsafe_impl.rs new file mode 100644 index 000000000..41055f41d --- /dev/null +++ b/tests/data/parser/inline/0008_unsafe_impl.rs | |||
@@ -0,0 +1 @@ | |||
unsafe impl Foo {} | |||
diff --git a/tests/data/parser/inline/0008_unsafe_impl.txt b/tests/data/parser/inline/0008_unsafe_impl.txt new file mode 100644 index 000000000..a88a447cb --- /dev/null +++ b/tests/data/parser/inline/0008_unsafe_impl.txt | |||
@@ -0,0 +1,11 @@ | |||
1 | FILE@[0; 19) | ||
2 | IMPL_ITEM@[0; 19) | ||
3 | UNSAFE_KW@[0; 6) | ||
4 | WHITESPACE@[6; 7) | ||
5 | IMPL_KW@[7; 11) | ||
6 | WHITESPACE@[11; 12) | ||
7 | IDENT@[12; 15) "Foo" | ||
8 | WHITESPACE@[15; 16) | ||
9 | L_CURLY@[16; 17) | ||
10 | R_CURLY@[17; 18) | ||
11 | WHITESPACE@[18; 19) | ||
diff --git a/tools/src/bin/collect-tests.rs b/tools/src/bin/collect-tests.rs index df9d2db81..9a84d92fc 100644 --- a/tools/src/bin/collect-tests.rs +++ b/tools/src/bin/collect-tests.rs | |||
@@ -79,16 +79,19 @@ fn collect_tests(s: &str) -> Vec<Test> { | |||
79 | .map(str::trim_left) | 79 | .map(str::trim_left) |
80 | .group_by(|line| line.starts_with(prefix)); | 80 | .group_by(|line| line.starts_with(prefix)); |
81 | 81 | ||
82 | for (is_comment, block) in comment_blocks.into_iter() { | 82 | 'outer: for (is_comment, block) in comment_blocks.into_iter() { |
83 | if !is_comment { | 83 | if !is_comment { |
84 | continue; | 84 | continue; |
85 | } | 85 | } |
86 | let mut block = block.map(|line| &line[prefix.len()..]); | 86 | let mut block = block.map(|line| &line[prefix.len()..]); |
87 | let first = block.next().unwrap(); | 87 | |
88 | if !first.starts_with("test ") { | 88 | let name = loop { |
89 | continue; | 89 | match block.next() { |
90 | } | 90 | Some(line) if line.starts_with("test ") => break line["test ".len()..].to_string(), |
91 | let name = first["test ".len()..].to_string(); | 91 | Some(_) => (), |
92 | None => continue 'outer, | ||
93 | } | ||
94 | }; | ||
92 | let text: String = itertools::join(block.chain(::std::iter::once("")), "\n"); | 95 | let text: String = itertools::join(block.chain(::std::iter::once("")), "\n"); |
93 | assert!(!text.trim().is_empty() && text.ends_with("\n")); | 96 | assert!(!text.trim().is_empty() && text.ends_with("\n")); |
94 | res.push(Test { name, text }) | 97 | res.push(Test { name, text }) |