Gitbutler >:(

I don't understand this piece of software at all
This commit is contained in:
2024-12-31 00:03:39 +01:00
parent 3a3ae98aff
commit e780969c6c
42 changed files with 1119 additions and 498 deletions

View File

@@ -7,8 +7,7 @@ use std::ops::Range;
use trait_set::trait_set;
use orchid_api_traits::{ApiEquiv, FromApi, ToApi};
use crate::interner::{deintern, intern, Tok};
use crate::interner::{intern, Tok};
use crate::name::Sym;
use crate::{api, intern, sym};
@@ -38,30 +37,20 @@ impl Pos {
other => format!("{other:?}"),
}
}
}
impl ApiEquiv for Pos {
type Api = api::Location;
}
impl FromApi for Pos {
type Ctx = ();
fn from_api(api: &Self::Api, ctx: &mut Self::Ctx) -> Self {
pub fn from_api(api: &api::Location) -> Self {
match_mapping!(api, api::Location => Pos {
None, Inherit, SlotTarget,
Range(r.clone()),
Gen(cgi => CodeGenInfo::from_api(cgi, &mut ())),
SourceRange(sr => CodeGenInfo::from_api(sr, &mut ()))
Gen(cgi => CodeGenInfo::from_api(cgi)),
SourceRange(sr => SourceRange::from_api(sr))
})
}
}
impl ToApi for Pos {
type Ctx = ();
fn to_api(&self, ctx: &mut Self::Ctx) -> Self::Api {
match_mapping!(self, Pos => Self::Api {
pub fn to_api(&self) -> api::Location {
match_mapping!(self, Pos => api::Location {
None, Inherit, SlotTarget,
Range(r.clone()),
Gen(cgi.to_api(ctx)),
SourceRange(sr.to_api(ctx)),
Gen(cgi.to_api()),
SourceRange(sr.to_api()),
})
}
}
@@ -106,20 +95,11 @@ impl SourceRange {
pub fn zw(path: Sym, pos: u32) -> Self {
Self { path, range: pos..pos }
}
}
impl ApiEquiv for SourceRange {
type Api = api::SourceRange;
}
impl FromApi for SourceRange {
type Ctx = ();
fn from_api(api: &Self::Api, ctx: &mut Self::Ctx) -> Self {
Self { path: Sym::from_api(&api.path, ctx), range: api.range.clone() }
fn from_api(api: &api::SourceRange) -> Self {
Self { path: Sym::from_api(api.path), range: api.range.clone() }
}
}
impl ToApi for SourceRange {
type Ctx = ();
fn to_api(&self, ctx: &mut Self::Ctx) -> Self::Api {
api::SourceRange { path: self.path.to_api(ctx), range: self.range.clone() }
fn to_api(&self) -> api::SourceRange {
api::SourceRange { path: self.path.to_api(), range: self.range.clone() }
}
}
@@ -140,6 +120,15 @@ impl CodeGenInfo {
}
/// Syntactic location
pub fn pos(&self) -> Pos { Pos::Gen(self.clone()) }
fn from_api(api: &api::CodeGenInfo) -> Self {
Self {
generator: Sym::from_api(api.generator),
details: Tok::from_api(api.details),
}
}
fn to_api(&self) -> api::CodeGenInfo {
api::CodeGenInfo { generator: self.generator.to_api(), details: self.details.to_api() }
}
}
impl fmt::Debug for CodeGenInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "CodeGenInfo({self})") }
@@ -150,24 +139,6 @@ impl fmt::Display for CodeGenInfo {
if !self.details.is_empty() { write!(f, ", details: {}", self.details) } else { write!(f, ".") }
}
}
impl ApiEquiv for CodeGenInfo {
type Api = api::CodeGenInfo;
}
impl FromApi for CodeGenInfo {
type Ctx = ();
fn from_api(api: &Self::Api, ctx: &mut Self::Ctx) -> Self {
Self {
generator: Sym::from_api(&api.generator, ctx),
details: Tok::from_api(&api.details, ctx),
}
}
}
impl ToApi for CodeGenInfo {
type Ctx = ();
fn to_api(&self, ctx: &mut Self::Ctx) -> Self::Api {
api::CodeGenInfo { generator: self.generator.to_api(ctx), details: self.details.to_api(ctx) }
}
}
#[must_use]
fn pos2lc(s: &str, i: u32) -> (u32, u32) {