use serde::{Deserialize, Serialize};
use lalrpop_util::lalrpop_mod;
lalrpop_mod!(localization_syn);
#[derive(Serialize, Deserialize, Debug)]
pub struct LocList {
pub lang: Loc,
pub entries: Vec<Entry>,
}
#[derive(Serialize, Deserialize)]
pub struct Loc(String);
impl core::ops::Deref for Loc {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl core::ops::DerefMut for Loc {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[derive(Serialize, Deserialize)]
pub struct Entry {
pub key: String,
pub num: Option<u8>,
pub value: String,
}
super::fn_parse_file!(LocList, localization_syn::LocListParser);
pub mod types {
pub use super::{Entry, Loc, LocList};
}
impl core::fmt::Debug for Loc {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:", self.0)
}
}
impl core::fmt::Debug for Entry {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.num {
Some(n) => write!(f, "{}:{} {}", self.key, n, self.value),
None => write!(f, "{}: {}", self.key, self.value),
}
}
}
impl core::fmt::Display for LocList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self.lang)?;
for entry in &self.entries {
writeln!(f, " {:?}", entry)?;
}
Ok(())
}
}