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

Attribute represents a part of a Message or Term.

CallArguments

List of arguments for a FunctionReference or a TermReference.

Comment

Fluent Comment.

Identifier

Identifier is part of nodes such as Message, Term and Attribute.

Message

Message node represents the most common Entry in an FTL Resource.

NamedArgument

A key-value pair used in CallArguments.

Pattern

Pattern contains a value of a Message, Term or an Attribute.

Resource

Root node of a Fluent Translation List.

Term

A Fluent Term.

Variant

Variant is a single branch of a value in a Select expression.

Enums

Entry

A top-level node representing an entry of a Resource.

Expression

An expression that is either a select expression or an inline expression.

InlineExpression

A subset of expressions which can be used as Placeable, selector, or in CallArguments.

PatternElement

PatternElement is an element of a Pattern.

VariantKey

A key of a Variant.