diff --git a/rust/parser/define/type_.rs b/rust/parser/define/type_.rs index bb28deec..2988f341 100644 --- a/rust/parser/define/type_.rs +++ b/rust/parser/define/type_.rs @@ -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 }; diff --git a/rust/parser/statement/type_.rs b/rust/parser/statement/type_.rs index 09f92e5e..f1e546ed 100644 --- a/rust/parser/statement/type_.rs +++ b/rust/parser/statement/type_.rs @@ -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 }; diff --git a/rust/parser/typeql.pest b/rust/parser/typeql.pest index 653f55db..50ec900a 100644 --- a/rust/parser/typeql.pest +++ b/rust/parser/typeql.pest @@ -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 } @@ -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 )? } diff --git a/rust/schema/definable/type_/capability.rs b/rust/schema/definable/type_/capability.rs index 772ce62f..d3569ec6 100644 --- a/rust/schema/definable/type_/capability.rs +++ b/rust/schema/definable/type_/capability.rs @@ -126,11 +126,11 @@ impl fmt::Display for Owns { pub struct Relates { pub span: Option, pub related: TypeRefAny, - pub specialised: Option