Parse relations
This commit is contained in:
@@ -117,10 +117,14 @@ pub enum Item<'db> {
|
||||
/// Parses [Relation] from an [AstNode].
|
||||
#[salsa::tracked]
|
||||
pub fn relation<'db>(db: &'db dyn Database, ast: AstNode) -> Relation<'db> {
|
||||
todo!()
|
||||
let name = ast.expect_field(db, "relation").with_contents(db);
|
||||
let is_decision = ast.get_field(db, "decision").is_some();
|
||||
let ty = ty(db, ast.expect_field(db, "type"));
|
||||
Relation::new(db, name, is_decision, ty)
|
||||
}
|
||||
|
||||
/// A definition of a relation.
|
||||
// TODO: parse IO
|
||||
#[salsa::tracked]
|
||||
pub struct Relation<'db> {
|
||||
/// The name of this relation.
|
||||
@@ -129,9 +133,6 @@ pub struct Relation<'db> {
|
||||
/// Whether this relation is a decision.
|
||||
pub is_decision: bool,
|
||||
|
||||
/// The IO of this relation.
|
||||
pub io: ir::RelationIO,
|
||||
|
||||
/// This relation's abstract type (pure syntax).
|
||||
pub ty: WithAst<Type>,
|
||||
}
|
||||
@@ -462,6 +463,15 @@ impl ir::EnumRepr for RedundantBinaryOpKind {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a type.
|
||||
pub fn ty(db: &dyn Database, ast: AstNode) -> WithAst<Type> {
|
||||
ast.with(if let Some(ast) = ast.get_field(db, "named") {
|
||||
Type::Named(ast.contents(db).to_string())
|
||||
} else {
|
||||
Type::Tuple(ast.get_fields(db, "tuple").map(|ast| ty(db, ast)).collect())
|
||||
})
|
||||
}
|
||||
|
||||
/// An abstract type definition.
|
||||
///
|
||||
/// This just represents the literal, syntactic type representation, without
|
||||
@@ -469,7 +479,6 @@ impl ir::EnumRepr for RedundantBinaryOpKind {
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Type {
|
||||
Named(String),
|
||||
Primitive(ir::Type),
|
||||
Tuple(Vec<WithAst<Type>>),
|
||||
}
|
||||
|
||||
@@ -477,7 +486,6 @@ impl Display for Type {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Type::Named(name) => write!(f, "{name}"),
|
||||
Type::Primitive(ty) => write!(f, "{ty:?}"),
|
||||
Type::Tuple(els) => {
|
||||
let els = els
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user