Type Alias fluent_syntax::parser::Result

source ·
pub type Result<S> = Result<Resource<S>, (Resource<S>, Vec<ParserError>)>;
Expand description

Parser result always returns an AST representation of the input, and if parsing errors were encountered, a list of ParserError elements is also returned.

§Example

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

let ftl = r#"
key1 = Value 1

g@Rb@ge = #2y ds

key2 = Value 2

"#;

let (resource, errors) = parser::parse_runtime(ftl)
    .expect_err("Resource should contain errors.");

assert_eq!(
    errors,
    vec![
        parser::ParserError {
            pos: 18..19,
            slice: Some(17..35),
            kind: parser::ErrorKind::ExpectedToken('=')
        }
    ]
);

assert_eq!(
    resource.body[0],
    ast::Entry::Message(
        ast::Message {
            id: ast::Identifier {
                name: "key1"
            },
            value: Some(ast::Pattern {
                elements: vec![
                    ast::PatternElement::TextElement {
                        value: "Value 1"
                    },
                ]
            }),
            attributes: vec![],
            comment: None,
        }
    ),
);

assert_eq!(
    resource.body[1],
    ast::Entry::Junk {
        content: "g@Rb@ge = #2y ds\n\n"
    }
);

assert_eq!(
    resource.body[2],
    ast::Entry::Message(
        ast::Message {
            id: ast::Identifier {
                name: "key2"
            },
            value: Some(ast::Pattern {
                elements: vec![
                    ast::PatternElement::TextElement {
                        value: "Value 2"
                    },
                ]
            }),
            attributes: vec![],
            comment: None,
        }
    ),
);

Aliased Type§

enum Result<S> {
    Ok(Resource<S>),
    Err((Resource<S>, Vec<ParserError>)),
}

Variants§

§1.0.0

Ok(Resource<S>)

Contains the success value

§1.0.0

Err((Resource<S>, Vec<ParserError>))

Contains the error value