Custom lexers can now terminate operators
Some checks failed
Rust / build (push) Has been cancelled

New constraint: custom lexer output is dropped whenever it is used to terminate an operator nested inside another custom lexer, because the recursive call has to return exactly one lexeme
This commit is contained in:
2026-01-25 17:52:18 +01:00
parent b9f1bb74d7
commit c461f82de1
17 changed files with 333 additions and 142 deletions

View File

@@ -40,7 +40,7 @@ impl TryFromExpr for Int {
}
impl Supports<GetTagIdMethod> for Int {
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
Sym::parse("std::number::Int").await.unwrap().to_api()
sym!(std::number::Int).to_api()
}
}
impl Supports<GetImplMethod> for Int {
@@ -90,7 +90,7 @@ impl TryFromExpr for Float {
}
impl Supports<GetTagIdMethod> for Float {
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
Sym::parse("std::number::Float").await.unwrap().to_api()
sym!(std::number::Float).to_api()
}
}
impl Supports<GetImplMethod> for Float {

View File

@@ -45,7 +45,7 @@ impl OwnedAtom for RecordAtom {
}
impl Supports<GetTagIdMethod> for RecordAtom {
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
Sym::literal("std::record::Record").await.to_api()
sym!(std::record::Record).to_api()
}
}
impl Supports<GetImplMethod> for RecordAtom {

View File

@@ -1,12 +1,15 @@
use std::rc::Rc;
use hashbrown::HashMap;
use itertools::Itertools;
use orchid_base::error::mk_errv;
use orchid_base::interner::is;
use orchid_extension::atom::TAtom;
use orchid_extension::atom_owned::own;
use orchid_extension::expr::Expr;
use orchid_extension::gen_expr::arg;
use orchid_extension::tree::{GenMember, cnst, fun, prefix};
use crate::std::option::OrcOpt;
use crate::std::record::record_atom::RecordAtom;
use crate::std::string::str_atom::IntStrAtom;
@@ -19,7 +22,15 @@ pub fn gen_record_lib() -> Vec<GenMember> {
RecordAtom(Rc::new(map))
}),
fun(true, "get", async |map: TAtom<RecordAtom>, key: IntStrAtom| {
OrcOpt(own(&map).await.0.get(&key.0).cloned())
let record = own(&map).await;
match record.0.get(&key.0) {
Some(val) => Ok(val.clone()),
None => Err(mk_errv(
is("Key not found in record").await,
format!("{} is not in this record, valid keys are {}", key.0, record.0.keys().join(", ")),
[arg(0).pos.clone(), arg(1).pos.clone()],
)),
}
}),
fun(true, "delete", async |map: TAtom<RecordAtom>, key: IntStrAtom| {
let mut map = own(&map).await.0.as_ref().clone();

View File

@@ -35,7 +35,11 @@ impl Atomic for StrAtom {
type Variant = OwnedVariant;
type Data = ();
fn reg_reqs() -> MethodSetBuilder<Self> {
MethodSetBuilder::new().handle::<StringGetValMethod>().handle::<ToStringMethod>()
MethodSetBuilder::new()
.handle::<StringGetValMethod>()
.handle::<ToStringMethod>()
.handle::<GetTagIdMethod>()
.handle::<GetImplMethod>()
}
}
impl StrAtom {
@@ -70,7 +74,7 @@ impl Supports<ToStringMethod> for StrAtom {
}
impl Supports<GetTagIdMethod> for StrAtom {
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
Sym::literal("std::string::StrAtom").await.to_api()
sym!(std::string::StrAtom).to_api()
}
}
impl Supports<GetImplMethod> for StrAtom {
@@ -126,7 +130,7 @@ impl Supports<ToStringMethod> for IntStrAtom {
}
impl Supports<GetTagIdMethod> for IntStrAtom {
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
Sym::literal("std::string::IntStrAtom").await.to_api()
sym!(std::string::IntStrAtom).to_api()
}
}
impl Supports<GetImplMethod> for IntStrAtom {

View File

@@ -11,14 +11,17 @@ use orchid_api_traits::Request;
use orchid_base::error::{OrcRes, mk_errv};
use orchid_base::format::{FmtCtx, FmtUnit, Format, Variants};
use orchid_base::interner::is;
use orchid_extension::atom::{Atomic, TAtom};
use orchid_base::name::Sym;
use orchid_base::sym;
use orchid_extension::atom::{Atomic, MethodSetBuilder, Supports, TAtom};
use orchid_extension::atom_owned::{DeserializeCtx, OwnedAtom, OwnedVariant, own};
use orchid_extension::conv::{ToExpr, TryFromExpr};
use orchid_extension::expr::{Expr, ExprHandle};
use orchid_extension::gen_expr::GExpr;
use orchid_extension::gen_expr::{GExpr, sym_ref};
use orchid_extension::system::dep_req;
use orchid_extension::tree::{GenMember, cnst, fun, prefix};
use crate::std::protocol::types::{GetImplMethod, GetTagIdMethod};
use crate::std::std_system::StdReq;
use crate::{Int, StdSystem, api};
@@ -28,6 +31,9 @@ pub struct Tuple(pub(super) Rc<Vec<Expr>>);
impl Atomic for Tuple {
type Data = Vec<api::ExprTicket>;
type Variant = OwnedVariant;
fn reg_reqs() -> orchid_extension::atom::MethodSetBuilder<Self> {
MethodSetBuilder::new().handle::<GetTagIdMethod>().handle::<GetImplMethod>()
}
}
impl OwnedAtom for Tuple {
@@ -46,6 +52,24 @@ impl OwnedAtom for Tuple {
.units_own(join_all(self.0.iter().map(|x| x.print(c))).await)
}
}
impl Supports<GetTagIdMethod> for Tuple {
async fn handle(&self, _: GetTagIdMethod) -> <GetTagIdMethod as Request>::Response {
sym!(std::tuple).to_api()
}
}
impl Supports<GetImplMethod> for Tuple {
async fn handle(&self, req: GetImplMethod) -> <GetImplMethod as Request>::Response {
let name = Sym::from_api(req.0).await;
let val = if name == sym!(std::ops::get) {
sym_ref(sym!(std::tuple::get))
} else if name == sym!(std::ops::set) {
sym_ref(sym!(std::tuple::set))
} else {
return None;
};
Some(val.create().await.serialize().await)
}
}
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(StdReq)]