y_lang/ast/
param.rs

1use pest::iterators::Pair;
2
3use super::{Ident, Position, Rule, TypeAnnotation};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Param<T> {
7    pub ident: Ident<T>,
8    pub type_annotation: TypeAnnotation,
9    pub position: Position,
10}
11
12impl Param<()> {
13    pub fn from_pair(pair: Pair<Rule>, file: &str) -> Param<()> {
14        assert_eq!(pair.as_rule(), Rule::parameter);
15
16        let (line, col) = pair.line_col();
17
18        let mut inner = pair.into_inner();
19
20        let ident = inner.next().unwrap();
21        let ident = Ident::from_pair(ident, file);
22
23        let type_annotation = inner.next().unwrap();
24        let type_annotation = TypeAnnotation::from_pair(type_annotation, file);
25
26        Param {
27            ident,
28            type_annotation,
29            position: (file.to_owned(), line, col),
30        }
31    }
32}
33
34impl<T> Param<T>
35where
36    T: Clone,
37{
38    pub fn info(&self) -> T {
39        self.ident.info.clone()
40    }
41}