Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a37d176

Browse files
authoredApr 28, 2025··
Allow relates overrides to have lists (#406)
## Product change and motivation We fix one syntactic inconsistency, grammatically allowing list overrides for relation's roles: ``` define relation sub-rel, relates sub-role[] as super-role[]; ``` ## Implementation We relax the grammar to allow specialisations of relation's roles with ordering.
1 parent 7cbb621 commit a37d176

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed
 

‎rust/parser/define/type_.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ pub(in crate::parser) fn visit_relates_declaration(node: Node<'_>) -> Relates {
110110
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: related_label.to_string() }),
111111
};
112112
let specialised = if children.try_consume_expected(Rule::AS).is_some() {
113-
Some(visit_label(children.consume_expected(Rule::label)))
113+
let node = children.consume_any();
114+
let specialised = match node.as_rule() {
115+
Rule::label_list => TypeRefAny::List(visit_label_list(node)),
116+
Rule::label => TypeRefAny::Type(TypeRef::Label(visit_label(node))),
117+
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: node.to_string() }),
118+
};
119+
Some(specialised)
114120
} else {
115121
None
116122
};

‎rust/parser/statement/type_.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ fn visit_relates_constraint(node: Node<'_>) -> Relates {
127127
};
128128

129129
let specialised = if children.try_consume_expected(Rule::AS).is_some() {
130-
Some(visit_type_ref(children.consume_expected(Rule::type_ref)))
130+
let next = children.consume_any();
131+
let specialised = match next.as_rule() {
132+
Rule::type_ref => TypeRefAny::Type(visit_type_ref(next)),
133+
Rule::type_ref_list => TypeRefAny::List(visit_type_ref_list(next)),
134+
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: next.to_string() }),
135+
};
136+
Some(specialised)
131137
} else {
132138
None
133139
};

‎rust/parser/typeql.pest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ label_constraint = { LABEL ~ ( label_scoped | label ) }
9191
owns_constraint = { OWNS ~ type_ref_list
9292
| OWNS ~ type_ref
9393
}
94-
relates_constraint = { RELATES ~ type_ref_list
94+
relates_constraint = { RELATES ~ type_ref_list ~ ( AS ~ type_ref_list )?
9595
| RELATES ~ type_ref ~ ( AS ~ type_ref )?
9696
}
9797
plays_constraint = { PLAYS ~ type_ref }
@@ -211,7 +211,7 @@ owns_declaration = { OWNS ~ label_list
211211
| OWNS ~ label
212212
}
213213
plays_declaration = { PLAYS ~ label_scoped }
214-
relates_declaration = { RELATES ~ label_list
214+
relates_declaration = { RELATES ~ label_list ~ ( AS ~ label_list )?
215215
| RELATES ~ label ~ ( AS ~ label )?
216216
}
217217

‎rust/schema/definable/type_/capability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ impl fmt::Display for Owns {
126126
pub struct Relates {
127127
pub span: Option<Span>,
128128
pub related: TypeRefAny,
129-
pub specialised: Option<Label>,
129+
pub specialised: Option<TypeRefAny>,
130130
}
131131

132132
impl Relates {
133-
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<Label>) -> Self {
133+
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<TypeRefAny>) -> Self {
134134
Self { span, related, specialised }
135135
}
136136
}

‎rust/statement/type_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ impl fmt::Display for Owns {
248248
pub struct Relates {
249249
pub span: Option<Span>,
250250
pub related: TypeRefAny,
251-
pub specialised: Option<TypeRef>,
251+
pub specialised: Option<TypeRefAny>,
252252
}
253253

254254
impl Relates {
255-
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<TypeRef>) -> Self {
255+
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<TypeRefAny>) -> Self {
256256
Self { span, related, specialised }
257257
}
258258
}

0 commit comments

Comments
 (0)
Please sign in to comment.