mylang_parser/
result.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use mylang_token::{Locatable, Pos, Range};
use thiserror::Error;

/// 構文解析中に発生するエラー
#[derive(Debug, Error)]
pub enum ParseErr {
    #[error("Term expected, but not found")]
    TermExpected(Pos),

    #[error("Either print_int or print_str expected, but not found")]
    KeywordExpected(Range),
}

impl Locatable for ParseErr {
    fn locate(&self) -> Range {
        match self {
            ParseErr::TermExpected(pos) => pos.clone().into(),

            ParseErr::KeywordExpected(range) => range.clone(),
        }
    }
}

pub type ParseResult<T> = Result<T, ParseErr>;