From f80f505351046912149120a264b7a3902f14f9a3 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 13 Jul 2024 17:15:01 -0400 Subject: [PATCH] feat(yaml): more comprehensive grammar (#3400) --- .../src/generated/node_factory.rs | 185 +- .../src/generated/syntax_factory.rs | 320 +++- .../biome_yaml_syntax/src/generated/kind.rs | 29 +- .../biome_yaml_syntax/src/generated/macros.rs | 68 +- .../biome_yaml_syntax/src/generated/nodes.rs | 1597 +++++++++++++++-- .../src/generated/nodes_mut.rs | 160 +- xtask/codegen/src/generate_syntax_kinds.rs | 2 +- xtask/codegen/src/js_kinds_src.rs | 1 + xtask/codegen/src/yaml_kinds_src.rs | 20 +- xtask/codegen/yaml.ungram | 68 +- 10 files changed, 2237 insertions(+), 213 deletions(-) diff --git a/crates/biome_yaml_factory/src/generated/node_factory.rs b/crates/biome_yaml_factory/src/generated/node_factory.rs index a41eb448e4ce..12a5263b3992 100644 --- a/crates/biome_yaml_factory/src/generated/node_factory.rs +++ b/crates/biome_yaml_factory/src/generated/node_factory.rs @@ -7,10 +7,138 @@ use biome_yaml_syntax::{ YamlSyntaxElement as SyntaxElement, YamlSyntaxNode as SyntaxNode, YamlSyntaxToken as SyntaxToken, *, }; -pub fn yaml_document(content: YamlContentList) -> YamlDocument { - YamlDocument::unwrap_cast(SyntaxNode::new_detached( - YamlSyntaxKind::YAML_DOCUMENT, - [Some(SyntaxElement::Node(content.into_syntax()))], +pub fn yaml_array(items: YamlArrayItemList) -> YamlArray { + YamlArray::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_ARRAY, + [Some(SyntaxElement::Node(items.into_syntax()))], + )) +} +pub fn yaml_array_inline( + l_brack_token: SyntaxToken, + items: YamlArrayInlineList, + r_brack_token: SyntaxToken, +) -> YamlArrayInline { + YamlArrayInline::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_ARRAY_INLINE, + [ + Some(SyntaxElement::Token(l_brack_token)), + Some(SyntaxElement::Node(items.into_syntax())), + Some(SyntaxElement::Token(r_brack_token)), + ], + )) +} +pub fn yaml_array_item(minus_token: SyntaxToken, item: AnyYamlValue) -> YamlArrayItem { + YamlArrayItem::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_ARRAY_ITEM, + [ + Some(SyntaxElement::Token(minus_token)), + Some(SyntaxElement::Node(item.into_syntax())), + ], + )) +} +pub fn yaml_block_folded(r_angle_token: SyntaxToken, value: YamlBlockValue) -> YamlBlockFolded { + YamlBlockFolded::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_BLOCK_FOLDED, + [ + Some(SyntaxElement::Token(r_angle_token)), + Some(SyntaxElement::Node(value.into_syntax())), + ], + )) +} +pub fn yaml_block_literal( + bitwise_or_token: SyntaxToken, + value: YamlBlockValue, +) -> YamlBlockLiteral { + YamlBlockLiteral::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_BLOCK_LITERAL, + [ + Some(SyntaxElement::Token(bitwise_or_token)), + Some(SyntaxElement::Node(value.into_syntax())), + ], + )) +} +pub fn yaml_block_value(yaml_block_value_token: SyntaxToken) -> YamlBlockValue { + YamlBlockValue::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_BLOCK_VALUE, + [Some(SyntaxElement::Token(yaml_block_value_token))], + )) +} +pub fn yaml_boolean_value(value_token: SyntaxToken) -> YamlBooleanValue { + YamlBooleanValue::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_BOOLEAN_VALUE, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn yaml_document(body: AnyYamlValue) -> YamlDocumentBuilder { + YamlDocumentBuilder { + body, + dashdashdash_token: None, + dotdotdot_token: None, + } +} +pub struct YamlDocumentBuilder { + body: AnyYamlValue, + dashdashdash_token: Option, + dotdotdot_token: Option, +} +impl YamlDocumentBuilder { + pub fn with_dashdashdash_token(mut self, dashdashdash_token: SyntaxToken) -> Self { + self.dashdashdash_token = Some(dashdashdash_token); + self + } + pub fn with_dotdotdot_token(mut self, dotdotdot_token: SyntaxToken) -> Self { + self.dotdotdot_token = Some(dotdotdot_token); + self + } + pub fn build(self) -> YamlDocument { + YamlDocument::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_DOCUMENT, + [ + self.dashdashdash_token + .map(|token| SyntaxElement::Token(token)), + Some(SyntaxElement::Node(self.body.into_syntax())), + self.dotdotdot_token + .map(|token| SyntaxElement::Token(token)), + ], + )) + } +} +pub fn yaml_identifier(value_token: SyntaxToken) -> YamlIdentifier { + YamlIdentifier::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_IDENTIFIER, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn yaml_null_value(value_token: SyntaxToken) -> YamlNullValue { + YamlNullValue::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_NULL_VALUE, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn yaml_number_value(value_token: SyntaxToken) -> YamlNumberValue { + YamlNumberValue::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_NUMBER_VALUE, + [Some(SyntaxElement::Token(value_token))], + )) +} +pub fn yaml_object(members: YamlObjectMemberList) -> YamlObject { + YamlObject::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_OBJECT, + [Some(SyntaxElement::Node(members.into_syntax()))], + )) +} +pub fn yaml_object_member( + key: YamlIdentifier, + colon_token: SyntaxToken, + value: AnyYamlValue, +) -> YamlObjectMember { + YamlObjectMember::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_OBJECT_MEMBER, + [ + Some(SyntaxElement::Node(key.into_syntax())), + Some(SyntaxElement::Token(colon_token)), + Some(SyntaxElement::Node(value.into_syntax())), + ], )) } pub fn yaml_root(documents: YamlDocumentList, eof_token: SyntaxToken) -> YamlRootBuilder { @@ -41,25 +169,40 @@ impl YamlRootBuilder { )) } } -pub fn yaml_scalar(value_token: SyntaxToken) -> YamlScalar { - YamlScalar::unwrap_cast(SyntaxNode::new_detached( - YamlSyntaxKind::YAML_SCALAR, +pub fn yaml_string_value(value_token: SyntaxToken) -> YamlStringValue { + YamlStringValue::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_STRING_VALUE, [Some(SyntaxElement::Token(value_token))], )) } -pub fn yaml_string_literal(value_token: SyntaxToken) -> YamlStringLiteral { - YamlStringLiteral::unwrap_cast(SyntaxNode::new_detached( - YamlSyntaxKind::YAML_STRING_LITERAL, - [Some(SyntaxElement::Token(value_token))], +pub fn yaml_array_inline_list(items: I, separators: S) -> YamlArrayInlineList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + S: IntoIterator, + S::IntoIter: ExactSizeIterator, +{ + let mut items = items.into_iter(); + let mut separators = separators.into_iter(); + let length = items.len() + separators.len(); + YamlArrayInlineList::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_ARRAY_INLINE_LIST, + (0..length).map(|index| { + if index % 2 == 0 { + Some(items.next()?.into_syntax().into()) + } else { + Some(separators.next()?.into()) + } + }), )) } -pub fn yaml_content_list(items: I) -> YamlContentList +pub fn yaml_array_item_list(items: I) -> YamlArrayItemList where - I: IntoIterator, + I: IntoIterator, I::IntoIter: ExactSizeIterator, { - YamlContentList::unwrap_cast(SyntaxNode::new_detached( - YamlSyntaxKind::YAML_CONTENT_LIST, + YamlArrayItemList::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_ARRAY_ITEM_LIST, items .into_iter() .map(|item| Some(item.into_syntax().into())), @@ -77,6 +220,18 @@ where .map(|item| Some(item.into_syntax().into())), )) } +pub fn yaml_object_member_list(items: I) -> YamlObjectMemberList +where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, +{ + YamlObjectMemberList::unwrap_cast(SyntaxNode::new_detached( + YamlSyntaxKind::YAML_OBJECT_MEMBER_LIST, + items + .into_iter() + .map(|item| Some(item.into_syntax().into())), + )) +} pub fn yaml_bogus(slots: I) -> YamlBogus where I: IntoIterator>, diff --git a/crates/biome_yaml_factory/src/generated/syntax_factory.rs b/crates/biome_yaml_factory/src/generated/syntax_factory.rs index 9507b49a75b9..e5f739ae02e0 100644 --- a/crates/biome_yaml_factory/src/generated/syntax_factory.rs +++ b/crates/biome_yaml_factory/src/generated/syntax_factory.rs @@ -17,12 +17,194 @@ impl SyntaxFactory for YamlSyntaxFactory { YAML_BOGUS | YAML_BOGUS_VALUE => { RawSyntaxNode::new(kind, children.into_iter().map(Some)) } - YAML_DOCUMENT => { + YAML_ARRAY => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if YamlContentList::can_cast(element.kind()) { + if YamlArrayItemList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_ARRAY.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_ARRAY, children) + } + YAML_ARRAY_INLINE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T!['['] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if YamlArrayInlineList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![']'] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_ARRAY_INLINE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_ARRAY_INLINE, children) + } + YAML_ARRAY_ITEM => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [-] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyYamlValue::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_ARRAY_ITEM.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_ARRAY_ITEM, children) + } + YAML_BLOCK_FOLDED => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [>] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if YamlBlockValue::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_BLOCK_FOLDED.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_BLOCK_FOLDED, children) + } + YAML_BLOCK_LITERAL => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<2usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [|] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if YamlBlockValue::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_BLOCK_LITERAL.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_BLOCK_LITERAL, children) + } + YAML_BLOCK_VALUE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == YAML_BLOCK_VALUE { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_BLOCK_VALUE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_BLOCK_VALUE, children) + } + YAML_BOOLEAN_VALUE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == YAML_BOOLEAN_VALUE { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_BOOLEAN_VALUE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_BOOLEAN_VALUE, children) + } + YAML_DOCUMENT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [---] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyYamlValue::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [...] { slots.mark_present(); current_element = elements.next(); } @@ -36,26 +218,50 @@ impl SyntaxFactory for YamlSyntaxFactory { } slots.into_node(YAML_DOCUMENT, children) } - YAML_ROOT => { + YAML_IDENTIFIER => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T![UNICODE_BOM] { + if element.kind() == YAML_IDENTIFIER { slots.mark_present(); current_element = elements.next(); } } slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_IDENTIFIER.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_IDENTIFIER, children) + } + YAML_NULL_VALUE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if YamlDocumentList::can_cast(element.kind()) { + if element.kind() == YAML_NULL_VALUE { slots.mark_present(); current_element = elements.next(); } } slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_NULL_VALUE.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_NULL_VALUE, children) + } + YAML_NUMBER_VALUE => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == T![EOF] { + if element.kind() == YAML_NUMBER_VALUE { slots.mark_present(); current_element = elements.next(); } @@ -63,18 +269,84 @@ impl SyntaxFactory for YamlSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - YAML_ROOT.to_bogus(), + YAML_NUMBER_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(YAML_ROOT, children) + slots.into_node(YAML_NUMBER_VALUE, children) } - YAML_SCALAR => { + YAML_OBJECT => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == YAML_SCALAR { + if YamlObjectMemberList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_OBJECT.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_OBJECT, children) + } + YAML_OBJECT_MEMBER => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if YamlIdentifier::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T ! [:] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if AnyYamlValue::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if current_element.is_some() { + return RawSyntaxNode::new( + YAML_OBJECT_MEMBER.to_bogus(), + children.into_iter().map(Some), + ); + } + slots.into_node(YAML_OBJECT_MEMBER, children) + } + YAML_ROOT => { + let mut elements = (&children).into_iter(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![UNICODE_BOM] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if YamlDocumentList::can_cast(element.kind()) { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); + if let Some(element) = ¤t_element { + if element.kind() == T![EOF] { slots.mark_present(); current_element = elements.next(); } @@ -82,18 +354,18 @@ impl SyntaxFactory for YamlSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - YAML_SCALAR.to_bogus(), + YAML_ROOT.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(YAML_SCALAR, children) + slots.into_node(YAML_ROOT, children) } - YAML_STRING_LITERAL => { + YAML_STRING_VALUE => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<1usize> = RawNodeSlots::default(); let mut current_element = elements.next(); if let Some(element) = ¤t_element { - if element.kind() == YAML_STRING_LITERAL { + if element.kind() == YAML_STRING_VALUE { slots.mark_present(); current_element = elements.next(); } @@ -101,18 +373,28 @@ impl SyntaxFactory for YamlSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - YAML_STRING_LITERAL.to_bogus(), + YAML_STRING_VALUE.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(YAML_STRING_LITERAL, children) + slots.into_node(YAML_STRING_VALUE, children) } - YAML_CONTENT_LIST => { - Self::make_node_list_syntax(kind, children, AnyYamlContent::can_cast) + YAML_ARRAY_INLINE_LIST => Self::make_separated_list_syntax( + kind, + children, + AnyYamlScalar::can_cast, + T ! [,], + true, + ), + YAML_ARRAY_ITEM_LIST => { + Self::make_node_list_syntax(kind, children, YamlArrayItem::can_cast) } YAML_DOCUMENT_LIST => { Self::make_node_list_syntax(kind, children, YamlDocument::can_cast) } + YAML_OBJECT_MEMBER_LIST => { + Self::make_node_list_syntax(kind, children, YamlObjectMember::can_cast) + } _ => unreachable!("Is {:?} a token?", kind), } } diff --git a/crates/biome_yaml_syntax/src/generated/kind.rs b/crates/biome_yaml_syntax/src/generated/kind.rs index 08b3e68bfb54..78d574c1e1bc 100644 --- a/crates/biome_yaml_syntax/src/generated/kind.rs +++ b/crates/biome_yaml_syntax/src/generated/kind.rs @@ -34,8 +34,12 @@ pub enum YamlSyntaxKind { DOC_START, DOC_END, NULL_KW, - YAML_STRING_LITERAL, - YAML_SCALAR, + YAML_STRING_VALUE, + YAML_NUMBER_VALUE, + YAML_BOOLEAN_VALUE, + YAML_NULL_VALUE, + YAML_BLOCK_VALUE, + YAML_IDENTIFIER, NEWLINE, WHITESPACE, IDENT, @@ -43,7 +47,16 @@ pub enum YamlSyntaxKind { YAML_ROOT, YAML_DOCUMENT_LIST, YAML_DOCUMENT, - YAML_CONTENT_LIST, + YAML_ARRAY_INLINE, + YAML_ARRAY_INLINE_LIST, + YAML_OBJECT, + YAML_OBJECT_MEMBER, + YAML_OBJECT_MEMBER_LIST, + YAML_ARRAY, + YAML_ARRAY_ITEM, + YAML_ARRAY_ITEM_LIST, + YAML_BLOCK_LITERAL, + YAML_BLOCK_FOLDED, YAML_BOGUS, YAML_BOGUS_VALUE, #[doc(hidden)] @@ -61,13 +74,17 @@ impl YamlSyntaxKind { } pub const fn is_literal(self) -> bool { match self { - YAML_STRING_LITERAL | YAML_SCALAR => true, + YAML_STRING_VALUE | YAML_NUMBER_VALUE | YAML_BOOLEAN_VALUE | YAML_NULL_VALUE + | YAML_BLOCK_VALUE | YAML_IDENTIFIER => true, _ => false, } } pub const fn is_list(self) -> bool { match self { - YAML_DOCUMENT_LIST | YAML_CONTENT_LIST => true, + YAML_DOCUMENT_LIST + | YAML_ARRAY_INLINE_LIST + | YAML_OBJECT_MEMBER_LIST + | YAML_ARRAY_ITEM_LIST => true, _ => false, } } @@ -101,7 +118,7 @@ impl YamlSyntaxKind { DOC_START => "---", DOC_END => "...", NULL_KW => "null", - YAML_STRING_LITERAL => "string literal", + YAML_STRING_VALUE => "string value", _ => return None, }; Some(tok) diff --git a/crates/biome_yaml_syntax/src/generated/macros.rs b/crates/biome_yaml_syntax/src/generated/macros.rs index 7dce5b35acac..f5df96f9d61d 100644 --- a/crates/biome_yaml_syntax/src/generated/macros.rs +++ b/crates/biome_yaml_syntax/src/generated/macros.rs @@ -16,20 +16,64 @@ macro_rules! map_syntax_node { ($ node : expr , $ pattern : pat => $ body : expr) => { match $node { node => match $crate::YamlSyntaxNode::kind(&node) { + $crate::YamlSyntaxKind::YAML_ARRAY => { + let $pattern = unsafe { $crate::YamlArray::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_ARRAY_INLINE => { + let $pattern = unsafe { $crate::YamlArrayInline::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_ARRAY_ITEM => { + let $pattern = unsafe { $crate::YamlArrayItem::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_BLOCK_FOLDED => { + let $pattern = unsafe { $crate::YamlBlockFolded::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_BLOCK_LITERAL => { + let $pattern = unsafe { $crate::YamlBlockLiteral::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_BLOCK_VALUE => { + let $pattern = unsafe { $crate::YamlBlockValue::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_BOOLEAN_VALUE => { + let $pattern = unsafe { $crate::YamlBooleanValue::new_unchecked(node) }; + $body + } $crate::YamlSyntaxKind::YAML_DOCUMENT => { let $pattern = unsafe { $crate::YamlDocument::new_unchecked(node) }; $body } - $crate::YamlSyntaxKind::YAML_ROOT => { - let $pattern = unsafe { $crate::YamlRoot::new_unchecked(node) }; + $crate::YamlSyntaxKind::YAML_IDENTIFIER => { + let $pattern = unsafe { $crate::YamlIdentifier::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_NULL_VALUE => { + let $pattern = unsafe { $crate::YamlNullValue::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_NUMBER_VALUE => { + let $pattern = unsafe { $crate::YamlNumberValue::new_unchecked(node) }; $body } - $crate::YamlSyntaxKind::YAML_SCALAR => { - let $pattern = unsafe { $crate::YamlScalar::new_unchecked(node) }; + $crate::YamlSyntaxKind::YAML_OBJECT => { + let $pattern = unsafe { $crate::YamlObject::new_unchecked(node) }; $body } - $crate::YamlSyntaxKind::YAML_STRING_LITERAL => { - let $pattern = unsafe { $crate::YamlStringLiteral::new_unchecked(node) }; + $crate::YamlSyntaxKind::YAML_OBJECT_MEMBER => { + let $pattern = unsafe { $crate::YamlObjectMember::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_ROOT => { + let $pattern = unsafe { $crate::YamlRoot::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_STRING_VALUE => { + let $pattern = unsafe { $crate::YamlStringValue::new_unchecked(node) }; $body } $crate::YamlSyntaxKind::YAML_BOGUS => { @@ -40,14 +84,22 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::YamlBogusValue::new_unchecked(node) }; $body } - $crate::YamlSyntaxKind::YAML_CONTENT_LIST => { - let $pattern = unsafe { $crate::YamlContentList::new_unchecked(node) }; + $crate::YamlSyntaxKind::YAML_ARRAY_INLINE_LIST => { + let $pattern = unsafe { $crate::YamlArrayInlineList::new_unchecked(node) }; + $body + } + $crate::YamlSyntaxKind::YAML_ARRAY_ITEM_LIST => { + let $pattern = unsafe { $crate::YamlArrayItemList::new_unchecked(node) }; $body } $crate::YamlSyntaxKind::YAML_DOCUMENT_LIST => { let $pattern = unsafe { $crate::YamlDocumentList::new_unchecked(node) }; $body } + $crate::YamlSyntaxKind::YAML_OBJECT_MEMBER_LIST => { + let $pattern = unsafe { $crate::YamlObjectMemberList::new_unchecked(node) }; + $body + } _ => unreachable!(), }, } diff --git a/crates/biome_yaml_syntax/src/generated/nodes.rs b/crates/biome_yaml_syntax/src/generated/nodes.rs index dac3d48447de..2a07f0e00060 100644 --- a/crates/biome_yaml_syntax/src/generated/nodes.rs +++ b/crates/biome_yaml_syntax/src/generated/nodes.rs @@ -25,6 +25,283 @@ use std::fmt::{Debug, Formatter}; #[allow(dead_code)] pub(crate) const SLOT_MAP_EMPTY_VALUE: u8 = u8::MAX; #[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlArray { + pub(crate) syntax: SyntaxNode, +} +impl YamlArray { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlArrayFields { + YamlArrayFields { + items: self.items(), + } + } + pub fn items(&self) -> YamlArrayItemList { + support::list(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlArray { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlArrayFields { + pub items: YamlArrayItemList, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlArrayInline { + pub(crate) syntax: SyntaxNode, +} +impl YamlArrayInline { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlArrayInlineFields { + YamlArrayInlineFields { + l_brack_token: self.l_brack_token(), + items: self.items(), + r_brack_token: self.r_brack_token(), + } + } + pub fn l_brack_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn items(&self) -> YamlArrayInlineList { + support::list(&self.syntax, 1usize) + } + pub fn r_brack_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlArrayInline { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlArrayInlineFields { + pub l_brack_token: SyntaxResult, + pub items: YamlArrayInlineList, + pub r_brack_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlArrayItem { + pub(crate) syntax: SyntaxNode, +} +impl YamlArrayItem { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlArrayItemFields { + YamlArrayItemFields { + minus_token: self.minus_token(), + item: self.item(), + } + } + pub fn minus_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn item(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlArrayItem { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlArrayItemFields { + pub minus_token: SyntaxResult, + pub item: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlBlockFolded { + pub(crate) syntax: SyntaxNode, +} +impl YamlBlockFolded { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlBlockFoldedFields { + YamlBlockFoldedFields { + r_angle_token: self.r_angle_token(), + value: self.value(), + } + } + pub fn r_angle_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn value(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlBlockFolded { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlBlockFoldedFields { + pub r_angle_token: SyntaxResult, + pub value: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlBlockLiteral { + pub(crate) syntax: SyntaxNode, +} +impl YamlBlockLiteral { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlBlockLiteralFields { + YamlBlockLiteralFields { + bitwise_or_token: self.bitwise_or_token(), + value: self.value(), + } + } + pub fn bitwise_or_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } + pub fn value(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlBlockLiteral { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlBlockLiteralFields { + pub bitwise_or_token: SyntaxResult, + pub value: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlBlockValue { + pub(crate) syntax: SyntaxNode, +} +impl YamlBlockValue { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlBlockValueFields { + YamlBlockValueFields { + yaml_block_value_token: self.yaml_block_value_token(), + } + } + pub fn yaml_block_value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlBlockValue { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlBlockValueFields { + pub yaml_block_value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlBooleanValue { + pub(crate) syntax: SyntaxNode, +} +impl YamlBooleanValue { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlBooleanValueFields { + YamlBooleanValueFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlBooleanValue { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlBooleanValueFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] pub struct YamlDocument { pub(crate) syntax: SyntaxNode, } @@ -40,11 +317,19 @@ impl YamlDocument { } pub fn as_fields(&self) -> YamlDocumentFields { YamlDocumentFields { - content: self.content(), + dashdashdash_token: self.dashdashdash_token(), + body: self.body(), + dotdotdot_token: self.dotdotdot_token(), } } - pub fn content(&self) -> YamlContentList { - support::list(&self.syntax, 0usize) + pub fn dashdashdash_token(&self) -> Option { + support::token(&self.syntax, 0usize) + } + pub fn body(&self) -> SyntaxResult { + support::required_node(&self.syntax, 1usize) + } + pub fn dotdotdot_token(&self) -> Option { + support::token(&self.syntax, 2usize) } } #[cfg(feature = "serde")] @@ -58,13 +343,15 @@ impl Serialize for YamlDocument { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct YamlDocumentFields { - pub content: YamlContentList, + pub dashdashdash_token: Option, + pub body: SyntaxResult, + pub dotdotdot_token: Option, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct YamlRoot { +pub struct YamlIdentifier { pub(crate) syntax: SyntaxNode, } -impl YamlRoot { +impl YamlIdentifier { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -74,25 +361,17 @@ impl YamlRoot { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> YamlRootFields { - YamlRootFields { - bom_token: self.bom_token(), - documents: self.documents(), - eof_token: self.eof_token(), + pub fn as_fields(&self) -> YamlIdentifierFields { + YamlIdentifierFields { + value_token: self.value_token(), } } - pub fn bom_token(&self) -> Option { - support::token(&self.syntax, 0usize) - } - pub fn documents(&self) -> YamlDocumentList { - support::list(&self.syntax, 1usize) - } - pub fn eof_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 2usize) + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) } } #[cfg(feature = "serde")] -impl Serialize for YamlRoot { +impl Serialize for YamlIdentifier { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -101,16 +380,14 @@ impl Serialize for YamlRoot { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct YamlRootFields { - pub bom_token: Option, - pub documents: YamlDocumentList, - pub eof_token: SyntaxResult, +pub struct YamlIdentifierFields { + pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct YamlScalar { +pub struct YamlNullValue { pub(crate) syntax: SyntaxNode, } -impl YamlScalar { +impl YamlNullValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -120,8 +397,8 @@ impl YamlScalar { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> YamlScalarFields { - YamlScalarFields { + pub fn as_fields(&self) -> YamlNullValueFields { + YamlNullValueFields { value_token: self.value_token(), } } @@ -130,7 +407,7 @@ impl YamlScalar { } } #[cfg(feature = "serde")] -impl Serialize for YamlScalar { +impl Serialize for YamlNullValue { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -139,14 +416,14 @@ impl Serialize for YamlScalar { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct YamlScalarFields { +pub struct YamlNullValueFields { pub value_token: SyntaxResult, } #[derive(Clone, PartialEq, Eq, Hash)] -pub struct YamlStringLiteral { +pub struct YamlNumberValue { pub(crate) syntax: SyntaxNode, } -impl YamlStringLiteral { +impl YamlNumberValue { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -156,8 +433,8 @@ impl YamlStringLiteral { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } - pub fn as_fields(&self) -> YamlStringLiteralFields { - YamlStringLiteralFields { + pub fn as_fields(&self) -> YamlNumberValueFields { + YamlNumberValueFields { value_token: self.value_token(), } } @@ -166,7 +443,43 @@ impl YamlStringLiteral { } } #[cfg(feature = "serde")] -impl Serialize for YamlStringLiteral { +impl Serialize for YamlNumberValue { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlNumberValueFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlObject { + pub(crate) syntax: SyntaxNode, +} +impl YamlObject { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlObjectFields { + YamlObjectFields { + members: self.members(), + } + } + pub fn members(&self) -> YamlObjectMemberList { + support::list(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlObject { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -174,36 +487,718 @@ impl Serialize for YamlStringLiteral { self.as_fields().serialize(serializer) } } -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct YamlStringLiteralFields { - pub value_token: SyntaxResult, -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] -pub enum AnyYamlContent { - YamlBogusValue(YamlBogusValue), - YamlScalar(YamlScalar), +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlObjectFields { + pub members: YamlObjectMemberList, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlObjectMember { + pub(crate) syntax: SyntaxNode, +} +impl YamlObjectMember { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlObjectMemberFields { + YamlObjectMemberFields { + key: self.key(), + colon_token: self.colon_token(), + value: self.value(), + } + } + pub fn key(&self) -> SyntaxResult { + support::required_node(&self.syntax, 0usize) + } + pub fn colon_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 1usize) + } + pub fn value(&self) -> SyntaxResult { + support::required_node(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlObjectMember { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlObjectMemberFields { + pub key: SyntaxResult, + pub colon_token: SyntaxResult, + pub value: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlRoot { + pub(crate) syntax: SyntaxNode, +} +impl YamlRoot { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlRootFields { + YamlRootFields { + bom_token: self.bom_token(), + documents: self.documents(), + eof_token: self.eof_token(), + } + } + pub fn bom_token(&self) -> Option { + support::token(&self.syntax, 0usize) + } + pub fn documents(&self) -> YamlDocumentList { + support::list(&self.syntax, 1usize) + } + pub fn eof_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 2usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlRoot { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlRootFields { + pub bom_token: Option, + pub documents: YamlDocumentList, + pub eof_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct YamlStringValue { + pub(crate) syntax: SyntaxNode, +} +impl YamlStringValue { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { syntax } + } + pub fn as_fields(&self) -> YamlStringValueFields { + YamlStringValueFields { + value_token: self.value_token(), + } + } + pub fn value_token(&self) -> SyntaxResult { + support::required_token(&self.syntax, 0usize) + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlStringValue { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.as_fields().serialize(serializer) + } +} +#[cfg_attr(feature = "serde", derive(Serialize))] +pub struct YamlStringValueFields { + pub value_token: SyntaxResult, +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyYamlScalar { + YamlBooleanValue(YamlBooleanValue), + YamlNullValue(YamlNullValue), + YamlNumberValue(YamlNumberValue), + YamlStringValue(YamlStringValue), +} +impl AnyYamlScalar { + pub fn as_yaml_boolean_value(&self) -> Option<&YamlBooleanValue> { + match &self { + AnyYamlScalar::YamlBooleanValue(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_null_value(&self) -> Option<&YamlNullValue> { + match &self { + AnyYamlScalar::YamlNullValue(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_number_value(&self) -> Option<&YamlNumberValue> { + match &self { + AnyYamlScalar::YamlNumberValue(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_string_value(&self) -> Option<&YamlStringValue> { + match &self { + AnyYamlScalar::YamlStringValue(item) => Some(item), + _ => None, + } + } +} +#[derive(Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize))] +pub enum AnyYamlValue { + AnyYamlScalar(AnyYamlScalar), + YamlArray(YamlArray), + YamlArrayInline(YamlArrayInline), + YamlBogusValue(YamlBogusValue), + YamlObject(YamlObject), +} +impl AnyYamlValue { + pub fn as_any_yaml_scalar(&self) -> Option<&AnyYamlScalar> { + match &self { + AnyYamlValue::AnyYamlScalar(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_array(&self) -> Option<&YamlArray> { + match &self { + AnyYamlValue::YamlArray(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_array_inline(&self) -> Option<&YamlArrayInline> { + match &self { + AnyYamlValue::YamlArrayInline(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_bogus_value(&self) -> Option<&YamlBogusValue> { + match &self { + AnyYamlValue::YamlBogusValue(item) => Some(item), + _ => None, + } + } + pub fn as_yaml_object(&self) -> Option<&YamlObject> { + match &self { + AnyYamlValue::YamlObject(item) => Some(item), + _ => None, + } + } +} +impl AstNode for YamlArray { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_ARRAY as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_ARRAY + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlArray { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlArray") + .field("items", &self.items()) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlArray) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlArray) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlArrayInline { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_ARRAY_INLINE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_ARRAY_INLINE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlArrayInline { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlArrayInline") + .field( + "l_brack_token", + &support::DebugSyntaxResult(self.l_brack_token()), + ) + .field("items", &self.items()) + .field( + "r_brack_token", + &support::DebugSyntaxResult(self.r_brack_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlArrayInline) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlArrayInline) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlArrayItem { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_ARRAY_ITEM as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_ARRAY_ITEM + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlArrayItem { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlArrayItem") + .field( + "minus_token", + &support::DebugSyntaxResult(self.minus_token()), + ) + .field("item", &support::DebugSyntaxResult(self.item())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlArrayItem) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlArrayItem) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlBlockFolded { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_BLOCK_FOLDED as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_BLOCK_FOLDED + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlBlockFolded { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlBlockFolded") + .field( + "r_angle_token", + &support::DebugSyntaxResult(self.r_angle_token()), + ) + .field("value", &support::DebugSyntaxResult(self.value())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlBlockFolded) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlBlockFolded) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlBlockLiteral { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_BLOCK_LITERAL as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_BLOCK_LITERAL + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlBlockLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlBlockLiteral") + .field( + "bitwise_or_token", + &support::DebugSyntaxResult(self.bitwise_or_token()), + ) + .field("value", &support::DebugSyntaxResult(self.value())) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlBlockLiteral) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlBlockLiteral) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlBlockValue { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_BLOCK_VALUE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_BLOCK_VALUE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlBlockValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlBlockValue") + .field( + "yaml_block_value_token", + &support::DebugSyntaxResult(self.yaml_block_value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlBlockValue) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlBlockValue) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlBooleanValue { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_BOOLEAN_VALUE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_BOOLEAN_VALUE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlBooleanValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlBooleanValue") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlBooleanValue) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlBooleanValue) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlDocument { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_DOCUMENT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_DOCUMENT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlDocument { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlDocument") + .field( + "dashdashdash_token", + &support::DebugOptionalElement(self.dashdashdash_token()), + ) + .field("body", &support::DebugSyntaxResult(self.body())) + .field( + "dotdotdot_token", + &support::DebugOptionalElement(self.dotdotdot_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlDocument) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlDocument) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlIdentifier { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_IDENTIFIER as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_IDENTIFIER + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlIdentifier { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlIdentifier") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlIdentifier) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlIdentifier) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlNullValue { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_NULL_VALUE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_NULL_VALUE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlNullValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlNullValue") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlNullValue) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlNullValue) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlNumberValue { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_NUMBER_VALUE as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_NUMBER_VALUE + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlNumberValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlNumberValue") + .field( + "value_token", + &support::DebugSyntaxResult(self.value_token()), + ) + .finish() + } +} +impl From for SyntaxNode { + fn from(n: YamlNumberValue) -> SyntaxNode { + n.syntax + } +} +impl From for SyntaxElement { + fn from(n: YamlNumberValue) -> SyntaxElement { + n.syntax.into() + } +} +impl AstNode for YamlObject { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_OBJECT as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_OBJECT + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } + fn into_syntax(self) -> SyntaxNode { + self.syntax + } +} +impl std::fmt::Debug for YamlObject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("YamlObject") + .field("members", &self.members()) + .finish() + } } -impl AnyYamlContent { - pub fn as_yaml_bogus_value(&self) -> Option<&YamlBogusValue> { - match &self { - AnyYamlContent::YamlBogusValue(item) => Some(item), - _ => None, - } +impl From for SyntaxNode { + fn from(n: YamlObject) -> SyntaxNode { + n.syntax } - pub fn as_yaml_scalar(&self) -> Option<&YamlScalar> { - match &self { - AnyYamlContent::YamlScalar(item) => Some(item), - _ => None, - } +} +impl From for SyntaxElement { + fn from(n: YamlObject) -> SyntaxElement { + n.syntax.into() } } -impl AstNode for YamlDocument { +impl AstNode for YamlObjectMember { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(YAML_DOCUMENT as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_OBJECT_MEMBER as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == YAML_DOCUMENT + kind == YAML_OBJECT_MEMBER } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -219,20 +1214,25 @@ impl AstNode for YamlDocument { self.syntax } } -impl std::fmt::Debug for YamlDocument { +impl std::fmt::Debug for YamlObjectMember { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("YamlDocument") - .field("content", &self.content()) + f.debug_struct("YamlObjectMember") + .field("key", &support::DebugSyntaxResult(self.key())) + .field( + "colon_token", + &support::DebugSyntaxResult(self.colon_token()), + ) + .field("value", &support::DebugSyntaxResult(self.value())) .finish() } } -impl From for SyntaxNode { - fn from(n: YamlDocument) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: YamlObjectMember) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: YamlDocument) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: YamlObjectMember) -> SyntaxElement { n.syntax.into() } } @@ -279,12 +1279,12 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for YamlScalar { +impl AstNode for YamlStringValue { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(YAML_SCALAR as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_STRING_VALUE as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == YAML_SCALAR + kind == YAML_STRING_VALUE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { @@ -300,9 +1300,9 @@ impl AstNode for YamlScalar { self.syntax } } -impl std::fmt::Debug for YamlScalar { +impl std::fmt::Debug for YamlStringValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("YamlScalar") + f.debug_struct("YamlStringValue") .field( "value_token", &support::DebugSyntaxResult(self.value_token()), @@ -310,117 +1310,238 @@ impl std::fmt::Debug for YamlScalar { .finish() } } -impl From for SyntaxNode { - fn from(n: YamlScalar) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: YamlStringValue) -> SyntaxNode { n.syntax } } -impl From for SyntaxElement { - fn from(n: YamlScalar) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: YamlStringValue) -> SyntaxElement { n.syntax.into() } } -impl AstNode for YamlStringLiteral { +impl From for AnyYamlScalar { + fn from(node: YamlBooleanValue) -> AnyYamlScalar { + AnyYamlScalar::YamlBooleanValue(node) + } +} +impl From for AnyYamlScalar { + fn from(node: YamlNullValue) -> AnyYamlScalar { + AnyYamlScalar::YamlNullValue(node) + } +} +impl From for AnyYamlScalar { + fn from(node: YamlNumberValue) -> AnyYamlScalar { + AnyYamlScalar::YamlNumberValue(node) + } +} +impl From for AnyYamlScalar { + fn from(node: YamlStringValue) -> AnyYamlScalar { + AnyYamlScalar::YamlStringValue(node) + } +} +impl AstNode for AnyYamlScalar { type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(YAML_STRING_LITERAL as u16)); + const KIND_SET: SyntaxKindSet = YamlBooleanValue::KIND_SET + .union(YamlNullValue::KIND_SET) + .union(YamlNumberValue::KIND_SET) + .union(YamlStringValue::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - kind == YAML_STRING_LITERAL + matches!( + kind, + YAML_BOOLEAN_VALUE | YAML_NULL_VALUE | YAML_NUMBER_VALUE | YAML_STRING_VALUE + ) } fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } + let res = match syntax.kind() { + YAML_BOOLEAN_VALUE => AnyYamlScalar::YamlBooleanValue(YamlBooleanValue { syntax }), + YAML_NULL_VALUE => AnyYamlScalar::YamlNullValue(YamlNullValue { syntax }), + YAML_NUMBER_VALUE => AnyYamlScalar::YamlNumberValue(YamlNumberValue { syntax }), + YAML_STRING_VALUE => AnyYamlScalar::YamlStringValue(YamlStringValue { syntax }), + _ => return None, + }; + Some(res) } fn syntax(&self) -> &SyntaxNode { - &self.syntax + match self { + AnyYamlScalar::YamlBooleanValue(it) => &it.syntax, + AnyYamlScalar::YamlNullValue(it) => &it.syntax, + AnyYamlScalar::YamlNumberValue(it) => &it.syntax, + AnyYamlScalar::YamlStringValue(it) => &it.syntax, + } } fn into_syntax(self) -> SyntaxNode { - self.syntax + match self { + AnyYamlScalar::YamlBooleanValue(it) => it.syntax, + AnyYamlScalar::YamlNullValue(it) => it.syntax, + AnyYamlScalar::YamlNumberValue(it) => it.syntax, + AnyYamlScalar::YamlStringValue(it) => it.syntax, + } } } -impl std::fmt::Debug for YamlStringLiteral { +impl std::fmt::Debug for AnyYamlScalar { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("YamlStringLiteral") - .field( - "value_token", - &support::DebugSyntaxResult(self.value_token()), - ) - .finish() + match self { + AnyYamlScalar::YamlBooleanValue(it) => std::fmt::Debug::fmt(it, f), + AnyYamlScalar::YamlNullValue(it) => std::fmt::Debug::fmt(it, f), + AnyYamlScalar::YamlNumberValue(it) => std::fmt::Debug::fmt(it, f), + AnyYamlScalar::YamlStringValue(it) => std::fmt::Debug::fmt(it, f), + } } } -impl From for SyntaxNode { - fn from(n: YamlStringLiteral) -> SyntaxNode { - n.syntax +impl From for SyntaxNode { + fn from(n: AnyYamlScalar) -> SyntaxNode { + match n { + AnyYamlScalar::YamlBooleanValue(it) => it.into(), + AnyYamlScalar::YamlNullValue(it) => it.into(), + AnyYamlScalar::YamlNumberValue(it) => it.into(), + AnyYamlScalar::YamlStringValue(it) => it.into(), + } } } -impl From for SyntaxElement { - fn from(n: YamlStringLiteral) -> SyntaxElement { - n.syntax.into() +impl From for SyntaxElement { + fn from(n: AnyYamlScalar) -> SyntaxElement { + let node: SyntaxNode = n.into(); + node.into() + } +} +impl From for AnyYamlValue { + fn from(node: YamlArray) -> AnyYamlValue { + AnyYamlValue::YamlArray(node) } } -impl From for AnyYamlContent { - fn from(node: YamlBogusValue) -> AnyYamlContent { - AnyYamlContent::YamlBogusValue(node) +impl From for AnyYamlValue { + fn from(node: YamlArrayInline) -> AnyYamlValue { + AnyYamlValue::YamlArrayInline(node) } } -impl From for AnyYamlContent { - fn from(node: YamlScalar) -> AnyYamlContent { - AnyYamlContent::YamlScalar(node) +impl From for AnyYamlValue { + fn from(node: YamlBogusValue) -> AnyYamlValue { + AnyYamlValue::YamlBogusValue(node) } } -impl AstNode for AnyYamlContent { +impl From for AnyYamlValue { + fn from(node: YamlObject) -> AnyYamlValue { + AnyYamlValue::YamlObject(node) + } +} +impl AstNode for AnyYamlValue { type Language = Language; - const KIND_SET: SyntaxKindSet = YamlBogusValue::KIND_SET.union(YamlScalar::KIND_SET); + const KIND_SET: SyntaxKindSet = AnyYamlScalar::KIND_SET + .union(YamlArray::KIND_SET) + .union(YamlArrayInline::KIND_SET) + .union(YamlBogusValue::KIND_SET) + .union(YamlObject::KIND_SET); fn can_cast(kind: SyntaxKind) -> bool { - matches!(kind, YAML_BOGUS_VALUE | YAML_SCALAR) + match kind { + YAML_ARRAY | YAML_ARRAY_INLINE | YAML_BOGUS_VALUE | YAML_OBJECT => true, + k if AnyYamlScalar::can_cast(k) => true, + _ => false, + } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - YAML_BOGUS_VALUE => AnyYamlContent::YamlBogusValue(YamlBogusValue { syntax }), - YAML_SCALAR => AnyYamlContent::YamlScalar(YamlScalar { syntax }), - _ => return None, + YAML_ARRAY => AnyYamlValue::YamlArray(YamlArray { syntax }), + YAML_ARRAY_INLINE => AnyYamlValue::YamlArrayInline(YamlArrayInline { syntax }), + YAML_BOGUS_VALUE => AnyYamlValue::YamlBogusValue(YamlBogusValue { syntax }), + YAML_OBJECT => AnyYamlValue::YamlObject(YamlObject { syntax }), + _ => { + if let Some(any_yaml_scalar) = AnyYamlScalar::cast(syntax) { + return Some(AnyYamlValue::AnyYamlScalar(any_yaml_scalar)); + } + return None; + } }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - AnyYamlContent::YamlBogusValue(it) => &it.syntax, - AnyYamlContent::YamlScalar(it) => &it.syntax, + AnyYamlValue::YamlArray(it) => &it.syntax, + AnyYamlValue::YamlArrayInline(it) => &it.syntax, + AnyYamlValue::YamlBogusValue(it) => &it.syntax, + AnyYamlValue::YamlObject(it) => &it.syntax, + AnyYamlValue::AnyYamlScalar(it) => it.syntax(), } } fn into_syntax(self) -> SyntaxNode { match self { - AnyYamlContent::YamlBogusValue(it) => it.syntax, - AnyYamlContent::YamlScalar(it) => it.syntax, + AnyYamlValue::YamlArray(it) => it.syntax, + AnyYamlValue::YamlArrayInline(it) => it.syntax, + AnyYamlValue::YamlBogusValue(it) => it.syntax, + AnyYamlValue::YamlObject(it) => it.syntax, + AnyYamlValue::AnyYamlScalar(it) => it.into_syntax(), } } } -impl std::fmt::Debug for AnyYamlContent { +impl std::fmt::Debug for AnyYamlValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyYamlContent::YamlBogusValue(it) => std::fmt::Debug::fmt(it, f), - AnyYamlContent::YamlScalar(it) => std::fmt::Debug::fmt(it, f), + AnyYamlValue::AnyYamlScalar(it) => std::fmt::Debug::fmt(it, f), + AnyYamlValue::YamlArray(it) => std::fmt::Debug::fmt(it, f), + AnyYamlValue::YamlArrayInline(it) => std::fmt::Debug::fmt(it, f), + AnyYamlValue::YamlBogusValue(it) => std::fmt::Debug::fmt(it, f), + AnyYamlValue::YamlObject(it) => std::fmt::Debug::fmt(it, f), } } } -impl From for SyntaxNode { - fn from(n: AnyYamlContent) -> SyntaxNode { +impl From for SyntaxNode { + fn from(n: AnyYamlValue) -> SyntaxNode { match n { - AnyYamlContent::YamlBogusValue(it) => it.into(), - AnyYamlContent::YamlScalar(it) => it.into(), + AnyYamlValue::AnyYamlScalar(it) => it.into(), + AnyYamlValue::YamlArray(it) => it.into(), + AnyYamlValue::YamlArrayInline(it) => it.into(), + AnyYamlValue::YamlBogusValue(it) => it.into(), + AnyYamlValue::YamlObject(it) => it.into(), } } } -impl From for SyntaxElement { - fn from(n: AnyYamlContent) -> SyntaxElement { +impl From for SyntaxElement { + fn from(n: AnyYamlValue) -> SyntaxElement { let node: SyntaxNode = n.into(); node.into() } } -impl std::fmt::Display for AnyYamlContent { +impl std::fmt::Display for AnyYamlScalar { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for AnyYamlValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlArray { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlArrayInline { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlArrayItem { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlBlockFolded { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlBlockLiteral { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlBlockValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlBooleanValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -430,17 +1551,37 @@ impl std::fmt::Display for YamlDocument { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for YamlRoot { +impl std::fmt::Display for YamlIdentifier { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlNullValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlNumberValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlObject { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for YamlObjectMember { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for YamlScalar { +impl std::fmt::Display for YamlRoot { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for YamlStringLiteral { +impl std::fmt::Display for YamlStringValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -560,10 +1701,93 @@ impl From for SyntaxElement { } } #[derive(Clone, Eq, PartialEq, Hash)] -pub struct YamlContentList { +pub struct YamlArrayInlineList { + syntax_list: SyntaxList, +} +impl YamlArrayInlineList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for YamlArrayInlineList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_ARRAY_INLINE_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_ARRAY_INLINE_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(YamlArrayInlineList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlArrayInlineList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstSeparatedList for YamlArrayInlineList { + type Language = Language; + type Node = AnyYamlScalar; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for YamlArrayInlineList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("YamlArrayInlineList ")?; + f.debug_list().entries(self.elements()).finish() + } +} +impl IntoIterator for YamlArrayInlineList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for &YamlArrayInlineList { + type Item = SyntaxResult; + type IntoIter = AstSeparatedListNodesIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct YamlArrayItemList { syntax_list: SyntaxList, } -impl YamlContentList { +impl YamlArrayItemList { #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] #[doc = r""] #[doc = r" # Safety"] @@ -576,16 +1800,16 @@ impl YamlContentList { } } } -impl AstNode for YamlContentList { +impl AstNode for YamlArrayItemList { type Language = Language; const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(YAML_CONTENT_LIST as u16)); + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_ARRAY_ITEM_LIST as u16)); fn can_cast(kind: SyntaxKind) -> bool { - kind == YAML_CONTENT_LIST + kind == YAML_ARRAY_ITEM_LIST } - fn cast(syntax: SyntaxNode) -> Option { + fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { - Some(YamlContentList { + Some(YamlArrayItemList { syntax_list: syntax.into_list(), }) } else { @@ -600,7 +1824,7 @@ impl AstNode for YamlContentList { } } #[cfg(feature = "serde")] -impl Serialize for YamlContentList { +impl Serialize for YamlArrayItemList { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -612,9 +1836,9 @@ impl Serialize for YamlContentList { seq.end() } } -impl AstNodeList for YamlContentList { +impl AstNodeList for YamlArrayItemList { type Language = Language; - type Node = AnyYamlContent; + type Node = YamlArrayItem; fn syntax_list(&self) -> &SyntaxList { &self.syntax_list } @@ -622,22 +1846,22 @@ impl AstNodeList for YamlContentList { self.syntax_list } } -impl Debug for YamlContentList { +impl Debug for YamlArrayItemList { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.write_str("YamlContentList ")?; + f.write_str("YamlArrayItemList ")?; f.debug_list().entries(self.iter()).finish() } } -impl IntoIterator for &YamlContentList { - type Item = AnyYamlContent; - type IntoIter = AstNodeListIterator; +impl IntoIterator for &YamlArrayItemList { + type Item = YamlArrayItem; + type IntoIter = AstNodeListIterator; fn into_iter(self) -> Self::IntoIter { self.iter() } } -impl IntoIterator for YamlContentList { - type Item = AnyYamlContent; - type IntoIter = AstNodeListIterator; +impl IntoIterator for YamlArrayItemList { + type Item = YamlArrayItem; + type IntoIter = AstNodeListIterator; fn into_iter(self) -> Self::IntoIter { self.iter() } @@ -725,6 +1949,89 @@ impl IntoIterator for YamlDocumentList { self.iter() } } +#[derive(Clone, Eq, PartialEq, Hash)] +pub struct YamlObjectMemberList { + syntax_list: SyntaxList, +} +impl YamlObjectMemberList { + #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] + #[doc = r""] + #[doc = r" # Safety"] + #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] + #[doc = r" or a match on [SyntaxNode::kind]"] + #[inline] + pub unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { + Self { + syntax_list: syntax.into_list(), + } + } +} +impl AstNode for YamlObjectMemberList { + type Language = Language; + const KIND_SET: SyntaxKindSet = + SyntaxKindSet::from_raw(RawSyntaxKind(YAML_OBJECT_MEMBER_LIST as u16)); + fn can_cast(kind: SyntaxKind) -> bool { + kind == YAML_OBJECT_MEMBER_LIST + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(YamlObjectMemberList { + syntax_list: syntax.into_list(), + }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + self.syntax_list.node() + } + fn into_syntax(self) -> SyntaxNode { + self.syntax_list.into_node() + } +} +#[cfg(feature = "serde")] +impl Serialize for YamlObjectMemberList { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for e in self.iter() { + seq.serialize_element(&e)?; + } + seq.end() + } +} +impl AstNodeList for YamlObjectMemberList { + type Language = Language; + type Node = YamlObjectMember; + fn syntax_list(&self) -> &SyntaxList { + &self.syntax_list + } + fn into_syntax_list(self) -> SyntaxList { + self.syntax_list + } +} +impl Debug for YamlObjectMemberList { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.write_str("YamlObjectMemberList ")?; + f.debug_list().entries(self.iter()).finish() + } +} +impl IntoIterator for &YamlObjectMemberList { + type Item = YamlObjectMember; + type IntoIter = AstNodeListIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} +impl IntoIterator for YamlObjectMemberList { + type Item = YamlObjectMember; + type IntoIter = AstNodeListIterator; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} #[derive(Clone)] pub struct DebugSyntaxElementChildren(pub SyntaxElementChildren); impl Debug for DebugSyntaxElementChildren { diff --git a/crates/biome_yaml_syntax/src/generated/nodes_mut.rs b/crates/biome_yaml_syntax/src/generated/nodes_mut.rs index 783ce380f3d8..0d8291ef9ddc 100644 --- a/crates/biome_yaml_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_yaml_syntax/src/generated/nodes_mut.rs @@ -3,35 +3,85 @@ use crate::{generated::nodes::*, YamlSyntaxToken as SyntaxToken}; use biome_rowan::AstNode; use std::iter::once; -impl YamlDocument { - pub fn with_content(self, element: YamlContentList) -> Self { +impl YamlArray { + pub fn with_items(self, element: YamlArrayItemList) -> Self { Self::unwrap_cast( self.syntax .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), ) } } -impl YamlRoot { - pub fn with_bom_token(self, element: Option) -> Self { +impl YamlArrayInline { + pub fn with_l_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + .splice_slots(0usize..=0usize, once(Some(element.into()))), ) } - pub fn with_documents(self, element: YamlDocumentList) -> Self { + pub fn with_items(self, element: YamlArrayInlineList) -> Self { Self::unwrap_cast( self.syntax .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), ) } - pub fn with_eof_token(self, element: SyntaxToken) -> Self { + pub fn with_r_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } } -impl YamlScalar { +impl YamlArrayItem { + pub fn with_minus_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_item(self, element: AnyYamlValue) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl YamlBlockFolded { + pub fn with_r_angle_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_value(self, element: YamlBlockValue) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl YamlBlockLiteral { + pub fn with_bitwise_or_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } + pub fn with_value(self, element: YamlBlockValue) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl YamlBlockValue { + pub fn with_yaml_block_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl YamlBooleanValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax @@ -39,7 +89,99 @@ impl YamlScalar { ) } } -impl YamlStringLiteral { +impl YamlDocument { + pub fn with_dashdashdash_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + ) + } + pub fn with_body(self, element: AnyYamlValue) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_dotdotdot_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(element.map(|element| element.into()))), + ) + } +} +impl YamlIdentifier { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl YamlNullValue { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl YamlNumberValue { + pub fn with_value_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into()))), + ) + } +} +impl YamlObject { + pub fn with_members(self, element: YamlObjectMemberList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl YamlObjectMember { + pub fn with_key(self, element: YamlIdentifier) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_colon_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into()))), + ) + } + pub fn with_value(self, element: AnyYamlValue) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), + ) + } +} +impl YamlRoot { + pub fn with_bom_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + ) + } + pub fn with_documents(self, element: YamlDocumentList) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + ) + } + pub fn with_eof_token(self, element: SyntaxToken) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(2usize..=2usize, once(Some(element.into()))), + ) + } +} +impl YamlStringValue { pub fn with_value_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax diff --git a/xtask/codegen/src/generate_syntax_kinds.rs b/xtask/codegen/src/generate_syntax_kinds.rs index 487fc7c4361f..adf376a9c257 100644 --- a/xtask/codegen/src/generate_syntax_kinds.rs +++ b/xtask/codegen/src/generate_syntax_kinds.rs @@ -178,7 +178,7 @@ pub fn generate_syntax_kinds(grammar: KindsSrc, language_kind: LanguageKind) -> let tok = match self { #(#punctuation => #punctuation_strings,)* #(#full_keywords => #all_keyword_to_strings,)* - YAML_STRING_LITERAL => "string literal", + YAML_STRING_VALUE => "string value", _ => return None, }; Some(tok) diff --git a/xtask/codegen/src/js_kinds_src.rs b/xtask/codegen/src/js_kinds_src.rs index 1be9e8ddea35..726a3d0aaed0 100644 --- a/xtask/codegen/src/js_kinds_src.rs +++ b/xtask/codegen/src/js_kinds_src.rs @@ -686,6 +686,7 @@ impl Field { ("$", LanguageKind::Graphql) => "dollar", ("~=", _) => "whitespace_like", (",", _) => "comma", + ("---", LanguageKind::Yaml) => "dashdashdash", _ => name, }; diff --git a/xtask/codegen/src/yaml_kinds_src.rs b/xtask/codegen/src/yaml_kinds_src.rs index 39c077f0ea72..25298871d231 100644 --- a/xtask/codegen/src/yaml_kinds_src.rs +++ b/xtask/codegen/src/yaml_kinds_src.rs @@ -24,13 +24,29 @@ pub const YAML_KINDS_SRC: KindsSrc = KindsSrc { ("...", "DOC_END"), ], keywords: &["null"], - literals: &["YAML_STRING_LITERAL", "YAML_SCALAR"], + literals: &[ + "YAML_STRING_VALUE", + "YAML_NUMBER_VALUE", + "YAML_BOOLEAN_VALUE", + "YAML_NULL_VALUE", + "YAML_BLOCK_VALUE", + "YAML_IDENTIFIER", + ], tokens: &["NEWLINE", "WHITESPACE", "IDENT", "COMMENT"], nodes: &[ "YAML_ROOT", "YAML_DOCUMENT_LIST", "YAML_DOCUMENT", - "YAML_CONTENT_LIST", + "YAML_ARRAY_INLINE", + "YAML_ARRAY_INLINE_LIST", + "YAML_OBJECT", + "YAML_OBJECT_MEMBER", + "YAML_OBJECT_MEMBER_LIST", + "YAML_ARRAY", + "YAML_ARRAY_ITEM", + "YAML_ARRAY_ITEM_LIST", + "YAML_BLOCK_LITERAL", + "YAML_BLOCK_FOLDED", // Bogus nodes "YAML_BOGUS", "YAML_BOGUS_VALUE", diff --git a/xtask/codegen/yaml.ungram b/xtask/codegen/yaml.ungram index 90e53252271b..8ba1d753e879 100644 --- a/xtask/codegen/yaml.ungram +++ b/xtask/codegen/yaml.ungram @@ -30,14 +30,66 @@ YamlBogus = SyntaxElement* YamlBogusValue = SyntaxElement* YamlRoot = - bom: 'UNICODE_BOM'? - documents: YamlDocumentList - eof: 'EOF' + bom: 'UNICODE_BOM'? + documents: YamlDocumentList + eof: 'EOF' YamlDocumentList = YamlDocument* -YamlDocument = content: YamlContentList -YamlContentList = AnyYamlContent* +YamlDocument = + '---'? // Document start marker + body: AnyYamlValue + '...'? -AnyYamlContent = YamlScalar | YamlBogusValue -YamlScalar = value: 'yaml_scalar' -YamlStringLiteral = value: 'yaml_string_literal' +AnyYamlScalar = + YamlStringValue + | YamlNumberValue + | YamlBooleanValue + | YamlNullValue + +YamlArrayInline = + '[' + items: YamlArrayInlineList + ']' + +YamlArrayInlineList = (AnyYamlScalar (',' AnyYamlScalar)* ','?) + +AnyYamlValue = + AnyYamlScalar + | YamlArray + | YamlArrayInline + | YamlObject + | YamlBogusValue + +YamlArray = + items: YamlArrayItemList + +YamlArrayItem = + '-' + item: AnyYamlValue + +YamlArrayItemList = YamlArrayItem* + +YamlObject = + members: YamlObjectMemberList + +YamlObjectMember = + key: YamlIdentifier + ':' + value: AnyYamlValue + +YamlObjectMemberList = YamlObjectMember* + +YamlBlockLiteral = + '|' + value: YamlBlockValue + +YamlBlockFolded = + '>' + value: YamlBlockValue + +YamlNumberValue = value: 'yaml_number_value' +YamlStringValue = value: 'yaml_string_value' +YamlBooleanValue = value: 'yaml_boolean_value' +YamlNullValue = value: 'yaml_null_value' +YamlIdentifier = value: 'yaml_identifier' +YamlBlockValue = 'yaml_block_value'