y_lang/ast/
indexing.rs

1use pest::iterators::Pair;
2
3use super::{Expression, Position, Rule};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Indexing<T> {
7    pub index: Box<Expression<T>>,
8    pub position: Position,
9    pub info: T,
10}
11
12impl Indexing<()> {
13    pub fn from_pair(pair: Pair<Rule>, file: &str) -> Indexing<()> {
14        assert_eq!(pair.as_rule(), Rule::indexing);
15
16        let (line, col) = pair.line_col();
17
18        let mut inner = pair.into_inner();
19
20        let index = inner.next().unwrap();
21        let index = Expression::from_pair(index, file);
22
23        Indexing {
24            index: Box::new(index),
25            position: (file.to_owned(), line, col),
26            info: (),
27        }
28    }
29}