bluejay_parser/ast/definition/
interface_implementations.rs1use crate::ast::definition::{Context, InterfaceImplementation};
2use crate::ast::{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> = std::slice::Iter<'b, Self::Item> where 'a: 'b;
15
16 fn iter(&self) -> Self::Iterator<'_> {
17 self.interface_implementations.iter()
18 }
19}
20
21impl<'a, C: Context + 'a> CoreInterfaceImplementations for InterfaceImplementations<'a, C> {
22 type InterfaceImplementation = InterfaceImplementation<'a, C>;
23}
24
25impl<'a, C: Context + 'a> InterfaceImplementations<'a, C> {
26 const IMPLEMENTS_IDENTIFIER: &'static str = "implements";
27}
28
29impl<'a, C: Context + 'a> FromTokens<'a> for InterfaceImplementations<'a, C> {
30 fn from_tokens(tokens: &mut impl Tokens<'a>) -> Result<Self, ParseError> {
31 tokens.expect_name_value(Self::IMPLEMENTS_IDENTIFIER)?;
32 tokens.next_if_punctuator(PunctuatorType::Ampersand);
33 let mut interface_implementations = vec![InterfaceImplementation::from_tokens(tokens)?];
34 while tokens
35 .next_if_punctuator(PunctuatorType::Ampersand)
36 .is_some()
37 {
38 interface_implementations.push(InterfaceImplementation::from_tokens(tokens)?);
39 }
40 Ok(Self {
41 interface_implementations,
42 })
43 }
44}
45
46impl<'a, C: Context + 'a> IsMatch<'a> for InterfaceImplementations<'a, C> {
47 fn is_match(tokens: &mut impl Tokens<'a>) -> bool {
48 tokens.peek_name_matches(0, Self::IMPLEMENTS_IDENTIFIER)
49 }
50}