Skip to content

Allow relates overrides to have lists #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion rust/parser/define/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ pub(in crate::parser) fn visit_relates_declaration(node: Node<'_>) -> Relates {
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: related_label.to_string() }),
};
let specialised = if children.try_consume_expected(Rule::AS).is_some() {
Some(visit_label(children.consume_expected(Rule::label)))
let node = children.consume_any();
let specialised = match node.as_rule() {
Rule::label_list => TypeRefAny::List(visit_label_list(node)),
Rule::label => TypeRefAny::Type(TypeRef::Label(visit_label(node))),
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: node.to_string() }),
};
Some(specialised)
} else {
None
};
Expand Down
8 changes: 7 additions & 1 deletion rust/parser/statement/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ fn visit_relates_constraint(node: Node<'_>) -> Relates {
};

let specialised = if children.try_consume_expected(Rule::AS).is_some() {
Some(visit_type_ref(children.consume_expected(Rule::type_ref)))
let next = children.consume_any();
let specialised = match next.as_rule() {
Rule::type_ref => TypeRefAny::Type(visit_type_ref(next)),
Rule::type_ref_list => TypeRefAny::List(visit_type_ref_list(next)),
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: next.to_string() }),
};
Some(specialised)
} else {
None
};
Expand Down
4 changes: 2 additions & 2 deletions rust/parser/typeql.pest
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ label_constraint = { LABEL ~ ( label_scoped | label ) }
owns_constraint = { OWNS ~ type_ref_list
| OWNS ~ type_ref
}
relates_constraint = { RELATES ~ type_ref_list
relates_constraint = { RELATES ~ type_ref_list ~ ( AS ~ type_ref_list )?
| RELATES ~ type_ref ~ ( AS ~ type_ref )?
}
plays_constraint = { PLAYS ~ type_ref }
Expand Down Expand Up @@ -211,7 +211,7 @@ owns_declaration = { OWNS ~ label_list
| OWNS ~ label
}
plays_declaration = { PLAYS ~ label_scoped }
relates_declaration = { RELATES ~ label_list
relates_declaration = { RELATES ~ label_list ~ ( AS ~ label_list )?
| RELATES ~ label ~ ( AS ~ label )?
}

Expand Down
4 changes: 2 additions & 2 deletions rust/schema/definable/type_/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ impl fmt::Display for Owns {
pub struct Relates {
pub span: Option<Span>,
pub related: TypeRefAny,
pub specialised: Option<Label>,
pub specialised: Option<TypeRefAny>,
}

impl Relates {
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<Label>) -> Self {
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<TypeRefAny>) -> Self {
Self { span, related, specialised }
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/statement/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ impl fmt::Display for Owns {
pub struct Relates {
pub span: Option<Span>,
pub related: TypeRefAny,
pub specialised: Option<TypeRef>,
pub specialised: Option<TypeRefAny>,
}

impl Relates {
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<TypeRef>) -> Self {
pub fn new(span: Option<Span>, related: TypeRefAny, specialised: Option<TypeRefAny>) -> Self {
Self { span, related, specialised }
}
}
Expand Down