Tweaks to AST data
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
use std::{convert::Infallible, fmt::Display, str::FromStr, sync::Arc};
|
||||
|
||||
use ir::EnumParse;
|
||||
use salsa::Update;
|
||||
use strum::{EnumDiscriminants, EnumIter};
|
||||
|
||||
use crate::prelude::*;
|
||||
@@ -160,17 +161,20 @@ pub struct TypeAlias<'db> {
|
||||
// TODO: after confirming that syntax is desirable, parse negation syntax
|
||||
#[salsa::tracked]
|
||||
pub fn rule<'db>(db: &'db dyn Database, ast: AstNode) -> Rule<'db> {
|
||||
let relation = ast.expect_field(db, "relation").with_contents(db);
|
||||
let relation = name(db, ast.expect_field(db, "relation"));
|
||||
let head = expr(db, ast.expect_field(db, "head"));
|
||||
let body = ast.get_field(db, "body").map(|ast| rule_body(db, ast));
|
||||
Rule::new(db, relation, head, body)
|
||||
Rule::new(db, ast, relation, head, body)
|
||||
}
|
||||
|
||||
/// An abstract rule.
|
||||
#[salsa::tracked]
|
||||
pub struct Rule<'db> {
|
||||
/// The AST node of this rule.
|
||||
pub ast: AstNode,
|
||||
|
||||
/// The name of the relation this rule stores to.
|
||||
pub relation: WithAst<String>,
|
||||
pub relation: Name,
|
||||
|
||||
/// The expression making up this rule's head.
|
||||
pub head: Expr,
|
||||
@@ -202,12 +206,15 @@ pub struct Import<'db> {
|
||||
#[salsa::tracked]
|
||||
pub fn assumption<'db>(db: &'db dyn Database, ast: AstNode) -> Assumption<'db> {
|
||||
let body = rule_body(db, ast.expect_field(db, "body"));
|
||||
Assumption::new(db, body)
|
||||
Assumption::new(db, ast, body)
|
||||
}
|
||||
|
||||
/// An abstract assumption.
|
||||
#[salsa::tracked]
|
||||
pub struct Assumption<'db> {
|
||||
/// The AST node of this assumption.
|
||||
pub ast: AstNode,
|
||||
|
||||
/// The assumption's rule body.
|
||||
pub body: RuleBody<'db>,
|
||||
}
|
||||
@@ -221,12 +228,15 @@ pub fn rule_body<'db>(db: &'db dyn Database, ast: AstNode) -> RuleBody<'db> {
|
||||
.map(|clause| expr(db, clause))
|
||||
.collect();
|
||||
|
||||
RuleBody::new(db, clauses)
|
||||
RuleBody::new(db, ast, clauses)
|
||||
}
|
||||
|
||||
/// An abstract rule body.
|
||||
#[salsa::tracked]
|
||||
pub struct RuleBody<'db> {
|
||||
/// The AST node of this rule body.
|
||||
pub ast: AstNode,
|
||||
|
||||
/// Each clause in the body.
|
||||
pub clauses: Vec<Expr>,
|
||||
}
|
||||
@@ -403,7 +413,7 @@ pub fn name(db: &dyn Database, ast: AstNode) -> Name {
|
||||
}
|
||||
|
||||
/// A named reference to some object.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Update)]
|
||||
pub struct Name {
|
||||
/// The AST node of the name.
|
||||
pub ast: AstNode,
|
||||
|
||||
Reference in New Issue
Block a user