From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- third_party/rust/weedle2/src/common.rs | 45 ++++++++++++++++++++++++++++++ third_party/rust/weedle2/src/dictionary.rs | 3 +- third_party/rust/weedle2/src/interface.rs | 4 ++- third_party/rust/weedle2/src/lib.rs | 16 +++++++++-- third_party/rust/weedle2/src/namespace.rs | 4 ++- third_party/rust/weedle2/src/whitespace.rs | 1 + 6 files changed, 68 insertions(+), 5 deletions(-) (limited to 'third_party/rust/weedle2/src') diff --git a/third_party/rust/weedle2/src/common.rs b/third_party/rust/weedle2/src/common.rs index fadf89ba8b..d36f6e5438 100644 --- a/third_party/rust/weedle2/src/common.rs +++ b/third_party/rust/weedle2/src/common.rs @@ -33,6 +33,18 @@ impl<'a, T: Parse<'a>, U: Parse<'a>, V: Parse<'a>> Parse<'a> for (T, U, V) { parser!(nom::sequence::tuple((T::parse, U::parse, V::parse))); } +pub(crate) fn docstring(input: &str) -> IResult<&str, String> { + nom::multi::many1(nom::sequence::preceded( + nom::character::complete::multispace0, + nom::sequence::delimited( + nom::bytes::complete::tag("///"), + nom::bytes::complete::take_until("\n"), + nom::bytes::complete::tag("\n"), + ), + ))(input) + .map(|io| (io.0, io.1.join("\n"))) +} + ast_types! { /// Parses `( body )` #[derive(Copy, Default)] @@ -103,6 +115,11 @@ ast_types! { assign: term!(=), value: DefaultValue<'a>, } + + /// Represents consecutive comment lines starting with `///`, joined by `\n`. + struct Docstring( + String = docstring, + ) } #[cfg(test)] @@ -211,4 +228,32 @@ mod test { Identifier; 0 == "hello"; }); + + test!(should_parse_docstring { "///hello world\n" => + ""; + Docstring; + 0 == "hello world"; + }); + + test!(should_parse_multiline_docstring { "///hello\n///world\n" => + ""; + Docstring; + 0 == "hello\nworld"; + }); + + test!(should_parse_multiline_indented_docstring { "///hello\n ///world\n" => + ""; + Docstring; + 0 == "hello\nworld"; + }); + + test!(should_not_parse_docstring_with_comments { "///hello\n//comment1\n///world\n" => + "//comment1\n///world\n"; + Docstring; + 0 == "hello"; + }); + + test!(err should_not_parse_not_docstring { "" => + Docstring + }); } diff --git a/third_party/rust/weedle2/src/dictionary.rs b/third_party/rust/weedle2/src/dictionary.rs index 3c9b23cac5..b775d526dc 100644 --- a/third_party/rust/weedle2/src/dictionary.rs +++ b/third_party/rust/weedle2/src/dictionary.rs @@ -1,5 +1,5 @@ use crate::attribute::ExtendedAttributeList; -use crate::common::{Default, Identifier}; +use crate::common::{Default, Docstring, Identifier}; use crate::types::Type; /// Parses dictionary members @@ -8,6 +8,7 @@ pub type DictionaryMembers<'a> = Vec>; ast_types! { /// Parses dictionary member `[attributes]? required? type identifier ( = default )?;` struct DictionaryMember<'a> { + docstring: Option, attributes: Option>, required: Option, type_: Type<'a>, diff --git a/third_party/rust/weedle2/src/interface.rs b/third_party/rust/weedle2/src/interface.rs index 5e30909c38..ab3c10d3c3 100644 --- a/third_party/rust/weedle2/src/interface.rs +++ b/third_party/rust/weedle2/src/interface.rs @@ -1,6 +1,6 @@ use crate::argument::ArgumentList; use crate::attribute::ExtendedAttributeList; -use crate::common::{Generics, Identifier, Parenthesized}; +use crate::common::{Docstring, Generics, Identifier, Parenthesized}; use crate::literal::ConstValue; use crate::types::{AttributedType, ConstType, ReturnType}; @@ -41,6 +41,7 @@ ast_types! { /// /// (( )) means ( ) chars Constructor(struct ConstructorInterfaceMember<'a> { + docstring: Option, attributes: Option>, constructor: term!(constructor), args: Parenthesized>, @@ -50,6 +51,7 @@ ast_types! { /// /// (( )) means ( ) chars Operation(struct OperationInterfaceMember<'a> { + docstring: Option, attributes: Option>, modifier: Option, special: Option, diff --git a/third_party/rust/weedle2/src/lib.rs b/third_party/rust/weedle2/src/lib.rs index 610a34fa14..71ab7c33b5 100644 --- a/third_party/rust/weedle2/src/lib.rs +++ b/third_party/rust/weedle2/src/lib.rs @@ -23,7 +23,7 @@ use self::argument::ArgumentList; use self::attribute::ExtendedAttributeList; -use self::common::{Braced, Identifier, Parenthesized, PunctuatedNonEmpty}; +use self::common::{Braced, Docstring, Identifier, Parenthesized, PunctuatedNonEmpty}; use self::dictionary::DictionaryMembers; use self::interface::{Inheritance, InterfaceMembers}; use self::literal::StringLit; @@ -109,6 +109,7 @@ ast_types! { }), /// Parses `[attributes]? callback interface identifier ( : inheritance )? { members };` CallbackInterface(struct CallbackInterfaceDefinition<'a> { + docstring: Option, attributes: Option>, callback: term!(callback), interface: term!(interface), @@ -119,6 +120,7 @@ ast_types! { }), /// Parses `[attributes]? interface identifier ( : inheritance )? { members };` Interface(struct InterfaceDefinition<'a> { + docstring: Option, attributes: Option>, interface: term!(interface), identifier: Identifier<'a>, @@ -137,6 +139,7 @@ ast_types! { }), /// Parses `[attributes]? namespace identifier { members };` Namespace(struct NamespaceDefinition<'a> { + docstring: Option, attributes: Option>, namespace: term!(namespace), identifier: Identifier<'a>, @@ -145,6 +148,7 @@ ast_types! { }), /// Parses `[attributes]? dictionary identifier ( : inheritance )? { members };` Dictionary(struct DictionaryDefinition<'a> { + docstring: Option, attributes: Option>, dictionary: term!(dictionary), identifier: Identifier<'a>, @@ -191,6 +195,7 @@ ast_types! { }), /// Parses `[attributes]? enum identifier { values };` Enum(struct EnumDefinition<'a> { + docstring: Option, attributes: Option>, enum_: term!(enum), identifier: Identifier<'a>, @@ -224,8 +229,15 @@ ast_types! { } } +ast_types! { + struct EnumVariant<'a> { + docstring: Option, + value: StringLit<'a>, + } +} + /// Parses a non-empty enum value list -pub type EnumValueList<'a> = PunctuatedNonEmpty, term!(,)>; +pub type EnumValueList<'a> = PunctuatedNonEmpty, term!(,)>; #[cfg(test)] mod test { diff --git a/third_party/rust/weedle2/src/namespace.rs b/third_party/rust/weedle2/src/namespace.rs index ed28573218..60673cdcec 100644 --- a/third_party/rust/weedle2/src/namespace.rs +++ b/third_party/rust/weedle2/src/namespace.rs @@ -1,6 +1,6 @@ use crate::argument::ArgumentList; use crate::attribute::ExtendedAttributeList; -use crate::common::{Identifier, Parenthesized}; +use crate::common::{Docstring, Identifier, Parenthesized}; use crate::types::{AttributedType, ReturnType}; /// Parses namespace members declaration @@ -13,6 +13,7 @@ ast_types! { /// /// (( )) means ( ) chars Operation(struct OperationNamespaceMember<'a> { + docstring: Option, attributes: Option>, return_type: ReturnType<'a>, identifier: Option>, @@ -21,6 +22,7 @@ ast_types! { }), /// Parses `[attribute]? readonly attributetype type identifier;` Attribute(struct AttributeNamespaceMember<'a> { + docstring: Option, attributes: Option>, readonly: term!(readonly), attribute: term!(attribute), diff --git a/third_party/rust/weedle2/src/whitespace.rs b/third_party/rust/weedle2/src/whitespace.rs index 336e4784e1..4be3ca43e8 100644 --- a/third_party/rust/weedle2/src/whitespace.rs +++ b/third_party/rust/weedle2/src/whitespace.rs @@ -7,6 +7,7 @@ pub(crate) fn sp(input: &str) -> IResult<&str, &str> { (), nom::sequence::tuple(( nom::bytes::complete::tag("//"), + nom::combinator::not(nom::bytes::complete::tag("/")), nom::bytes::complete::take_until("\n"), nom::bytes::complete::tag("\n"), )), -- cgit v1.2.3