diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/grammar/items/mod.rs | 92 | ||||
-rw-r--r-- | src/parser/parser.rs | 6 |
2 files changed, 67 insertions, 31 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 4afe2e418..588fca4c6 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -81,38 +81,74 @@ fn item(p: &mut Parser) { | |||
81 | CONST_ITEM | 81 | CONST_ITEM |
82 | } | 82 | } |
83 | }, | 83 | }, |
84 | // test unsafe_trait | 84 | UNSAFE_KW => { |
85 | // unsafe trait T {} | ||
86 | UNSAFE_KW if la == TRAIT_KW => { | ||
87 | p.bump(); | 85 | p.bump(); |
88 | traits::trait_item(p); | 86 | let la = p.nth(1); |
89 | TRAIT_ITEM | 87 | match p.current() { |
90 | } | 88 | // test unsafe_trait |
89 | // unsafe trait T {} | ||
90 | TRAIT_KW => { | ||
91 | traits::trait_item(p); | ||
92 | TRAIT_ITEM | ||
93 | } | ||
91 | 94 | ||
92 | // test unsafe_auto_trait | 95 | // test unsafe_auto_trait |
93 | // unsafe auto trait T {} | 96 | // unsafe auto trait T {} |
94 | UNSAFE_KW if p.at_kw(1, "auto") && p.nth(2) == TRAIT_KW => { | 97 | IDENT if p.at_kw("auto") && la == TRAIT_KW => { |
95 | p.bump(); | 98 | p.bump_remap(AUTO_KW); |
96 | p.bump_remap(AUTO_KW); | 99 | traits::trait_item(p); |
97 | traits::trait_item(p); | 100 | TRAIT_ITEM |
98 | TRAIT_ITEM | 101 | } |
99 | } | ||
100 | 102 | ||
101 | // test unsafe_impl | 103 | // test unsafe_impl |
102 | // unsafe impl Foo {} | 104 | // unsafe impl Foo {} |
103 | UNSAFE_KW if la == IMPL_KW => { | 105 | IMPL_KW => { |
104 | p.bump(); | 106 | traits::impl_item(p); |
105 | traits::impl_item(p); | 107 | IMPL_ITEM |
106 | IMPL_ITEM | 108 | } |
107 | } | ||
108 | 109 | ||
109 | // test unsafe_default_impl | 110 | // test unsafe_default_impl |
110 | // unsafe default impl Foo {} | 111 | // unsafe default impl Foo {} |
111 | UNSAFE_KW if p.at_kw(1, "default") && p.nth(2) == IMPL_KW => { | 112 | IDENT if p.at_kw("default") && la == IMPL_KW => { |
112 | p.bump(); | 113 | p.bump_remap(DEFAULT_KW); |
113 | p.bump_remap(DEFAULT_KW); | 114 | traits::impl_item(p); |
114 | traits::impl_item(p); | 115 | IMPL_ITEM |
115 | IMPL_ITEM | 116 | } |
117 | |||
118 | // test unsafe_extern_fn | ||
119 | // unsafe extern "C" fn foo() {} | ||
120 | EXTERN_KW => { | ||
121 | abi(p); | ||
122 | if !p.at(FN_KW) { | ||
123 | item.abandon(p); | ||
124 | p.error().message("expected function").emit(); | ||
125 | return | ||
126 | } | ||
127 | fn_item(p); | ||
128 | FN_ITEM | ||
129 | } | ||
130 | |||
131 | // test unsafe_fn | ||
132 | // unsafe fn foo() {} | ||
133 | FN_KW => { | ||
134 | fn_item(p); | ||
135 | FN_ITEM | ||
136 | } | ||
137 | |||
138 | t => { | ||
139 | item.abandon(p); | ||
140 | let message = "expected `trait`, `impl` or `fn`"; | ||
141 | |||
142 | // test unsafe_block_in_mod | ||
143 | // fn foo(){} unsafe { } fn bar(){} | ||
144 | if t == L_CURLY { | ||
145 | error_block(p, message); | ||
146 | } else { | ||
147 | p.error().message(message).emit(); | ||
148 | } | ||
149 | return; | ||
150 | } | ||
151 | } | ||
116 | } | 152 | } |
117 | 153 | ||
118 | MOD_KW => { | 154 | MOD_KW => { |
diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 7e1b22ee5..53a116fb7 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use super::Event; | 1 | use super::Event; |
2 | use super::input::{InputPosition, ParserInput}; | 2 | use super::input::{InputPosition, ParserInput}; |
3 | use SyntaxKind::{self, EOF, TOMBSTONE, IDENT}; | 3 | use SyntaxKind::{self, EOF, TOMBSTONE}; |
4 | 4 | ||
5 | pub(crate) struct Marker { | 5 | pub(crate) struct Marker { |
6 | pos: u32, | 6 | pos: u32, |
@@ -161,8 +161,8 @@ impl<'t> Parser<'t> { | |||
161 | self.inp.kind(self.pos + n) | 161 | self.inp.kind(self.pos + n) |
162 | } | 162 | } |
163 | 163 | ||
164 | pub(crate) fn at_kw(&self, n: u32, t: &str) -> bool { | 164 | pub(crate) fn at_kw(&self, t: &str) -> bool { |
165 | self.nth(n) == IDENT && self.inp.text(self.pos + n) == t | 165 | self.inp.text(self.pos) == t |
166 | } | 166 | } |
167 | 167 | ||
168 | pub(crate) fn current(&self) -> SyntaxKind { | 168 | pub(crate) fn current(&self) -> SyntaxKind { |