Module fluent_syntax::ast [−][src]
Abstract Syntax Tree representation of the Fluent Translation List.
The AST of Fluent contains all nodes structures to represent a complete representation of the FTL resource.
The tree preserves all semantic information and allow for round-trip of a canonically written FTL resource.
The root node is called Resource
and contains a list of Entry
nodes
representing all possible entries in the Fluent Translation List.
Example
use fluent_syntax::parser; use fluent_syntax::ast; let ftl = r#" # This is a message comment hello-world = Hello World! .tooltip = Tooltip for you, { $userName }. "#; let resource = parser::parse(ftl) .expect("Failed to parse an FTL resource."); assert_eq!( resource.body[0], 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![ ast::Attribute { id: ast::Identifier { name: "tooltip" }, value: ast::Pattern { elements: vec![ ast::PatternElement::TextElement { value: "Tooltip for you, " }, ast::PatternElement::Placeable { expression: ast::Expression::Inline( ast::InlineExpression::VariableReference { id: ast::Identifier { name: "userName" } } ) }, ast::PatternElement::TextElement { value: "." }, ] } } ], comment: Some( ast::Comment { content: vec!["This is a message comment"] } ) } ), );
Errors
Fluent AST preserves blocks containing invaid syntax as Entry::Junk
.
White space
At the moment, AST does not preserve white space. In result only a canonical form of the AST is suitable for a round-trip.
Structs
Attribute | |
CallArguments | List of arguments for a |
Comment | Fluent |
Identifier | Identifier is part of nodes such as |
Message | Message node represents the most common |
NamedArgument | A key-value pair used in |
Pattern | Pattern contains a value of a |
Resource | Root node of a Fluent Translation List. |
Term | A Fluent |
Variant | Variant is a single branch of a value in a |
Enums
Entry | A top-level node representing an entry of a |
Expression | An expression that is either a select expression or an inline expression. |
InlineExpression | A subset of expressions which can be used as |
PatternElement | PatternElement is an element of a |
VariantKey | A key of a |