Compare commits
2 Commits
nadro/adho
...
jtran/recu
Author | SHA1 | Date | |
---|---|---|---|
55a6155400 | |||
d41972ee4d |
7
src/wasm-lib/Cargo.lock
generated
7
src/wasm-lib/Cargo.lock
generated
@ -1428,6 +1428,7 @@ dependencies = [
|
|||||||
"parse-display",
|
"parse-display",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
|
"recursion",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"ropey",
|
"ropey",
|
||||||
"schemars",
|
"schemars",
|
||||||
@ -2148,6 +2149,12 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "recursion"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f705426858ccd7bbfe19798239d6b6bfd9bf96bde0624a84b92694046e98871"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
|
@ -31,6 +31,7 @@ lazy_static = "1.5.0"
|
|||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
parse-display = "0.9.1"
|
parse-display = "0.9.1"
|
||||||
pyo3 = { version = "0.22.2", optional = true }
|
pyo3 = { version = "0.22.2", optional = true }
|
||||||
|
recursion = "0.5.2"
|
||||||
reqwest = { version = "0.11.26", default-features = false, features = ["stream", "rustls-tls"] }
|
reqwest = { version = "0.11.26", default-features = false, features = ["stream", "rustls-tls"] }
|
||||||
ropey = "1.6.1"
|
ropey = "1.6.1"
|
||||||
schemars = { version = "0.8.17", features = ["impl_json_schema", "url", "uuid1"] }
|
schemars = { version = "0.8.17", features = ["impl_json_schema", "url", "uuid1"] }
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
pub mod modify;
|
pub mod modify;
|
||||||
|
mod recursion;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
167
src/wasm-lib/kcl/src/ast/recursion.rs
Normal file
167
src/wasm-lib/kcl/src/ast/recursion.rs
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
use recursion::{Collapsible, MappableFrame, PartiallyApplied};
|
||||||
|
|
||||||
|
use super::types::{
|
||||||
|
BinaryExpression, BinaryOperator, BinaryPart, Digest, Expr, FnArgType, Identifier, KclNone, Literal, Parameter,
|
||||||
|
PipeSubstitution, TagDeclarator,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub enum ExprFrame<A> {
|
||||||
|
Literal(Box<Literal>),
|
||||||
|
Identifier(Box<Identifier>),
|
||||||
|
TagDeclarator(Box<TagDeclarator>),
|
||||||
|
BinaryExpression(Box<BinaryExpressionFrame<A>>),
|
||||||
|
FunctionExpression(Box<FunctionExpressionFrame<A>>),
|
||||||
|
CallExpression(Box<CallExpressionFrame<A>>),
|
||||||
|
PipeExpression(Box<PipeExpressionFrame<A>>),
|
||||||
|
PipeSubstitution(Box<PipeSubstitution>),
|
||||||
|
ArrayExpression(Box<ArrayExpressionFrame<A>>),
|
||||||
|
ObjectExpression(Box<ObjectExpressionFrame<A>>),
|
||||||
|
MemberExpression(Box<MemberExpressionFrame<A>>),
|
||||||
|
UnaryExpression(Box<UnaryExpressionFrame<A>>),
|
||||||
|
None(KclNone),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MappableFrame for ExprFrame<PartiallyApplied> {
|
||||||
|
type Frame<X> = ExprFrame<X>;
|
||||||
|
|
||||||
|
fn map_frame<A, B>(input: Self::Frame<A>, mut f: impl FnMut(A) -> B) -> Self::Frame<B> {
|
||||||
|
match input {
|
||||||
|
ExprFrame::Literal(x) => ExprFrame::Literal(x),
|
||||||
|
ExprFrame::Identifier(x) => ExprFrame::Identifier(x),
|
||||||
|
ExprFrame::TagDeclarator(x) => ExprFrame::TagDeclarator(x),
|
||||||
|
ExprFrame::BinaryExpression(x) => ExprFrame::BinaryExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::FunctionExpression(x) => ExprFrame::FunctionExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::CallExpression(x) => ExprFrame::CallExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::PipeExpression(x) => ExprFrame::PipeExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::PipeSubstitution(x) => ExprFrame::PipeSubstitution(x),
|
||||||
|
ExprFrame::ArrayExpression(x) => ExprFrame::ArrayExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::ObjectExpression(x) => ExprFrame::ObjectExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::MemberExpression(x) => ExprFrame::MemberExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::UnaryExpression(x) => ExprFrame::UnaryExpression(MappableFrame::map_frame(x, &mut f)),
|
||||||
|
ExprFrame::None(x) => ExprFrame::None(x),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Collapsible for &'a Expr {
|
||||||
|
type FrameToken = ExprFrame<PartiallyApplied>;
|
||||||
|
|
||||||
|
fn into_frame(self) -> <Self::FrameToken as MappableFrame>::Frame<Self> {
|
||||||
|
match self {
|
||||||
|
Expr::Literal(x) => ExprFrame::Literal(x.clone()),
|
||||||
|
Expr::Identifier(x) => ExprFrame::Identifier(x.clone()),
|
||||||
|
Expr::TagDeclarator(x) => ExprFrame::TagDeclarator(x.clone()),
|
||||||
|
Expr::BinaryExpression(x) => ExprFrame::BinaryExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::FunctionExpression(x) => ExprFrame::FunctionExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::CallExpression(x) => ExprFrame::CallExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::PipeExpression(x) => ExprFrame::PipeExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::PipeSubstitution(x) => ExprFrame::PipeSubstitution(x.clone()),
|
||||||
|
Expr::ArrayExpression(x) => ExprFrame::ArrayExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::ObjectExpression(x) => ExprFrame::ObjectExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::MemberExpression(x) => ExprFrame::MemberExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::UnaryExpression(x) => ExprFrame::UnaryExpression(Box::new(x.into_frame())),
|
||||||
|
Expr::None(x) => ExprFrame::None(x.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct BinaryExpressionFrame<A> {
|
||||||
|
pub start: usize,
|
||||||
|
pub end: usize,
|
||||||
|
pub operator: BinaryOperator,
|
||||||
|
pub left: BinaryPartFrame<A>,
|
||||||
|
pub right: BinaryPartFrame<A>,
|
||||||
|
|
||||||
|
pub digest: Option<Digest>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MappableFrame for BinaryExpressionFrame<PartiallyApplied> {
|
||||||
|
type Frame<X> = BinaryExpressionFrame<X>;
|
||||||
|
|
||||||
|
fn map_frame<A, B>(input: Self::Frame<A>, mut f: impl FnMut(A) -> B) -> Self::Frame<B> {
|
||||||
|
BinaryExpressionFrame::<B> {
|
||||||
|
start: input.start,
|
||||||
|
end: input.end,
|
||||||
|
operator: input.operator,
|
||||||
|
left: <BinaryPartFrame<PartiallyApplied> as MappableFrame>::map_frame(input.left, &mut f),
|
||||||
|
right: <BinaryPartFrame<PartiallyApplied> as MappableFrame>::map_frame(input.right, &mut f),
|
||||||
|
digest: input.digest,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Collapsible for &'a BinaryExpression {
|
||||||
|
type FrameToken = BinaryExpressionFrame<PartiallyApplied>;
|
||||||
|
|
||||||
|
fn into_frame(self) -> <Self::FrameToken as MappableFrame>::Frame<Self> {
|
||||||
|
BinaryExpressionFrame::<BinaryExpression> {
|
||||||
|
start: self.start,
|
||||||
|
end: self.end,
|
||||||
|
operator: self.operator.clone(),
|
||||||
|
left: self.left.into_frame(),
|
||||||
|
right: self.right.into_frame(),
|
||||||
|
digest: self.digest,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum BinaryPartFrame<A> {
|
||||||
|
Literal(Box<Literal>),
|
||||||
|
Identifier(Box<Identifier>),
|
||||||
|
BinaryExpression(Box<BinaryExpressionFrame<A>>),
|
||||||
|
CallExpression(Box<CallExpressionFrame<A>>),
|
||||||
|
UnaryExpression(Box<UnaryExpressionFrame<A>>),
|
||||||
|
MemberExpression(Box<MemberExpressionFrame<A>>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MappableFrame for BinaryPartFrame<PartiallyApplied> {
|
||||||
|
type Frame<X> = BinaryPartFrame<X>;
|
||||||
|
|
||||||
|
fn map_frame<A, B>(input: Self::Frame<A>, mut f: impl FnMut(A) -> B) -> Self::Frame<B> {
|
||||||
|
match input {
|
||||||
|
BinaryPartFrame::Literal(x) => BinaryPartFrame::Literal(x),
|
||||||
|
BinaryPartFrame::Identifier(x) => BinaryPartFrame::Identifier(x),
|
||||||
|
BinaryPartFrame::BinaryExpression(x) => BinaryPartFrame::BinaryExpression(MappableFrame::map_frame(x, f)),
|
||||||
|
BinaryPartFrame::CallExpression(x) => BinaryPartFrame::CallExpression(MappableFrame::map_frame(x, f)),
|
||||||
|
BinaryPartFrame::UnaryExpression(x) => BinaryPartFrame::UnaryExpression(MappableFrame::map_frame(x, f)),
|
||||||
|
BinaryPartFrame::MemberExpression(x) => BinaryPartFrame::MemberExpression(MappableFrame::map_frame(x, f)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Collapsible for &'a BinaryPart {
|
||||||
|
type FrameToken = BinaryPartFrame<PartiallyApplied>;
|
||||||
|
|
||||||
|
fn into_frame(self) -> <Self::FrameToken as MappableFrame>::Frame<Self> {
|
||||||
|
match self {
|
||||||
|
BinaryPart::Literal(x) => BinaryPartFrame::Literal(x.clone()),
|
||||||
|
BinaryPart::Identifier(x) => BinaryPartFrame::Identifier(x.clone()),
|
||||||
|
BinaryPart::BinaryExpression(x) => BinaryPartFrame::BinaryExpression(x.into_frame()),
|
||||||
|
BinaryPart::CallExpression(x) => BinaryPartFrame::CallExpression(x.into_frame()),
|
||||||
|
BinaryPart::UnaryExpression(x) => BinaryPartFrame::UnaryExpression(x.into_frame()),
|
||||||
|
BinaryPart::MemberExpression(x) => BinaryPartFrame::MemberExpression(x.into_frame()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FunctionExpressionFrame<A> {
|
||||||
|
pub start: usize,
|
||||||
|
pub end: usize,
|
||||||
|
pub params: Vec<Parameter>,
|
||||||
|
pub body: ProgramFrame<A>,
|
||||||
|
pub return_type: Option<FnArgType>,
|
||||||
|
|
||||||
|
pub digest: Option<Digest>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CallExpressionFrame<A> {
|
||||||
|
pub start: usize,
|
||||||
|
pub end: usize,
|
||||||
|
pub callee: Identifier,
|
||||||
|
pub arguments: Vec<ExprFrame<A>>,
|
||||||
|
pub optional: bool,
|
||||||
|
|
||||||
|
pub digest: Option<Digest>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// More...
|
Reference in New Issue
Block a user