Skip to content

Commit

Permalink
Lexicon support (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg authored May 15, 2023
1 parent 0e06bf3 commit 0f6e93a
Show file tree
Hide file tree
Showing 71 changed files with 4,294 additions and 1,000 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"modules/rust/macros",
"modules/rust/cli",
"modules/rust/prelude",
"modules/lexicon"
]

[workspace.package]
Expand All @@ -28,6 +29,7 @@ treeldr-json-ld-context = { path = "modules/json-ld-context", version = "0.1.0"
treeldr-rust-gen = { path = "modules/rust/gen", version = "0.1.0" }
treeldr-rust-macros = { path = "modules/rust/macros", version = "0.1.0" }
treeldr-rust-prelude = { path = "modules/rust/prelude", version = "0.1.0" }
treeldr-lexicon = { path = "modules/lexicon", version = "0.1.0" }

log = "0.4"
iref = "2.2"
Expand All @@ -45,14 +47,15 @@ thiserror = "1.0.31"
decoded-char = "0.1.1"
contextual = "0.1.3"
json-ld = "0.14.0"
json-syntax = "0.9.1"
json-syntax = "0.9.4"
serde = "1.0"

chrono = "0.4.19"
quote = "1.0"
proc-macro2 = "1.0"
syn = "2.0.15"

clap = "3.0"
clap = "4.0"
async-std = "1.12.0"
nquads-syntax = "0.12.0"

Expand Down
17 changes: 14 additions & 3 deletions build/src/error/node_type_invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ use super::NodeBindingTypeInvalid;

#[derive(Debug)]
pub struct NodeTypeInvalid<M> {
pub id: Id,
pub expected: Type,
pub found: PropertyValues<Type, M>
id: Id,
expected: Type,
found: PropertyValues<Type, M>
}

impl<M> NodeTypeInvalid<M> {
pub fn new(
id: Id,
expected: Type,
found: PropertyValues<Type, M>
) -> Self {
// panic!("invalid type");
Self { id, expected, found }
}
}

impl<M> NodeTypeInvalid<M> {
Expand Down
6 changes: 6 additions & 0 deletions build/src/layout/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ impl<M: Clone + Merge> BuildPrimitive<M> for Primitive {
Primitive::Url => Ok(treeldr::layout::RestrictedPrimitive::Url(
restrictions.try_map(|r| r.build(id))?,
)),
Primitive::Bytes => Ok(treeldr::layout::RestrictedPrimitive::Bytes(
restrictions.try_map(|r| r.build(id))?,
)),
Primitive::Cid => Ok(treeldr::layout::RestrictedPrimitive::Cid(
restrictions.try_map(|r| r.build(id))?,
)),
}
}
}
190 changes: 95 additions & 95 deletions build/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::Class(None)) {
Ok(self.as_type())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::Class(None).into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::Class(None).into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -326,11 +326,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::Class(None)) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::Class(None).into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::Class(None).into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -341,11 +341,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, ty::SubClass::DataType) {
Ok(self.as_datatype())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: ty::SubClass::DataType.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
ty::SubClass::DataType.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -356,11 +356,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, ty::SubClass::DataType) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: ty::SubClass::DataType.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
ty::SubClass::DataType.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -371,11 +371,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, ty::SubClass::Restriction) {
Ok(self.as_restriction())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: ty::SubClass::Restriction.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
ty::SubClass::Restriction.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -386,11 +386,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::LayoutRestriction) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::LayoutRestriction.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::LayoutRestriction.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -401,11 +401,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::DatatypeRestriction) {
Ok(self.as_datatype_restriction())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::DatatypeRestriction.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::DatatypeRestriction.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -416,11 +416,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::DatatypeRestriction) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::DatatypeRestriction.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::DatatypeRestriction.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -431,11 +431,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::Property(None)) {
Ok(self.as_property())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::Property(None).into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::Property(None).into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -446,11 +446,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::Property(None)) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::Property(None).into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::Property(None).into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -461,11 +461,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, component::Type::Layout) {
Ok(self.as_layout())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: component::Type::Layout.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
component::Type::Layout.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -476,11 +476,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, component::Type::Layout) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: component::Type::Layout.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
component::Type::Layout.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -491,11 +491,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, component::formatted::Type::LayoutField) {
Ok(self.as_layout_field())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: component::formatted::Type::LayoutField.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
component::formatted::Type::LayoutField.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -506,11 +506,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, component::formatted::Type::LayoutField) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: component::formatted::Type::LayoutField.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
component::formatted::Type::LayoutField.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -521,11 +521,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, component::formatted::Type::LayoutVariant) {
Ok(self.as_layout_variant())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: component::formatted::Type::LayoutVariant.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
component::formatted::Type::LayoutVariant.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -536,11 +536,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, component::formatted::Type::LayoutVariant) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: component::formatted::Type::LayoutVariant.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
component::formatted::Type::LayoutVariant.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -551,11 +551,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::LayoutRestriction) {
Ok(self.as_layout_restriction())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::LayoutRestriction.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::LayoutRestriction.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -566,11 +566,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::LayoutRestriction) {
Ok(treeldr::TId::new(self.data.id))
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::LayoutRestriction.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::LayoutRestriction.into(),
self.data.type_.clone(),
))
}
}

Expand All @@ -581,11 +581,11 @@ impl<M: Clone> Definition<M> {
if self.has_type(context, Type::List) {
Ok(self.as_list())
} else {
Err(NodeTypeInvalid {
id: self.data.id,
expected: Type::List.into(),
found: self.data.type_.clone(),
})
Err(NodeTypeInvalid::new(
self.data.id,
Type::List.into(),
self.data.type_.clone(),
))
}
}

Expand Down
Loading

0 comments on commit 0f6e93a

Please sign in to comment.