More progress on integrating ariadne's error reporting

This commit is contained in:
2026-03-01 02:20:58 -05:00
parent 792b0c21d0
commit dff87fd5c2
19 changed files with 297 additions and 295 deletions

View File

@@ -1,7 +1,9 @@
use std::collections::VecDeque;
use ariadne::Span as AriadneSpan;
use crate::parse::lex::{Span, Tk, TkRule};
use crate::parse::{Redir, RedirType};
use crate::parse::{Node, Redir, RedirType};
use crate::prelude::*;
pub trait VecDequeExt<T> {
@@ -27,6 +29,10 @@ pub trait RedirVecUtils<Redir> {
fn split_by_channel(self) -> (Vec<Redir>, Vec<Redir>);
}
pub trait NodeVecUtils<Node> {
fn get_span(&self) -> Option<Span>;
}
impl<T> VecDequeExt<T> for VecDeque<T> {
fn to_vec(self) -> Vec<T> {
self.into_iter().collect::<Vec<T>>()
@@ -124,3 +130,17 @@ impl RedirVecUtils<Redir> for Vec<Redir> {
(input, output)
}
}
impl NodeVecUtils<Node> for Vec<Node> {
fn get_span(&self) -> Option<Span> {
if let Some(first_nd) = self.first()
&& let Some(last_nd) = self.last() {
let first_start = first_nd.get_span().range().start;
let last_end = last_nd.get_span().range().end;
if first_start <= last_end {
return Some(Span::new(first_start..last_end, first_nd.get_span().source().content()));
}
}
None
}
}