Struct fluent_syntax::ast::Pattern [−][src]
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
Auto Trait Implementations
impl<S> RefUnwindSafe for Pattern<S> where
S: RefUnwindSafe,
impl<S> UnwindSafe for Pattern<S> where
S: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more