1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use gramatika::{Parse, ParseStreamer, Span, Spanned};

use crate::{
	common::TypeDecl,
	token::{keyword, operator, punct, Token, TokenKind},
	ParseStream,
};

#[derive(Clone, DebugLisp)]
pub struct TypeAliasDecl {
	pub storage: Token,
	pub name: Token,
	pub eq: Token,
	pub value: TypeDecl,
	pub semicolon: Token,
}

impl Parse for TypeAliasDecl {
	type Stream = ParseStream;

	fn parse(input: &mut Self::Stream) -> gramatika::Result<Self> {
		let storage = input.consume(keyword![alias])?;
		let name = input.consume_kind(TokenKind::Ident)?;
		let eq = input.consume(operator![=])?;
		let value = input.parse()?;
		let semicolon = input.consume(punct![;])?;

		Ok(Self {
			storage,
			name,
			eq,
			value,
			semicolon,
		})
	}
}

impl Spanned for TypeAliasDecl {
	fn span(&self) -> Span {
		self.storage.span().through(self.semicolon.span())
	}
}