From c5bdb040987e29bfcfb234e3a014d5a609a50d53 Mon Sep 17 00:00:00 2001 From: nothendev Date: Tue, 17 Oct 2023 21:17:11 +0300 Subject: [PATCH] continu --- cli/src/error.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/cli/src/error.rs b/cli/src/error.rs index b1a4869..4a996c0 100644 --- a/cli/src/error.rs +++ b/cli/src/error.rs @@ -3,7 +3,8 @@ use std::{borrow::Cow, num::ParseIntError, ops::Range}; use oxcr_protocol::{ aott::{ self, - error::LabelError, + error::{BuiltinLabel, LabelError}, + primitive::SeqLabel, text::{self, CharError, CharLabel}, }, miette::{self, SourceSpan}, @@ -78,6 +79,14 @@ pub enum ParseError { label: aott::error::BuiltinLabel, last_token: Option, }, + + #[error("{label}; last token was {last_token:?}")] + Sequence { + #[label = "here"] + at: SourceSpan, + label: SeqLabel, + last_token: Option, + }, } #[derive(Debug, thiserror::Error)] @@ -123,4 +132,44 @@ impl<'a> aott::error::FundamentalError<&'a str> for ParseError { } } -impl<'a> LabelError<&'a str, CharLabel> for ParseError {} +impl<'a> LabelError<&'a str, CharLabel> for ParseError { + fn from_label( + span: Range, + label: CharLabel, + last_token: Option<<&'a str as aott::prelude::InputType>::Token>, + ) -> Self { + Self::Text { + at: span.into(), + label, + last_token, + } + } +} + +impl<'a> LabelError<&'a str, BuiltinLabel> for ParseError { + fn from_label( + span: Range, + label: BuiltinLabel, + last_token: Option<<&'a str as aott::prelude::InputType>::Token>, + ) -> Self { + Self::Builtin { + at: span.into(), + label, + last_token, + } + } +} + +impl<'a> LabelError<&'a str, SeqLabel> for ParseError { + fn from_label( + span: Range, + label: SeqLabel, + last_token: Option<<&'a str as aott::prelude::InputType>::Token>, + ) -> Self { + Self::Sequence { + at: span.into(), + label, + last_token, + } + } +}