MCPcopy Create free account
hub / github.com/Voxon-Development/zeta-lang / parse_interface_decl

Method parse_interface_decl

scribe-parser/src/parser/declarations.rs:289–357  ·  view source on GitHub ↗

Parse an interface declaration (like Rust trait) ```ignore interface Drawable { fn draw(&this); } sealed interface SealedTrait permits A, B, C { fn method(&this); } ```

(
        &mut self,
        visibility: Visibility,
        is_sealed: bool,
    )

Source from the content-addressed store, hash-verified

287 /// }
288 /// ```
289 pub fn parse_interface_decl(
290 &mut self,
291 visibility: Visibility,
292 is_sealed: bool,
293 ) -> Result<Stmt<'a, 'bump>, DiagnosticError<'a>> {
294 let token = self.cursor.expect(TokenKind::Interface)?;
295
296 let (name, _span) = self.cursor.expect_ident()?;
297
298 // Parse optional generics: <T, U: Display>
299 let generics = if self.cursor.peek() == TokenKind::Lt {
300 self.parse_generics()?
301 } else {
302 None
303 };
304
305 // Parse optional permits clause for sealed interfaces
306 let permits = if self.cursor.peek() == TokenKind::Permits {
307 Some(self.parse_permits_expr()?)
308 } else {
309 None
310 };
311
312 self.cursor.expect(TokenKind::LBrace)?;
313
314 let mut methods = Vec::new();
315
316 while self.cursor.peek() != TokenKind::RBrace && self.cursor.peek() != TokenKind::EOF {
317 let method_vis = if self.cursor.peek() == TokenKind::Private
318 || self.cursor.peek() == TokenKind::Module
319 || self.cursor.peek() == TokenKind::Package
320 {
321 let vis = token_to_visibility(self.cursor.peek());
322 self.cursor.advance();
323 vis
324 } else {
325 Visibility::Public
326 };
327
328 if matches!(
329 self.cursor.peek(),
330 TokenKind::Func
331 | TokenKind::Unsafe
332 | TokenKind::Inline
333 | TokenKind::Noinline
334 | TokenKind::Extern
335 ) {
336 let func = self.parse_function_signature(method_vis)?;
337 methods.push(func);
338 } else {
339 // Interface can also have associated types, consts, etc.
340 // For now, just skip unknown tokens
341 self.cursor.advance();
342 }
343 }
344
345 self.cursor.expect(TokenKind::RBrace)?;
346

Callers 1

parse_stmtMethod · 0.80

Calls 12

InterfaceDeclClass · 0.85
expectMethod · 0.80
expect_identMethod · 0.80
peekMethod · 0.80
parse_genericsMethod · 0.80
parse_permits_exprMethod · 0.80
advanceMethod · 0.80
is_emptyMethod · 0.80
alloc_slice_copyMethod · 0.80
token_to_visibilityFunction · 0.70
alloc_value_immutableMethod · 0.45

Tested by

no test coverage detected