use std::path::PathBuf;
mod dummy_dialect;
mod tags;
mod xmlish;
use crate::{
config::Config,
session::{ModelResponse, Session},
Result,
};
pub use dummy_dialect::*;
pub use tags::*;
pub trait DialectProvider {
fn name(&self) -> &'static str;
fn system(&self) -> String;
fn render_context(&self, config: &Config, p: &Session) -> Result<String>;
fn render_step_request(
&self,
config: &Config,
session: &Session,
offset: usize,
) -> Result<String>;
fn render_step_response(
&self,
config: &Config,
session: &Session,
offset: usize,
) -> Result<String>;
fn render_editables(
&self,
config: &Config,
session: &Session,
paths: Vec<PathBuf>,
) -> Result<String>;
fn parse(&self, txt: &str) -> Result<ModelResponse>;
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Dialect {
Tags(Tags),
Dummy(DummyDialect),
}
impl DialectProvider for Dialect {
fn name(&self) -> &'static str {
match self {
Dialect::Tags(t) => t.name(),
Dialect::Dummy(d) => d.name(),
}
}
fn system(&self) -> String {
match self {
Dialect::Tags(t) => t.system(),
Dialect::Dummy(d) => d.system(),
}
}
fn render_context(&self, config: &Config, s: &Session) -> Result<String> {
match self {
Dialect::Tags(t) => t.render_context(config, s),
Dialect::Dummy(d) => d.render_context(config, s),
}
}
fn render_editables(
&self,
config: &Config,
session: &Session,
paths: Vec<PathBuf>,
) -> Result<String> {
match self {
Dialect::Tags(t) => t.render_editables(config, session, paths),
Dialect::Dummy(d) => d.render_editables(config, session, paths),
}
}
fn render_step_request(
&self,
config: &Config,
session: &Session,
offset: usize,
) -> Result<String> {
match self {
Dialect::Tags(t) => t.render_step_request(config, session, offset),
Dialect::Dummy(d) => d.render_step_request(config, session, offset),
}
}
fn parse(&self, txt: &str) -> Result<ModelResponse> {
match self {
Dialect::Tags(t) => t.parse(txt),
Dialect::Dummy(d) => d.parse(txt),
}
}
fn render_step_response(
&self,
config: &Config,
session: &Session,
offset: usize,
) -> Result<String> {
match self {
Dialect::Tags(t) => t.render_step_response(config, session, offset),
Dialect::Dummy(d) => d.render_step_response(config, session, offset),
}
}
}