use std::fmt::{Display, Error as FmtError, Formatter};
use crate::base::{ComputeMode, Remove, Rewrite, UseForce};
use crate::hs::HaskellBool;
pub use self::goal::*;
pub use self::iotcm::*;
mod goal;
mod iotcm;
#[derive(Debug, Clone)]
pub enum Cmd {
Load {
path: String,
flags: Vec<String>,
},
Compile {
backend: String,
path: String,
flags: Vec<String>,
},
Constraints,
Metas,
ShowModuleContentsToplevel {
rewrite: Rewrite,
search: String,
},
SearchAboutToplevel {
rewrite: Rewrite,
search: String,
},
SolveAll(Rewrite),
SolveOne(InputWithRewrite),
AutoOne(GoalInput),
AutoAll,
InferToplevel {
rewrite: Rewrite,
code: String,
},
ComputeToplevel {
compute_mode: ComputeMode,
code: String,
},
LoadHighlightingInfo {
path: String,
},
TokenHighlighting {
path: String,
remove: Remove,
},
Highlight(GoalInput),
ShowImplicitArgs(bool),
ToggleImplicitArgs,
Give {
force: UseForce,
input: GoalInput,
},
Refine(GoalInput),
Intro {
dunno: bool,
input: GoalInput,
},
RefineOrIntro {
dunno: bool,
input: GoalInput,
},
Context(InputWithRewrite),
HelperFunction(InputWithRewrite),
Infer(InputWithRewrite),
GoalType(InputWithRewrite),
ElaborateGive(InputWithRewrite),
GoalTypeContext(InputWithRewrite),
GoalTypeContextInfer(InputWithRewrite),
GoalTypeContextCheck(InputWithRewrite),
ShowModuleContents(InputWithRewrite),
MakeCase(GoalInput),
Compute {
compute_mode: ComputeMode,
input: GoalInput,
},
WhyInScope(GoalInput),
WhyInScopeToplevel(String),
ShowVersion,
Abort,
}
impl Cmd {
pub fn load_simple(path: String) -> Self {
Cmd::Load {
path,
flags: vec![],
}
}
pub fn goal_type(input: GoalInput) -> Self {
Cmd::GoalType(From::from(input))
}
pub fn context(input: GoalInput) -> Self {
Cmd::Context(From::from(input))
}
pub fn split(input: GoalInput) -> Self {
Cmd::MakeCase(input)
}
pub fn search_module(search: String) -> Self {
Cmd::ShowModuleContentsToplevel {
rewrite: Default::default(),
search,
}
}
pub fn infer(input: GoalInput) -> Self {
Cmd::Infer(From::from(input))
}
pub fn give(input: GoalInput) -> Self {
Cmd::Give {
force: UseForce::WithoutForce,
input,
}
}
}
impl Display for Cmd {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
use Cmd::*;
match self {
Load { path, flags } => write!(f, "( Cmd_load {:?} {:?} )", path, flags),
Compile {
backend,
path,
flags,
} => write!(f, "( Cmd_compile {:?} {:?} {:?} )", backend, path, flags),
Constraints => f.write_str("Cmd_constraints"),
Metas => f.write_str("Cmd_metas"),
ShowModuleContentsToplevel { rewrite, search } => write!(
f,
"( Cmd_show_module_contents_toplevel {:?} {:?} )",
rewrite, search
),
SearchAboutToplevel { rewrite, search } => write!(
f,
"( Cmd_search_about_toplevel {:?} {:?} )",
rewrite, search
),
SolveAll(rewrite) => write!(f, "( Cmd_solveAll {:?} )", rewrite),
SolveOne(info) => write!(f, "( Cmd_solveOne {} )", info),
AutoOne(input) => write!(f, "( Cmd_autoOne {} )", input),
AutoAll => f.write_str("Cmd_autoAll"),
InferToplevel { rewrite, code } => {
write!(f, "( Cmd_infer_toplevel {:?} {:?} )", rewrite, code)
}
ComputeToplevel { compute_mode, code } => {
write!(f, "( Cmd_compute_toplevel {:?} {:?} )", compute_mode, code)
}
LoadHighlightingInfo { path } => write!(f, "( Cmd_load_highlighting_info {:?} )", path),
TokenHighlighting { path, remove } => {
write!(f, "( Cmd_tokenHighlighting {:?} {:?} ", path, remove)
}
Highlight(input) => write!(f, "( Cmd_highlight {} )", input),
ShowImplicitArgs(show) => {
write!(f, "( ShowImplicitArgs {:?} )", HaskellBool::from(*show))
}
ToggleImplicitArgs => f.write_str("ToggleImplicitArgs"),
Give { force, input } => write!(f, "( Cmd_give {:?} {} )", force, input),
Refine(input) => write!(f, "( Cmd_refine {} )", input),
Intro { dunno, input } => {
write!(f, "( Cmd_intro {:?} {} )", HaskellBool::from(*dunno), input)
}
RefineOrIntro { dunno, input } => write!(
f,
"( Cmd_refine_or_intro {:?} {} )",
HaskellBool::from(*dunno),
input
),
Context(info) => write!(f, "( Cmd_context {} )", info),
HelperFunction(info) => write!(f, "( Cmd_helper_function {} )", info),
Infer(info) => write!(f, "( Cmd_infer {} )", info),
GoalType(info) => write!(f, "( Cmd_goal_type {} )", info),
ElaborateGive(info) => write!(f, "( Cmd_elaborate_give {} )", info),
GoalTypeContext(info) => write!(f, "( Cmd_goal_type_context {} )", info),
GoalTypeContextInfer(info) => write!(f, "( Cmd_goal_type_context_infer {} )", info),
GoalTypeContextCheck(info) => write!(f, "( Cmd_goal_type_context_check {} )", info),
ShowModuleContents(info) => write!(f, "( Cmd_show_module_contents {} )", info),
MakeCase(input) => write!(f, "( Cmd_make_case {} )", input),
Compute {
compute_mode,
input,
} => write!(f, "( Cmd_compute {:?} {} )", compute_mode, input),
WhyInScope(input) => write!(f, "( Cmd_why_in_scope {} )", input),
WhyInScopeToplevel(name) => write!(f, "( Cmd_why_in_scope_toplevel {:?} )", name),
ShowVersion => f.write_str("Cmd_show_version"),
Abort => f.write_str("Cmd_abort"),
}
}
}