Function fluent_syntax::parser::parse [−][src]
pub fn parse<'s, S>(input: S) -> Result<S> where
S: Slice<'s>,
Parses an input into a complete Abstract Syntax Tree representation with all source information preserved.
This mode is intended for tooling, linters and other scenarios where complete representation, with comments, is preferred over speed and memory utilization.
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(ftl) .expect("Failed to parse an FTL resource."); assert_eq!( resource.body[0], ast::Entry::ResourceComment( ast::Comment { content: vec![ "Resource Level Comment" ] } ) ); assert_eq!( resource.body[1], 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: Some( ast::Comment { content: vec!["This is a message comment"] } ) } ), );