1use std::fmt::{Display, Error as FmtError, Formatter};
2
3use crate::base::{ComputeMode, Remove, Rewrite, UseForce};
4use crate::hs::HaskellBool;
5
6pub use self::goal::*;
7pub use self::iotcm::*;
8
9mod goal;
10mod iotcm;
11
12#[derive(Debug, Clone)]
13pub enum Cmd {
14 Load {
17 path: String,
18 flags: Vec<String>,
19 },
20 Compile {
23 backend: String,
24 path: String,
25 flags: Vec<String>,
26 },
27 Constraints,
28 Metas,
31 ShowModuleContentsToplevel {
34 rewrite: Rewrite,
35 search: String,
36 },
37 SearchAboutToplevel {
40 rewrite: Rewrite,
41 search: String,
42 },
43 SolveAll(Rewrite),
46 SolveOne(InputWithRewrite),
49 AutoOne(GoalInput),
51 AutoAll,
53 InferToplevel {
56 rewrite: Rewrite,
58 code: String,
59 },
60 ComputeToplevel {
63 compute_mode: ComputeMode,
64 code: String,
65 },
66
67 LoadHighlightingInfo {
85 path: String,
86 },
87 TokenHighlighting {
100 path: String,
101 remove: Remove,
102 },
103 Highlight(GoalInput),
106 ShowImplicitArgs(bool),
110 ToggleImplicitArgs,
112 Give {
117 force: UseForce,
118 input: GoalInput,
119 },
120 Refine(GoalInput),
121 Intro {
122 dunno: bool,
123 input: GoalInput,
124 },
125 RefineOrIntro {
126 dunno: bool,
127 input: GoalInput,
128 },
129 Context(InputWithRewrite),
130 HelperFunction(InputWithRewrite),
131 Infer(InputWithRewrite),
132 GoalType(InputWithRewrite),
133 ElaborateGive(InputWithRewrite),
136 GoalTypeContext(InputWithRewrite),
138 GoalTypeContextInfer(InputWithRewrite),
141 GoalTypeContextCheck(InputWithRewrite),
144 ShowModuleContents(InputWithRewrite),
147 MakeCase(GoalInput),
148 Compute {
149 compute_mode: ComputeMode,
150 input: GoalInput,
151 },
152 WhyInScope(GoalInput),
153 WhyInScopeToplevel(String),
154 ShowVersion,
156 Abort,
159}
160
161impl Cmd {
162 pub fn load_simple(path: String) -> Self {
163 Cmd::Load {
164 path,
165 flags: vec![],
166 }
167 }
168
169 pub fn goal_type(input: GoalInput) -> Self {
171 Cmd::GoalType(From::from(input))
172 }
173
174 pub fn context(input: GoalInput) -> Self {
175 Cmd::Context(From::from(input))
176 }
177
178 pub fn split(input: GoalInput) -> Self {
179 Cmd::MakeCase(input)
180 }
181
182 pub fn search_module(search: String) -> Self {
183 Cmd::ShowModuleContentsToplevel {
184 rewrite: Default::default(),
185 search,
186 }
187 }
188
189 pub fn infer(input: GoalInput) -> Self {
191 Cmd::Infer(From::from(input))
192 }
193
194 pub fn give(input: GoalInput) -> Self {
195 Cmd::Give {
196 force: UseForce::WithoutForce,
197 input,
198 }
199 }
200}
201
202impl Display for Cmd {
203 fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
204 use Cmd::*;
205 match self {
206 Load { path, flags } => write!(f, "( Cmd_load {:?} {:?} )", path, flags),
207 Compile {
208 backend,
209 path,
210 flags,
211 } => write!(f, "( Cmd_compile {:?} {:?} {:?} )", backend, path, flags),
212 Constraints => f.write_str("Cmd_constraints"),
213 Metas => f.write_str("Cmd_metas"),
214 ShowModuleContentsToplevel { rewrite, search } => write!(
215 f,
216 "( Cmd_show_module_contents_toplevel {:?} {:?} )",
217 rewrite, search
218 ),
219 SearchAboutToplevel { rewrite, search } => write!(
220 f,
221 "( Cmd_search_about_toplevel {:?} {:?} )",
222 rewrite, search
223 ),
224 SolveAll(rewrite) => write!(f, "( Cmd_solveAll {:?} )", rewrite),
225 SolveOne(info) => write!(f, "( Cmd_solveOne {} )", info),
226 AutoOne(input) => write!(f, "( Cmd_autoOne {} )", input),
227 AutoAll => f.write_str("Cmd_autoAll"),
228 InferToplevel { rewrite, code } => {
229 write!(f, "( Cmd_infer_toplevel {:?} {:?} )", rewrite, code)
230 }
231 ComputeToplevel { compute_mode, code } => {
232 write!(f, "( Cmd_compute_toplevel {:?} {:?} )", compute_mode, code)
233 }
234 LoadHighlightingInfo { path } => write!(f, "( Cmd_load_highlighting_info {:?} )", path),
235 TokenHighlighting { path, remove } => {
236 write!(f, "( Cmd_tokenHighlighting {:?} {:?} ", path, remove)
237 }
238 Highlight(input) => write!(f, "( Cmd_highlight {} )", input),
239 ShowImplicitArgs(show) => {
240 write!(f, "( ShowImplicitArgs {:?} )", HaskellBool::from(*show))
241 }
242 ToggleImplicitArgs => f.write_str("ToggleImplicitArgs"),
243 Give { force, input } => write!(f, "( Cmd_give {:?} {} )", force, input),
244 Refine(input) => write!(f, "( Cmd_refine {} )", input),
245 Intro { dunno, input } => {
246 write!(f, "( Cmd_intro {:?} {} )", HaskellBool::from(*dunno), input)
247 }
248 RefineOrIntro { dunno, input } => write!(
249 f,
250 "( Cmd_refine_or_intro {:?} {} )",
251 HaskellBool::from(*dunno),
252 input
253 ),
254 Context(info) => write!(f, "( Cmd_context {} )", info),
255 HelperFunction(info) => write!(f, "( Cmd_helper_function {} )", info),
256 Infer(info) => write!(f, "( Cmd_infer {} )", info),
257 GoalType(info) => write!(f, "( Cmd_goal_type {} )", info),
258 ElaborateGive(info) => write!(f, "( Cmd_elaborate_give {} )", info),
259 GoalTypeContext(info) => write!(f, "( Cmd_goal_type_context {} )", info),
260 GoalTypeContextInfer(info) => write!(f, "( Cmd_goal_type_context_infer {} )", info),
261 GoalTypeContextCheck(info) => write!(f, "( Cmd_goal_type_context_check {} )", info),
262 ShowModuleContents(info) => write!(f, "( Cmd_show_module_contents {} )", info),
263 MakeCase(input) => write!(f, "( Cmd_make_case {} )", input),
264 Compute {
265 compute_mode,
266 input,
267 } => write!(f, "( Cmd_compute {:?} {} )", compute_mode, input),
268 WhyInScope(input) => write!(f, "( Cmd_why_in_scope {} )", input),
269 WhyInScopeToplevel(name) => write!(f, "( Cmd_why_in_scope_toplevel {:?} )", name),
270 ShowVersion => f.write_str("Cmd_show_version"),
271 Abort => f.write_str("Cmd_abort"),
272 }
273 }
274}