forked from Orchid/orchid
Changes in api and upwards
- Removed out-of-stack error reporting - Revised module system to match previous Orchid system - Errors are now in a Vec everywhere - Implemented atoms and lexer - Started implementation of line parser - Tree is now ephemeral to avoid copying Atoms held inside - Moved numbers into std and the shared parser into base - Started implementation of Commands
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
use orchid_api_traits::Coding;
|
||||
|
||||
pub trait AsApi: Sized {
|
||||
type Api: Sized;
|
||||
type Ctx<'a>;
|
||||
fn to_api(&self, ctx: Self::Ctx<'_>) -> Self::Api;
|
||||
fn into_api(self, ctx: Self::Ctx<'_>) -> Self::Api { self.to_api(ctx) }
|
||||
fn from_api_ref(api: &Self::Api, ctx: Self::Ctx<'_>) -> Self;
|
||||
fn from_api(api: Self::Api, ctx: Self::Ctx<'_>) -> Self { Self::from_api_ref(&api, ctx) }
|
||||
}
|
||||
@@ -5,6 +5,16 @@ use orchid_api::parser::CharFilter;
|
||||
|
||||
pub type CRange = RangeInclusive<char>;
|
||||
|
||||
pub trait ICFilter {
|
||||
fn ranges(&self) -> &[RangeInclusive<char>];
|
||||
}
|
||||
impl ICFilter for [RangeInclusive<char>] {
|
||||
fn ranges(&self) -> &[RangeInclusive<char>] { self }
|
||||
}
|
||||
impl ICFilter for CharFilter {
|
||||
fn ranges(&self) -> &[RangeInclusive<char>] { &self.0 }
|
||||
}
|
||||
|
||||
fn try_merge_char_ranges(left: CRange, right: CRange) -> Result<CRange, (CRange, CRange)> {
|
||||
match *left.end() as u32 + 1 < *right.start() as u32 {
|
||||
true => Err((left, right)),
|
||||
@@ -25,19 +35,19 @@ pub fn mk_char_filter(items: impl IntoIterator<Item = CRange>) -> CharFilter {
|
||||
}
|
||||
|
||||
/// Decide whether a char filter matches a character via binary search
|
||||
pub fn char_filter_match(cf: &CharFilter, c: char) -> bool {
|
||||
match cf.0.binary_search_by_key(&c, |l| *l.end()) {
|
||||
pub fn char_filter_match(cf: &(impl ICFilter + ?Sized), c: char) -> bool {
|
||||
match cf.ranges().binary_search_by_key(&c, |l| *l.end()) {
|
||||
Ok(_) => true, // c is the end of a range
|
||||
Err(i) if i == cf.0.len() => false, // all ranges end before c
|
||||
Err(i) => cf.0[i].contains(&c), // c between cf.0[i-1]?.end and cf.0[i].end, check [i]
|
||||
Err(i) if i == cf.ranges().len() => false, // all ranges end before c
|
||||
Err(i) => cf.ranges()[i].contains(&c), // c between cf.0[i-1]?.end and cf.0[i].end, check [i]
|
||||
}
|
||||
}
|
||||
|
||||
/// Merge two char filters into a filter that matches if either of the
|
||||
/// constituents would match.
|
||||
pub fn char_filter_union(l: &CharFilter, r: &CharFilter) -> CharFilter {
|
||||
pub fn char_filter_union(l: &(impl ICFilter + ?Sized), r: &(impl ICFilter + ?Sized)) -> CharFilter {
|
||||
CharFilter(
|
||||
(l.0.iter().merge_by(&r.0, |l, r| l.start() <= r.start()))
|
||||
(l.ranges().iter().merge_by(r.ranges(), |l, r| l.start() <= r.start()))
|
||||
.cloned()
|
||||
.coalesce(try_merge_char_ranges)
|
||||
.collect_vec(),
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::location::Pos;
|
||||
|
||||
/// A point of interest in resolving the error, such as the point where
|
||||
/// processing got stuck, a command that is likely to be incorrect
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ErrorPosition {
|
||||
/// The suspected origin
|
||||
pub position: Pos,
|
||||
@@ -35,7 +35,7 @@ impl From<Pos> for ErrorPosition {
|
||||
fn from(origin: Pos) -> Self { Self { position: origin, message: None } }
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OwnedError {
|
||||
pub description: Tok<String>,
|
||||
pub message: Arc<String>,
|
||||
@@ -49,4 +49,7 @@ impl OwnedError {
|
||||
positions: err.locations.iter().map(ErrorPosition::from_api).collect(),
|
||||
}
|
||||
}
|
||||
pub fn from_apiv(err: Vec<ProjErr>) -> Vec<Self> {
|
||||
err.into_iter().map(|e| Self::from_api(&e)).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ pub mod event;
|
||||
pub mod msg;
|
||||
// pub mod gen;
|
||||
pub mod api_utils;
|
||||
pub mod as_api;
|
||||
pub mod box_cow;
|
||||
pub mod char_filter;
|
||||
pub mod error;
|
||||
|
||||
@@ -9,9 +9,10 @@ use std::path::Path;
|
||||
use std::{fmt, slice, vec};
|
||||
|
||||
use itertools::Itertools;
|
||||
use orchid_api::interner::TStr;
|
||||
use trait_set::trait_set;
|
||||
|
||||
use crate::interner::{intern, InternMarker, Tok};
|
||||
use crate::interner::{deintern, intern, InternMarker, Tok};
|
||||
|
||||
trait_set! {
|
||||
/// Traits that all name iterators should implement
|
||||
@@ -226,6 +227,9 @@ impl VName {
|
||||
let data: Vec<_> = items.into_iter().collect();
|
||||
if data.is_empty() { Err(EmptyNameError) } else { Ok(Self(data)) }
|
||||
}
|
||||
pub fn deintern(items: impl IntoIterator<Item = TStr>) -> Result<Self, EmptyNameError> {
|
||||
Self::new(items.into_iter().map(deintern))
|
||||
}
|
||||
/// Unwrap the enclosed vector
|
||||
pub fn into_vec(self) -> Vec<Tok<String>> { self.0 }
|
||||
/// Get a reference to the enclosed vector
|
||||
|
||||
@@ -2,7 +2,7 @@ use orchid_api::tree::{Placeholder, PlaceholderKind};
|
||||
|
||||
use crate::interner::{deintern, Tok};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OwnedPh {
|
||||
pub name: Tok<String>,
|
||||
pub kind: PlaceholderKind,
|
||||
|
||||
Reference in New Issue
Block a user