bluejay_parser/ast/definition/
interface_implementations.rs1use crate::ast::definition::{Context, InterfaceImplementation};
2use crate::ast::{DepthLimiter, FromTokens, IsMatch, ParseError, Tokens};
3use crate::lexical_token::PunctuatorType;
4use bluejay_core::definition::InterfaceImplementations as CoreInterfaceImplementations;
5use bluejay_core::AsIter;
6
7#[derive(Debug)]
8pub struct InterfaceImplementations<'a, C: Context + 'a> {
9 interface_implementations: Vec<InterfaceImplementation<'a, C>>,
10}
11
12impl<'a, C: Context + 'a> AsIter for InterfaceImplementations<'a, C> {
13 type Item = InterfaceImplementation<'a, C>;
14 type Iterator<'b>
15 = std::slice::Iter<'b, Self::Item>
16 where
17 'a: 'b;
18
19 fn iter(&self) -> Self::Iterator<'_> {
20 self.interface_implementations.iter()
21 }
22}
23
24impl<'a, C: Context + 'a> CoreInterfaceImplementations for InterfaceImplementations<'a, C> {
25 type InterfaceImplementation = InterfaceImplementation<'a, C>;
26}
27
28impl<'a, C: Context + 'a> InterfaceImplementations<'a, C> {
29 const IMPLEMENTS_IDENTIFIER: &'static str = "implements";
30}
31
32impl<'a, C: Context + 'a> FromTokens<'a> for InterfaceImplementations<'a, C> {
33 fn from_tokens(
34 tokens: &mut impl Tokens<'a>,
35 depth_limiter: DepthLimiter,
36 ) -> Result<Self, ParseError> {
37 tokens.expect_name_value(Self::IMPLEMENTS_IDENTIFIER)?;
38 tokens.next_if_punctuator(PunctuatorType::Ampersand);
39 let mut interface_implementations = vec![InterfaceImplementation::from_tokens(
40 tokens,
41 depth_limiter.bump()?,
42 )?];
43 while tokens
44 .next_if_punctuator(PunctuatorType::Ampersand)
45 .is_some()
46 {
47 interface_implementations.push(InterfaceImplementation::from_tokens(
48 tokens,
49 depth_limiter.bump()?,
50 )?);
51 }
52 Ok(Self {
53 interface_implementations,
54 })
55 }
56}
57
58impl<'a, C: Context + 'a> IsMatch<'a> for InterfaceImplementations<'a, C> {
59 fn is_match(tokens: &mut impl Tokens<'a>) -> bool {
60 tokens.peek_name_matches(0, Self::IMPLEMENTS_IDENTIFIER)
61 }
62}