Formatter introduced

This commit is contained in:
2025-02-07 00:47:34 +01:00
parent b94d8a64cb
commit 40c5eaf3d5
23 changed files with 608 additions and 218 deletions

View File

@@ -4,7 +4,8 @@ use orchid_api_derive::{Coding, Hierarchy};
use orchid_api_traits::Request;
use crate::{
ExprTicket, Expression, ExtHostReq, HostExtNotif, HostExtReq, OrcResult, SysId, TStrv,
ExprTicket, Expression, ExtHostReq, FormattingUnit, HostExtNotif, HostExtReq, OrcResult, SysId,
TStrv,
};
pub type AtomData = Vec<u8>;
@@ -117,14 +118,14 @@ pub struct AtomDrop(pub SysId, pub AtomId);
#[extends(AtomReq, HostExtReq)]
pub struct AtomPrint(pub Atom);
impl Request for AtomPrint {
type Response = String;
type Response = FormattingUnit;
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
#[extends(ExtHostReq)]
pub struct ExtAtomPrint(pub Atom);
impl Request for ExtAtomPrint {
type Response = String;
type Response = FormattingUnit;
}
/// Requests that apply to an existing atom instance

20
orchid-api/src/format.rs Normal file
View File

@@ -0,0 +1,20 @@
use orchid_api_derive::Coding;
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding)]
pub struct FormattingUnit {
pub subs: Vec<FormattingUnit>,
pub variants: Vec<FormattingVariant>,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding)]
pub struct FormattingVariant {
pub bounded: bool,
pub elements: Vec<FormattingElement>,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding)]
pub enum FormattingElement {
Sub { slot: u32, bounded: Option<bool> },
String(String),
Indent(Vec<FormattingElement>),
}

View File

@@ -1,5 +1,7 @@
mod lexer;
pub use lexer::*;
mod format;
pub use format::*;
mod macros;
pub use macros::*;
mod atom;