Struct fluent_syntax::ast::Pattern
source · pub struct Pattern<S> {
pub elements: Vec<PatternElement<S>>,
}
Expand description
Pattern contains a value of a Message
, Term
or an Attribute
.
Each pattern is a list of PatternElement
nodes representing
either a simple textual value, or a combination of text literals
and placeholder Expression
nodes.
§Example
use fluent_syntax::parser;
use fluent_syntax::ast;
let ftl = r#"
hello-world = Hello, World!
welcome = Welcome, { $userName }.
"#;
let resource = parser::parse(ftl)
.expect("Failed to parse an FTL resource.");
assert_eq!(
resource,
ast::Resource {
body: vec![
ast::Entry::Message(ast::Message {
id: ast::Identifier {
name: "hello-world"
},
value: Some(ast::Pattern {
elements: vec![
ast::PatternElement::TextElement {
value: "Hello, World!"
}
]
}),
attributes: vec![],
comment: None,
}),
ast::Entry::Message(ast::Message {
id: ast::Identifier {
name: "welcome"
},
value: Some(ast::Pattern {
elements: vec![
ast::PatternElement::TextElement {
value: "Welcome, "
},
ast::PatternElement::Placeable {
expression: ast::Expression::Inline(
ast::InlineExpression::VariableReference {
id: ast::Identifier {
name: "userName"
}
}
)
},
ast::PatternElement::TextElement {
value: "."
}
]
}),
attributes: vec![],
comment: None,
}),
]
}
);
Fields§
§elements: Vec<PatternElement<S>>
Trait Implementations§
source§impl<S: PartialEq> PartialEq for Pattern<S>
impl<S: PartialEq> PartialEq for Pattern<S>
impl<S> StructuralPartialEq for Pattern<S>
Auto Trait Implementations§
impl<S> Freeze for Pattern<S>
impl<S> RefUnwindSafe for Pattern<S>where
S: RefUnwindSafe,
impl<S> Send for Pattern<S>where
S: Send,
impl<S> Sync for Pattern<S>where
S: Sync,
impl<S> Unpin for Pattern<S>where
S: Unpin,
impl<S> UnwindSafe for Pattern<S>where
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more