= i18n_pattern Rizzen Yazston
== Pattern parser and formatter
The parser handles the parsing of string tokens into an Abstract Syntax Tree (AST), checking the grammar of patterns is valid. The parser only does the syntactic analysis of the supplied Token vector.
The formatter takes the AST that was generated by the parser and constructs a string template for values to be substituted into. The formatter also does the semantic analysis of the grammar. Once a string template has been constructed, it can be used multiple times by simply supplying new placeholder values when executing the format() method. Depending on the placeholder type of the pattern, a suitable selection of the available data types can be used, these include the basic String
, integers, unsigned integers and floats. In addition to these special ICU4X types are supported such as FixedDecimal
, Date
, Time
and DateTime
structs.
See pattern strings.asciidoc
in docs
of pattern
crate for the pattern formatting specification.
== Acknowledgement
Stefano Angeleri for advice on various design aspects of implementing the components of the internationalisation project, and also providing the Italian translation of error message strings.
== Cargo.toml
``` [dependencies] iculocid = "1.1.0" i18nicu-rizzen-yazston = "0.6.1" i18nutility-rizzen-yazston = "0.6.1" i18nlexer-rizzen-yazston = "0.6.1" # Needed for Token, TokenType tree-rizzen-yazston = "0.4.0" icu_provider = "1.2.0"
icuproperties = "1.2.0" icusegmenter = "1.2.0" icuplurals = "1.2.0" icudecimal = "1.2.0" icucalendar = "1.2.0" icudatetime = "1.2.0"
[dependencies.fixed_decimal] version = "0.5.3"
features = [ "ryu" ] ```
== Examples
``` use i18nicu::IcuDataProvider; use i18nlexer::{Token, TokenType, tokenise}; use i18npattern::{ parse, NodeType, Formatter, FormatterError, PlaceholderValue, CommandRegistry, englishaoran }; use icutestdata::buffer; use icuprovider::serde::AsDeserializingBufferProvider; use icu_locid::Locale; use std::collections::HashMap; use std::rc::Rc; use std::error::Error;
fn patternplural() -> Result<(), Box
fn commanddelayed() -> Result<(), Box