mod parse_ast;
mod type_in_comment;
use std::fmt::Display;
use crate::build::r#gen::StrExt;
pub use type_in_comment::{Annotation, annotation};
#[derive(Debug)]
pub struct Message {
pub id: Id,
pub comment: Vec<String>,
pub variables: Vec<Variable>,
pub elements: Vec<ElementMarker>,
pub pattern_refs: Vec<Ref>,
pub file: String,
pub line: usize,
pub comment_line: usize,
}
impl PartialEq for Message {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
&& self.comment == other.comment
&& self.variables == other.variables
&& self.elements == other.elements
&& self.pattern_refs == other.pattern_refs
}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Ref {
pub name: String,
pub kind: RefKind,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum RefKind {
Variable,
Term,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Id {
pub message: String,
pub attribute: Option<String>,
}
impl Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let msg = &self.message;
match &self.attribute {
Some(a) => write!(f, "message '{msg}' with attribute '{a}'"),
None => write!(f, "message '{msg}'"),
}
}
}
impl Id {
#[cfg(test)]
pub fn new_attr(message: &str, attribute: &str) -> Self {
Self {
message: message.to_owned(),
attribute: Some(attribute.to_owned()),
}
}
#[cfg(test)]
pub fn new_msg(message: &str) -> Self {
Self {
message: message.to_owned(),
attribute: None,
}
}
pub fn func_name(&self) -> String {
let atr = self
.attribute
.as_ref()
.map(|a| format!("_{a}"))
.unwrap_or_default();
format!("{}{atr}", self.message).rust_id()
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct Variable {
pub id: String,
pub typ: VarType,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum VarType {
Any,
String,
Number,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct ElementMarker {
pub name: String,
pub kind: ElementKind,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum ElementKind {
Variable,
Term,
}