Function fluent_syntax::parser::parse_runtime

source ·
pub fn parse_runtime<'s, S>(input: S) -> Result<S>
where S: Slice<'s>,
Expand description

Parses an input into an Abstract Syntax Tree representation with comments stripped.

This mode is intended for runtime use of Fluent. It currently strips all comments improving parsing performance and reducing the size of the AST tree.

§Example

use fluent_syntax::parser;
use fluent_syntax::ast;

let ftl = r#"
### Resource Level Comment

# This is a message comment
hello-world = Hello World!

"#;

let resource = parser::parse_runtime(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![],
            comment: None,
        }
    ),
);