From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/fluent-syntax/src/ast/helper.rs | 25 ++++ third_party/rust/fluent-syntax/src/ast/mod.rs | 149 +++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 third_party/rust/fluent-syntax/src/ast/helper.rs create mode 100644 third_party/rust/fluent-syntax/src/ast/mod.rs (limited to 'third_party/rust/fluent-syntax/src/ast') diff --git a/third_party/rust/fluent-syntax/src/ast/helper.rs b/third_party/rust/fluent-syntax/src/ast/helper.rs new file mode 100644 index 0000000000..923437d23b --- /dev/null +++ b/third_party/rust/fluent-syntax/src/ast/helper.rs @@ -0,0 +1,25 @@ +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +use super::Comment; +// This is a helper struct used to properly deserialize referential +// JSON comments which are single continous String, into a vec of +// content slices. +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(untagged))] +pub enum CommentDef { + Single { content: S }, + Multi { content: Vec }, +} + +impl<'s, S> From> for Comment { + fn from(input: CommentDef) -> Self { + match input { + CommentDef::Single { content } => Self { + content: vec![content], + }, + CommentDef::Multi { content } => Self { content }, + } + } +} diff --git a/third_party/rust/fluent-syntax/src/ast/mod.rs b/third_party/rust/fluent-syntax/src/ast/mod.rs new file mode 100644 index 0000000000..48583441ca --- /dev/null +++ b/third_party/rust/fluent-syntax/src/ast/mod.rs @@ -0,0 +1,149 @@ +mod helper; + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct Resource { + pub body: Vec>, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub enum Entry { + Message(Message), + Term(Term), + Comment(Comment), + GroupComment(Comment), + ResourceComment(Comment), + Junk { content: S }, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct Message { + pub id: Identifier, + pub value: Option>, + pub attributes: Vec>, + pub comment: Option>, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct Term { + pub id: Identifier, + pub value: Pattern, + pub attributes: Vec>, + pub comment: Option>, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct Pattern { + pub elements: Vec>, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub enum PatternElement { + TextElement { value: S }, + Placeable { expression: Expression }, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct Attribute { + pub id: Identifier, + pub value: Pattern, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct Identifier { + pub name: S, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub struct Variant { + pub key: VariantKey, + pub value: Pattern, + pub default: bool, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub enum VariantKey { + Identifier { name: S }, + NumberLiteral { value: S }, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(from = "helper::CommentDef"))] +pub struct Comment { + pub content: Vec, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub struct CallArguments { + pub positional: Vec>, + pub named: Vec>, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub struct NamedArgument { + pub name: Identifier, + pub value: InlineExpression, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type"))] +pub enum InlineExpression { + StringLiteral { + value: S, + }, + NumberLiteral { + value: S, + }, + FunctionReference { + id: Identifier, + arguments: Option>, + }, + MessageReference { + id: Identifier, + attribute: Option>, + }, + TermReference { + id: Identifier, + attribute: Option>, + arguments: Option>, + }, + VariableReference { + id: Identifier, + }, + Placeable { + expression: Box>, + }, +} + +#[derive(Debug, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", serde(untagged))] +pub enum Expression { + SelectExpression { + selector: InlineExpression, + variants: Vec>, + }, + InlineExpression(InlineExpression), +} -- cgit v1.2.3