1use crate::parse::{Token, Parser, ParseError};
4use crate::storage::Storage;
5use itertools::Itertools;
6use crate::lexicon::*;
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize))]
9pub enum SpecConstant<'st> {
10 Numeral(Numeral<'st>),
12 Decimal(Decimal<'st>),
14 Hexadecimal(Hexadecimal<'st>),
16 Binary(Binary<'st>),
18 String(&'st str),
20}
21impl std::fmt::Display for SpecConstant<'_> {
22 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23 match self {
24 Self::Numeral(m0) => write!(f, "{}", m0),
25 Self::Decimal(m0) => write!(f, "{}", m0),
26 Self::Hexadecimal(m0) => write!(f, "{}", m0),
27 Self::Binary(m0) => write!(f, "{}", m0),
28 Self::String(m0) => write!(f, "{}", m0),
29 }
30 }
31}
32impl<'st> SpecConstant<'st> {
33 pub fn parse(st: &'st Storage, src: &str) -> Result<SpecConstant<'st>, ParseError> {
34 <SpecConstant<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
35 }
36}
37impl<'st> SmtlibParse<'st> for SpecConstant<'st> {
38 type Output = SpecConstant<'st>;
39 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
40 (String::is_start_of(offset, p)) || (Binary::is_start_of(offset, p))
41 || (Hexadecimal::is_start_of(offset, p)) || (Decimal::is_start_of(offset, p))
42 || (Numeral::is_start_of(offset, p))
43 }
44 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
45 let offset = 0;
46 if String::is_start_of(offset, p) {
47 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
48 #[allow(clippy::useless_conversion)] return Ok(Self::String(m0.into()));
49 }
50 if Binary::is_start_of(offset, p) {
51 let m0 = <Binary<'st> as SmtlibParse<'st>>::parse(p)?;
52 #[allow(clippy::useless_conversion)] return Ok(Self::Binary(m0.into()));
53 }
54 if Hexadecimal::is_start_of(offset, p) {
55 let m0 = <Hexadecimal<'st> as SmtlibParse<'st>>::parse(p)?;
56 #[allow(clippy::useless_conversion)] return Ok(Self::Hexadecimal(m0.into()));
57 }
58 if Decimal::is_start_of(offset, p) {
59 let m0 = <Decimal<'st> as SmtlibParse<'st>>::parse(p)?;
60 #[allow(clippy::useless_conversion)] return Ok(Self::Decimal(m0.into()));
61 }
62 if Numeral::is_start_of(offset, p) {
63 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
64 #[allow(clippy::useless_conversion)] return Ok(Self::Numeral(m0.into()));
65 }
66 Err(p.stuck("SpecConstant"))
67 }
68}
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
70#[cfg_attr(feature = "serde", derive(serde::Serialize))]
71pub enum SExpr<'st> {
72 SpecConstant(SpecConstant<'st>),
74 Symbol(Symbol<'st>),
76 Reserved(Reserved<'st>),
78 Keyword(Keyword<'st>),
80 Paren(&'st [SExpr<'st>]),
82}
83impl std::fmt::Display for SExpr<'_> {
84 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
85 match self {
86 Self::SpecConstant(m0) => write!(f, "{}", m0),
87 Self::Symbol(m0) => write!(f, "{}", m0),
88 Self::Reserved(m0) => write!(f, "{}", m0),
89 Self::Keyword(m0) => write!(f, "{}", m0),
90 Self::Paren(m0) => write!(f, "({})", m0.iter().format(" ")),
91 }
92 }
93}
94impl<'st> SExpr<'st> {
95 pub fn parse(st: &'st Storage, src: &str) -> Result<SExpr<'st>, ParseError> {
96 <SExpr<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
97 }
98}
99impl<'st> SmtlibParse<'st> for SExpr<'st> {
100 type Output = SExpr<'st>;
101 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
102 (p.nth(offset) == Token::LParen) || (Keyword::is_start_of(offset, p))
103 || (Reserved::is_start_of(offset, p)) || (Symbol::is_start_of(offset, p))
104 || (SpecConstant::is_start_of(offset, p))
105 }
106 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
107 let offset = 0;
108 if p.nth(offset) == Token::LParen {
109 p.expect(Token::LParen)?;
110 let m0 = p.any::<SExpr<'st>>()?;
111 p.expect(Token::RParen)?;
112 #[allow(clippy::useless_conversion)] return Ok(Self::Paren(m0.into()));
113 }
114 if Keyword::is_start_of(offset, p) {
115 let m0 = <Keyword<'st> as SmtlibParse<'st>>::parse(p)?;
116 #[allow(clippy::useless_conversion)] return Ok(Self::Keyword(m0.into()));
117 }
118 if Reserved::is_start_of(offset, p) {
119 let m0 = <Reserved<'st> as SmtlibParse<'st>>::parse(p)?;
120 #[allow(clippy::useless_conversion)] return Ok(Self::Reserved(m0.into()));
121 }
122 if Symbol::is_start_of(offset, p) {
123 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
124 #[allow(clippy::useless_conversion)] return Ok(Self::Symbol(m0.into()));
125 }
126 if SpecConstant::is_start_of(offset, p) {
127 let m0 = <SpecConstant<'st> as SmtlibParse<'st>>::parse(p)?;
128 #[allow(clippy::useless_conversion)]
129 return Ok(Self::SpecConstant(m0.into()));
130 }
131 Err(p.stuck("SExpr"))
132 }
133}
134#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
135#[cfg_attr(feature = "serde", derive(serde::Serialize))]
136pub enum Index<'st> {
137 Numeral(Numeral<'st>),
139 Symbol(Symbol<'st>),
141}
142impl std::fmt::Display for Index<'_> {
143 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
144 match self {
145 Self::Numeral(m0) => write!(f, "{}", m0),
146 Self::Symbol(m0) => write!(f, "{}", m0),
147 }
148 }
149}
150impl<'st> Index<'st> {
151 pub fn parse(st: &'st Storage, src: &str) -> Result<Index<'st>, ParseError> {
152 <Index<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
153 }
154}
155impl<'st> SmtlibParse<'st> for Index<'st> {
156 type Output = Index<'st>;
157 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
158 (Symbol::is_start_of(offset, p)) || (Numeral::is_start_of(offset, p))
159 }
160 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
161 let offset = 0;
162 if Symbol::is_start_of(offset, p) {
163 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
164 #[allow(clippy::useless_conversion)] return Ok(Self::Symbol(m0.into()));
165 }
166 if Numeral::is_start_of(offset, p) {
167 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
168 #[allow(clippy::useless_conversion)] return Ok(Self::Numeral(m0.into()));
169 }
170 Err(p.stuck("Index"))
171 }
172}
173#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
174#[cfg_attr(feature = "serde", derive(serde::Serialize))]
175pub enum Identifier<'st> {
176 Simple(Symbol<'st>),
178 Indexed(Symbol<'st>, &'st [Index<'st>]),
180}
181impl std::fmt::Display for Identifier<'_> {
182 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183 match self {
184 Self::Simple(m0) => write!(f, "{}", m0),
185 Self::Indexed(m0, m1) => write!(f, "(_ {} {})", m0, m1.iter().format(" ")),
186 }
187 }
188}
189impl<'st> Identifier<'st> {
190 pub fn parse(st: &'st Storage, src: &str) -> Result<Identifier<'st>, ParseError> {
191 <Identifier<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
192 }
193}
194impl<'st> SmtlibParse<'st> for Identifier<'st> {
195 type Output = Identifier<'st>;
196 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
197 (p.nth(offset) == Token::LParen
198 && p.nth_matches(offset + 1, Token::Reserved, "_"))
199 || (Symbol::is_start_of(offset, p))
200 }
201 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
202 let offset = 0;
203 if p.nth(offset) == Token::LParen
204 && p.nth_matches(offset + 1, Token::Reserved, "_")
205 {
206 p.expect(Token::LParen)?;
207 p.expect_matches(Token::Reserved, "_")?;
208 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
209 let m1 = p.non_zero::<Index<'st>>()?;
210 p.expect(Token::RParen)?;
211 #[allow(clippy::useless_conversion)]
212 return Ok(Self::Indexed(m0.into(), m1.into()));
213 }
214 if Symbol::is_start_of(offset, p) {
215 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
216 #[allow(clippy::useless_conversion)] return Ok(Self::Simple(m0.into()));
217 }
218 Err(p.stuck("Identifier"))
219 }
220}
221#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
222#[cfg_attr(feature = "serde", derive(serde::Serialize))]
223pub enum AttributeValue<'st> {
224 SpecConstant(SpecConstant<'st>),
226 Symbol(Symbol<'st>),
228 Expr(SExpr<'st>),
230}
231impl std::fmt::Display for AttributeValue<'_> {
232 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
233 match self {
234 Self::SpecConstant(m0) => write!(f, "{}", m0),
235 Self::Symbol(m0) => write!(f, "{}", m0),
236 Self::Expr(m0) => write!(f, "({})", m0),
237 }
238 }
239}
240impl<'st> AttributeValue<'st> {
241 pub fn parse(
242 st: &'st Storage,
243 src: &str,
244 ) -> Result<AttributeValue<'st>, ParseError> {
245 <AttributeValue<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
246 }
247}
248impl<'st> SmtlibParse<'st> for AttributeValue<'st> {
249 type Output = AttributeValue<'st>;
250 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
251 (p.nth(offset) == Token::LParen) || (Symbol::is_start_of(offset, p))
252 || (SpecConstant::is_start_of(offset, p))
253 }
254 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
255 let offset = 0;
256 if p.nth(offset) == Token::LParen {
257 p.expect(Token::LParen)?;
258 let m0 = <SExpr<'st> as SmtlibParse<'st>>::parse(p)?;
259 p.expect(Token::RParen)?;
260 #[allow(clippy::useless_conversion)] return Ok(Self::Expr(m0.into()));
261 }
262 if Symbol::is_start_of(offset, p) {
263 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
264 #[allow(clippy::useless_conversion)] return Ok(Self::Symbol(m0.into()));
265 }
266 if SpecConstant::is_start_of(offset, p) {
267 let m0 = <SpecConstant<'st> as SmtlibParse<'st>>::parse(p)?;
268 #[allow(clippy::useless_conversion)]
269 return Ok(Self::SpecConstant(m0.into()));
270 }
271 Err(p.stuck("AttributeValue"))
272 }
273}
274#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
275#[cfg_attr(feature = "serde", derive(serde::Serialize))]
276pub enum Attribute<'st> {
277 Keyword(Keyword<'st>),
279 WithValue(Keyword<'st>, AttributeValue<'st>),
281}
282impl std::fmt::Display for Attribute<'_> {
283 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
284 match self {
285 Self::Keyword(m0) => write!(f, "{}", m0),
286 Self::WithValue(m0, m1) => write!(f, "{} {}", m0, m1),
287 }
288 }
289}
290impl<'st> Attribute<'st> {
291 pub fn parse(st: &'st Storage, src: &str) -> Result<Attribute<'st>, ParseError> {
292 <Attribute<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
293 }
294}
295impl<'st> SmtlibParse<'st> for Attribute<'st> {
296 type Output = Attribute<'st>;
297 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
298 (Keyword::is_start_of(offset, p) && AttributeValue::is_start_of(offset + 1, p))
299 || (Keyword::is_start_of(offset, p))
300 }
301 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
302 let offset = 0;
303 if Keyword::is_start_of(offset, p) && AttributeValue::is_start_of(offset + 1, p)
304 {
305 let m0 = <Keyword<'st> as SmtlibParse<'st>>::parse(p)?;
306 let m1 = <AttributeValue<'st> as SmtlibParse<'st>>::parse(p)?;
307 #[allow(clippy::useless_conversion)]
308 return Ok(Self::WithValue(m0.into(), m1.into()));
309 }
310 if Keyword::is_start_of(offset, p) {
311 let m0 = <Keyword<'st> as SmtlibParse<'st>>::parse(p)?;
312 #[allow(clippy::useless_conversion)] return Ok(Self::Keyword(m0.into()));
313 }
314 Err(p.stuck("Attribute"))
315 }
316}
317#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
318#[cfg_attr(feature = "serde", derive(serde::Serialize))]
319pub enum Sort<'st> {
320 Sort(Identifier<'st>),
322 Parametric(Identifier<'st>, &'st [Sort<'st>]),
324}
325impl std::fmt::Display for Sort<'_> {
326 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
327 match self {
328 Self::Sort(m0) => write!(f, "{}", m0),
329 Self::Parametric(m0, m1) => write!(f, "({} {})", m0, m1.iter().format(" ")),
330 }
331 }
332}
333impl<'st> Sort<'st> {
334 pub fn parse(st: &'st Storage, src: &str) -> Result<Sort<'st>, ParseError> {
335 <Sort<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
336 }
337}
338impl<'st> SmtlibParse<'st> for Sort<'st> {
339 type Output = Sort<'st>;
340 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
341 (Identifier::is_start_of(offset, p)) || (p.nth(offset) == Token::LParen)
342 }
343 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
344 let offset = 0;
345 if Identifier::is_start_of(offset, p) {
346 let m0 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
347 #[allow(clippy::useless_conversion)] return Ok(Self::Sort(m0.into()));
348 }
349 if p.nth(offset) == Token::LParen {
350 p.expect(Token::LParen)?;
351 let m0 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
352 let m1 = p.non_zero::<Sort<'st>>()?;
353 p.expect(Token::RParen)?;
354 #[allow(clippy::useless_conversion)]
355 return Ok(Self::Parametric(m0.into(), m1.into()));
356 }
357 Err(p.stuck("Sort"))
358 }
359}
360#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
361#[cfg_attr(feature = "serde", derive(serde::Serialize))]
362pub enum QualIdentifier<'st> {
363 Identifier(Identifier<'st>),
365 Sorted(Identifier<'st>, Sort<'st>),
367}
368impl std::fmt::Display for QualIdentifier<'_> {
369 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
370 match self {
371 Self::Identifier(m0) => write!(f, "{}", m0),
372 Self::Sorted(m0, m1) => write!(f, "(as {} {})", m0, m1),
373 }
374 }
375}
376impl<'st> QualIdentifier<'st> {
377 pub fn parse(
378 st: &'st Storage,
379 src: &str,
380 ) -> Result<QualIdentifier<'st>, ParseError> {
381 <QualIdentifier<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
382 }
383}
384impl<'st> SmtlibParse<'st> for QualIdentifier<'st> {
385 type Output = QualIdentifier<'st>;
386 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
387 (p.nth(offset) == Token::LParen
388 && p.nth_matches(offset + 1, Token::Reserved, "as"))
389 || (Identifier::is_start_of(offset, p))
390 }
391 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
392 let offset = 0;
393 if p.nth(offset) == Token::LParen
394 && p.nth_matches(offset + 1, Token::Reserved, "as")
395 {
396 p.expect(Token::LParen)?;
397 p.expect_matches(Token::Reserved, "as")?;
398 let m0 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
399 let m1 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
400 p.expect(Token::RParen)?;
401 #[allow(clippy::useless_conversion)]
402 return Ok(Self::Sorted(m0.into(), m1.into()));
403 }
404 if Identifier::is_start_of(offset, p) {
405 let m0 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
406 #[allow(clippy::useless_conversion)] return Ok(Self::Identifier(m0.into()));
407 }
408 Err(p.stuck("QualIdentifier"))
409 }
410}
411#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
413#[cfg_attr(feature = "serde", derive(serde::Serialize))]
414pub struct VarBinding<'st>(pub Symbol<'st>, pub &'st Term<'st>);
415impl std::fmt::Display for VarBinding<'_> {
416 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
417 write!(f, "({} {})", self.0, self.1)
418 }
419}
420impl<'st> VarBinding<'st> {
421 pub fn parse(st: &'st Storage, src: &str) -> Result<VarBinding<'st>, ParseError> {
422 <VarBinding<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
423 }
424}
425impl<'st> SmtlibParse<'st> for VarBinding<'st> {
426 type Output = VarBinding<'st>;
427 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
428 p.nth(offset) == Token::LParen
429 }
430 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
431 p.expect(Token::LParen)?;
432 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
433 let m1 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
434 p.expect(Token::RParen)?;
435 Ok(Self(m0, m1))
436 }
437}
438#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
440#[cfg_attr(feature = "serde", derive(serde::Serialize))]
441pub struct SortedVar<'st>(pub Symbol<'st>, pub Sort<'st>);
442impl std::fmt::Display for SortedVar<'_> {
443 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
444 write!(f, "({} {})", self.0, self.1)
445 }
446}
447impl<'st> SortedVar<'st> {
448 pub fn parse(st: &'st Storage, src: &str) -> Result<SortedVar<'st>, ParseError> {
449 <SortedVar<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
450 }
451}
452impl<'st> SmtlibParse<'st> for SortedVar<'st> {
453 type Output = SortedVar<'st>;
454 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
455 p.nth(offset) == Token::LParen
456 }
457 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
458 p.expect(Token::LParen)?;
459 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
460 let m1 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
461 p.expect(Token::RParen)?;
462 Ok(Self(m0, m1))
463 }
464}
465#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
466#[cfg_attr(feature = "serde", derive(serde::Serialize))]
467pub enum Pattern<'st> {
468 Symbol(Symbol<'st>),
470 Application(Symbol<'st>, &'st [Symbol<'st>]),
472}
473impl std::fmt::Display for Pattern<'_> {
474 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
475 match self {
476 Self::Symbol(m0) => write!(f, "{}", m0),
477 Self::Application(m0, m1) => write!(f, "({} {})", m0, m1.iter().format(" ")),
478 }
479 }
480}
481impl<'st> Pattern<'st> {
482 pub fn parse(st: &'st Storage, src: &str) -> Result<Pattern<'st>, ParseError> {
483 <Pattern<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
484 }
485}
486impl<'st> SmtlibParse<'st> for Pattern<'st> {
487 type Output = Pattern<'st>;
488 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
489 (p.nth(offset) == Token::LParen) || (Symbol::is_start_of(offset, p))
490 }
491 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
492 let offset = 0;
493 if p.nth(offset) == Token::LParen {
494 p.expect(Token::LParen)?;
495 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
496 let m1 = p.non_zero::<Symbol<'st>>()?;
497 p.expect(Token::RParen)?;
498 #[allow(clippy::useless_conversion)]
499 return Ok(Self::Application(m0.into(), m1.into()));
500 }
501 if Symbol::is_start_of(offset, p) {
502 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
503 #[allow(clippy::useless_conversion)] return Ok(Self::Symbol(m0.into()));
504 }
505 Err(p.stuck("Pattern"))
506 }
507}
508#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
510#[cfg_attr(feature = "serde", derive(serde::Serialize))]
511pub struct MatchCase<'st>(pub Pattern<'st>, pub &'st Term<'st>);
512impl std::fmt::Display for MatchCase<'_> {
513 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
514 write!(f, "({} {})", self.0, self.1)
515 }
516}
517impl<'st> MatchCase<'st> {
518 pub fn parse(st: &'st Storage, src: &str) -> Result<MatchCase<'st>, ParseError> {
519 <MatchCase<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
520 }
521}
522impl<'st> SmtlibParse<'st> for MatchCase<'st> {
523 type Output = MatchCase<'st>;
524 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
525 p.nth(offset) == Token::LParen
526 }
527 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
528 p.expect(Token::LParen)?;
529 let m0 = <Pattern<'st> as SmtlibParse<'st>>::parse(p)?;
530 let m1 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
531 p.expect(Token::RParen)?;
532 Ok(Self(m0, m1))
533 }
534}
535#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
536#[cfg_attr(feature = "serde", derive(serde::Serialize))]
537pub enum Term<'st> {
538 SpecConstant(SpecConstant<'st>),
540 Identifier(QualIdentifier<'st>),
542 Application(QualIdentifier<'st>, &'st [&'st Term<'st>]),
544 Let(&'st [VarBinding<'st>], &'st Term<'st>),
546 Forall(&'st [SortedVar<'st>], &'st Term<'st>),
548 Exists(&'st [SortedVar<'st>], &'st Term<'st>),
550 Match(&'st Term<'st>, &'st [MatchCase<'st>]),
552 Annotation(&'st Term<'st>, &'st [Attribute<'st>]),
554}
555impl std::fmt::Display for Term<'_> {
556 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
557 match self {
558 Self::SpecConstant(m0) => write!(f, "{}", m0),
559 Self::Identifier(m0) => write!(f, "{}", m0),
560 Self::Application(m0, m1) => write!(f, "({} {})", m0, m1.iter().format(" ")),
561 Self::Let(m0, m1) => write!(f, "(let ({}) {})", m0.iter().format(" "), m1),
562 Self::Forall(m0, m1) => {
563 write!(f, "(forall ({}) {})", m0.iter().format(" "), m1)
564 }
565 Self::Exists(m0, m1) => {
566 write!(f, "(exists ({}) {})", m0.iter().format(" "), m1)
567 }
568 Self::Match(m0, m1) => {
569 write!(f, "(match {} ({}))", m0, m1.iter().format(" "))
570 }
571 Self::Annotation(m0, m1) => write!(f, "(! {} {})", m0, m1.iter().format(" ")),
572 }
573 }
574}
575impl<'st> Term<'st> {
576 pub fn parse(st: &'st Storage, src: &str) -> Result<&'st Term<'st>, ParseError> {
577 <Term<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
578 }
579}
580impl<'st> SmtlibParse<'st> for Term<'st> {
581 type Output = &'st Term<'st>;
582 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
583 (p.nth(offset) == Token::LParen
584 && p.nth_matches(offset + 1, Token::Reserved, "match"))
585 || (p.nth(offset) == Token::LParen
586 && p.nth_matches(offset + 1, Token::Reserved, "exists")
587 && p.nth(offset + 2) == Token::LParen)
588 || (p.nth(offset) == Token::LParen
589 && p.nth_matches(offset + 1, Token::Reserved, "forall")
590 && p.nth(offset + 2) == Token::LParen)
591 || (p.nth(offset) == Token::LParen
592 && p.nth_matches(offset + 1, Token::Reserved, "let")
593 && p.nth(offset + 2) == Token::LParen)
594 || (p.nth(offset) == Token::LParen
595 && p.nth_matches(offset + 1, Token::Reserved, "!"))
596 || (p.nth(offset) == Token::LParen)
597 || (QualIdentifier::is_start_of(offset, p))
598 || (SpecConstant::is_start_of(offset, p))
599 }
600 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
601 let offset = 0;
602 if p.nth(offset) == Token::LParen
603 && p.nth_matches(offset + 1, Token::Reserved, "match")
604 {
605 p.expect(Token::LParen)?;
606 p.expect_matches(Token::Reserved, "match")?;
607 let m0 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
608 p.expect(Token::LParen)?;
609 let m1 = p.non_zero::<MatchCase<'st>>()?;
610 p.expect(Token::RParen)?;
611 p.expect(Token::RParen)?;
612 #[allow(clippy::useless_conversion)]
613 return Ok(p.storage.alloc(Self::Match(m0.into(), m1.into())));
614 }
615 if p.nth(offset) == Token::LParen
616 && p.nth_matches(offset + 1, Token::Reserved, "exists")
617 && p.nth(offset + 2) == Token::LParen
618 {
619 p.expect(Token::LParen)?;
620 p.expect_matches(Token::Reserved, "exists")?;
621 p.expect(Token::LParen)?;
622 let m0 = p.non_zero::<SortedVar<'st>>()?;
623 p.expect(Token::RParen)?;
624 let m1 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
625 p.expect(Token::RParen)?;
626 #[allow(clippy::useless_conversion)]
627 return Ok(p.storage.alloc(Self::Exists(m0.into(), m1.into())));
628 }
629 if p.nth(offset) == Token::LParen
630 && p.nth_matches(offset + 1, Token::Reserved, "forall")
631 && p.nth(offset + 2) == Token::LParen
632 {
633 p.expect(Token::LParen)?;
634 p.expect_matches(Token::Reserved, "forall")?;
635 p.expect(Token::LParen)?;
636 let m0 = p.non_zero::<SortedVar<'st>>()?;
637 p.expect(Token::RParen)?;
638 let m1 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
639 p.expect(Token::RParen)?;
640 #[allow(clippy::useless_conversion)]
641 return Ok(p.storage.alloc(Self::Forall(m0.into(), m1.into())));
642 }
643 if p.nth(offset) == Token::LParen
644 && p.nth_matches(offset + 1, Token::Reserved, "let")
645 && p.nth(offset + 2) == Token::LParen
646 {
647 p.expect(Token::LParen)?;
648 p.expect_matches(Token::Reserved, "let")?;
649 p.expect(Token::LParen)?;
650 let m0 = p.non_zero::<VarBinding<'st>>()?;
651 p.expect(Token::RParen)?;
652 let m1 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
653 p.expect(Token::RParen)?;
654 #[allow(clippy::useless_conversion)]
655 return Ok(p.storage.alloc(Self::Let(m0.into(), m1.into())));
656 }
657 if p.nth(offset) == Token::LParen
658 && p.nth_matches(offset + 1, Token::Reserved, "!")
659 {
660 p.expect(Token::LParen)?;
661 p.expect_matches(Token::Reserved, "!")?;
662 let m0 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
663 let m1 = p.non_zero::<Attribute<'st>>()?;
664 p.expect(Token::RParen)?;
665 #[allow(clippy::useless_conversion)]
666 return Ok(p.storage.alloc(Self::Annotation(m0.into(), m1.into())));
667 }
668 if p.nth(offset) == Token::LParen {
669 p.expect(Token::LParen)?;
670 let m0 = <QualIdentifier<'st> as SmtlibParse<'st>>::parse(p)?;
671 let m1 = p.non_zero::<Term<'st>>()?;
672 p.expect(Token::RParen)?;
673 #[allow(clippy::useless_conversion)]
674 return Ok(p.storage.alloc(Self::Application(m0.into(), m1.into())));
675 }
676 if QualIdentifier::is_start_of(offset, p) {
677 let m0 = <QualIdentifier<'st> as SmtlibParse<'st>>::parse(p)?;
678 #[allow(clippy::useless_conversion)]
679 return Ok(p.storage.alloc(Self::Identifier(m0.into())));
680 }
681 if SpecConstant::is_start_of(offset, p) {
682 let m0 = <SpecConstant<'st> as SmtlibParse<'st>>::parse(p)?;
683 #[allow(clippy::useless_conversion)]
684 return Ok(p.storage.alloc(Self::SpecConstant(m0.into())));
685 }
686 Err(p.stuck("Term"))
687 }
688}
689#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
691#[cfg_attr(feature = "serde", derive(serde::Serialize))]
692pub struct SortSymbolDecl<'st>(
693 pub Identifier<'st>,
694 pub Numeral<'st>,
695 pub &'st [Attribute<'st>],
696);
697impl std::fmt::Display for SortSymbolDecl<'_> {
698 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
699 write!(f, "({} {} {})", self.0, self.1, self.2.iter().format(" "))
700 }
701}
702impl<'st> SortSymbolDecl<'st> {
703 pub fn parse(
704 st: &'st Storage,
705 src: &str,
706 ) -> Result<SortSymbolDecl<'st>, ParseError> {
707 <SortSymbolDecl<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
708 }
709}
710impl<'st> SmtlibParse<'st> for SortSymbolDecl<'st> {
711 type Output = SortSymbolDecl<'st>;
712 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
713 p.nth(offset) == Token::LParen
714 }
715 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
716 p.expect(Token::LParen)?;
717 let m0 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
718 let m1 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
719 let m2 = p.any::<Attribute<'st>>()?;
720 p.expect(Token::RParen)?;
721 Ok(Self(m0, m1, m2))
722 }
723}
724#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
725#[cfg_attr(feature = "serde", derive(serde::Serialize))]
726pub enum MetaSpecConstant {
727 Numeral,
729 Decimal,
731 String,
733}
734impl std::fmt::Display for MetaSpecConstant {
735 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
736 match self {
737 Self::Numeral => write!(f, "NUMERAL"),
738 Self::Decimal => write!(f, "DECIMAL"),
739 Self::String => write!(f, "STRING"),
740 }
741 }
742}
743impl<'st> MetaSpecConstant {
744 pub fn parse(st: &'st Storage, src: &str) -> Result<MetaSpecConstant, ParseError> {
745 <MetaSpecConstant as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
746 }
747}
748impl<'st> SmtlibParse<'st> for MetaSpecConstant {
749 type Output = MetaSpecConstant;
750 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
751 (p.nth_matches(offset, Token::Reserved, "STRING"))
752 || (p.nth_matches(offset, Token::Reserved, "DECIMAL"))
753 || (p.nth_matches(offset, Token::Reserved, "NUMERAL"))
754 }
755 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
756 let offset = 0;
757 if p.nth_matches(offset, Token::Reserved, "STRING") {
758 p.expect_matches(Token::Reserved, "STRING")?;
759 #[allow(clippy::useless_conversion)] return Ok(Self::String);
760 }
761 if p.nth_matches(offset, Token::Reserved, "DECIMAL") {
762 p.expect_matches(Token::Reserved, "DECIMAL")?;
763 #[allow(clippy::useless_conversion)] return Ok(Self::Decimal);
764 }
765 if p.nth_matches(offset, Token::Reserved, "NUMERAL") {
766 p.expect_matches(Token::Reserved, "NUMERAL")?;
767 #[allow(clippy::useless_conversion)] return Ok(Self::Numeral);
768 }
769 Err(p.stuck("MetaSpecConstant"))
770 }
771}
772#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
773#[cfg_attr(feature = "serde", derive(serde::Serialize))]
774pub enum FunSymbolDecl<'st> {
775 SpecConstant(SpecConstant<'st>, Sort<'st>, &'st [Attribute<'st>]),
777 MetaSpecConstant(MetaSpecConstant, Sort<'st>, &'st [Attribute<'st>]),
779 Identifier(Identifier<'st>, &'st [Sort<'st>], &'st [Attribute<'st>]),
781}
782impl std::fmt::Display for FunSymbolDecl<'_> {
783 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
784 match self {
785 Self::SpecConstant(m0, m1, m2) => {
786 write!(f, "({} {} {})", m0, m1, m2.iter().format(" "))
787 }
788 Self::MetaSpecConstant(m0, m1, m2) => {
789 write!(f, "({} {} {})", m0, m1, m2.iter().format(" "))
790 }
791 Self::Identifier(m0, m1, m2) => {
792 write!(f, "({} {} {})", m0, m1.iter().format(" "), m2.iter().format(" "))
793 }
794 }
795 }
796}
797impl<'st> FunSymbolDecl<'st> {
798 pub fn parse(st: &'st Storage, src: &str) -> Result<FunSymbolDecl<'st>, ParseError> {
799 <FunSymbolDecl<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
800 }
801}
802impl<'st> SmtlibParse<'st> for FunSymbolDecl<'st> {
803 type Output = FunSymbolDecl<'st>;
804 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
805 (p.nth(offset) == Token::LParen) || (p.nth(offset) == Token::LParen)
806 || (p.nth(offset) == Token::LParen)
807 }
808 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
809 let offset = 0;
810 if p.nth(offset) == Token::LParen {
811 p.expect(Token::LParen)?;
812 let m0 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
813 let m1 = p.non_zero::<Sort<'st>>()?;
814 let m2 = p.any::<Attribute<'st>>()?;
815 p.expect(Token::RParen)?;
816 #[allow(clippy::useless_conversion)]
817 return Ok(Self::Identifier(m0.into(), m1.into(), m2.into()));
818 }
819 if p.nth(offset) == Token::LParen {
820 p.expect(Token::LParen)?;
821 let m0 = <MetaSpecConstant as SmtlibParse<'st>>::parse(p)?;
822 let m1 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
823 let m2 = p.any::<Attribute<'st>>()?;
824 p.expect(Token::RParen)?;
825 #[allow(clippy::useless_conversion)]
826 return Ok(Self::MetaSpecConstant(m0.into(), m1.into(), m2.into()));
827 }
828 if p.nth(offset) == Token::LParen {
829 p.expect(Token::LParen)?;
830 let m0 = <SpecConstant<'st> as SmtlibParse<'st>>::parse(p)?;
831 let m1 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
832 let m2 = p.any::<Attribute<'st>>()?;
833 p.expect(Token::RParen)?;
834 #[allow(clippy::useless_conversion)]
835 return Ok(Self::SpecConstant(m0.into(), m1.into(), m2.into()));
836 }
837 Err(p.stuck("FunSymbolDecl"))
838 }
839}
840#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
841#[cfg_attr(feature = "serde", derive(serde::Serialize))]
842pub enum ParFunSymbolDecl<'st> {
843 Par(&'st [Symbol<'st>], Identifier<'st>, &'st [Sort<'st>], &'st [Attribute<'st>]),
845 FunSymbolDecl(FunSymbolDecl<'st>),
847}
848impl std::fmt::Display for ParFunSymbolDecl<'_> {
849 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
850 match self {
851 Self::Par(m0, m1, m2, m3) => {
852 write!(
853 f, "(par ({}) ({} {} {}))", m0.iter().format(" "), m1, m2.iter()
854 .format(" "), m3.iter().format(" ")
855 )
856 }
857 Self::FunSymbolDecl(m0) => write!(f, "{}", m0),
858 }
859 }
860}
861impl<'st> ParFunSymbolDecl<'st> {
862 pub fn parse(
863 st: &'st Storage,
864 src: &str,
865 ) -> Result<ParFunSymbolDecl<'st>, ParseError> {
866 <ParFunSymbolDecl<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
867 }
868}
869impl<'st> SmtlibParse<'st> for ParFunSymbolDecl<'st> {
870 type Output = ParFunSymbolDecl<'st>;
871 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
872 (p.nth(offset) == Token::LParen
873 && p.nth_matches(offset + 1, Token::Reserved, "par")
874 && p.nth(offset + 2) == Token::LParen)
875 || (FunSymbolDecl::is_start_of(offset, p))
876 }
877 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
878 let offset = 0;
879 if p.nth(offset) == Token::LParen
880 && p.nth_matches(offset + 1, Token::Reserved, "par")
881 && p.nth(offset + 2) == Token::LParen
882 {
883 p.expect(Token::LParen)?;
884 p.expect_matches(Token::Reserved, "par")?;
885 p.expect(Token::LParen)?;
886 let m0 = p.non_zero::<Symbol<'st>>()?;
887 p.expect(Token::RParen)?;
888 p.expect(Token::LParen)?;
889 let m1 = <Identifier<'st> as SmtlibParse<'st>>::parse(p)?;
890 let m2 = p.non_zero::<Sort<'st>>()?;
891 let m3 = p.any::<Attribute<'st>>()?;
892 p.expect(Token::RParen)?;
893 p.expect(Token::RParen)?;
894 #[allow(clippy::useless_conversion)]
895 return Ok(Self::Par(m0.into(), m1.into(), m2.into(), m3.into()));
896 }
897 if FunSymbolDecl::is_start_of(offset, p) {
898 let m0 = <FunSymbolDecl<'st> as SmtlibParse<'st>>::parse(p)?;
899 #[allow(clippy::useless_conversion)]
900 return Ok(Self::FunSymbolDecl(m0.into()));
901 }
902 Err(p.stuck("ParFunSymbolDecl"))
903 }
904}
905#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
906#[cfg_attr(feature = "serde", derive(serde::Serialize))]
907pub enum TheoryAttribute<'st> {
908 Sorts(&'st [SortSymbolDecl<'st>]),
910 Funs(&'st [ParFunSymbolDecl<'st>]),
912 SortsDescription(&'st str),
914 FunsDescription(&'st str),
916 Definition(&'st str),
918 Values(&'st str),
920 Notes(&'st str),
922 Attribute(Attribute<'st>),
924}
925impl std::fmt::Display for TheoryAttribute<'_> {
926 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
927 match self {
928 Self::Sorts(m0) => write!(f, ":sorts ({})", m0.iter().format(" ")),
929 Self::Funs(m0) => write!(f, ":funs ({})", m0.iter().format(" ")),
930 Self::SortsDescription(m0) => write!(f, ":sorts-description {}", m0),
931 Self::FunsDescription(m0) => write!(f, ":funs-description {}", m0),
932 Self::Definition(m0) => write!(f, ":definition {}", m0),
933 Self::Values(m0) => write!(f, ":values {}", m0),
934 Self::Notes(m0) => write!(f, ":notes {}", m0),
935 Self::Attribute(m0) => write!(f, "{}", m0),
936 }
937 }
938}
939impl<'st> TheoryAttribute<'st> {
940 pub fn parse(
941 st: &'st Storage,
942 src: &str,
943 ) -> Result<TheoryAttribute<'st>, ParseError> {
944 <TheoryAttribute<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
945 }
946}
947impl<'st> SmtlibParse<'st> for TheoryAttribute<'st> {
948 type Output = TheoryAttribute<'st>;
949 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
950 (p.nth_matches(offset, Token::Keyword, ":funs")
951 && p.nth(offset + 1) == Token::LParen)
952 || (p.nth_matches(offset, Token::Keyword, ":sorts")
953 && p.nth(offset + 1) == Token::LParen)
954 || (p.nth_matches(offset, Token::Keyword, ":notes"))
955 || (p.nth_matches(offset, Token::Keyword, ":values"))
956 || (p.nth_matches(offset, Token::Keyword, ":definition"))
957 || (p.nth_matches(offset, Token::Keyword, ":funs-description"))
958 || (p.nth_matches(offset, Token::Keyword, ":sorts-description"))
959 || (Attribute::is_start_of(offset, p))
960 }
961 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
962 let offset = 0;
963 if p.nth_matches(offset, Token::Keyword, ":funs")
964 && p.nth(offset + 1) == Token::LParen
965 {
966 p.expect_matches(Token::Keyword, ":funs")?;
967 p.expect(Token::LParen)?;
968 let m0 = p.non_zero::<ParFunSymbolDecl<'st>>()?;
969 p.expect(Token::RParen)?;
970 #[allow(clippy::useless_conversion)] return Ok(Self::Funs(m0.into()));
971 }
972 if p.nth_matches(offset, Token::Keyword, ":sorts")
973 && p.nth(offset + 1) == Token::LParen
974 {
975 p.expect_matches(Token::Keyword, ":sorts")?;
976 p.expect(Token::LParen)?;
977 let m0 = p.non_zero::<SortSymbolDecl<'st>>()?;
978 p.expect(Token::RParen)?;
979 #[allow(clippy::useless_conversion)] return Ok(Self::Sorts(m0.into()));
980 }
981 if p.nth_matches(offset, Token::Keyword, ":notes") {
982 p.expect_matches(Token::Keyword, ":notes")?;
983 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
984 #[allow(clippy::useless_conversion)] return Ok(Self::Notes(m0.into()));
985 }
986 if p.nth_matches(offset, Token::Keyword, ":values") {
987 p.expect_matches(Token::Keyword, ":values")?;
988 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
989 #[allow(clippy::useless_conversion)] return Ok(Self::Values(m0.into()));
990 }
991 if p.nth_matches(offset, Token::Keyword, ":definition") {
992 p.expect_matches(Token::Keyword, ":definition")?;
993 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
994 #[allow(clippy::useless_conversion)] return Ok(Self::Definition(m0.into()));
995 }
996 if p.nth_matches(offset, Token::Keyword, ":funs-description") {
997 p.expect_matches(Token::Keyword, ":funs-description")?;
998 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
999 #[allow(clippy::useless_conversion)]
1000 return Ok(Self::FunsDescription(m0.into()));
1001 }
1002 if p.nth_matches(offset, Token::Keyword, ":sorts-description") {
1003 p.expect_matches(Token::Keyword, ":sorts-description")?;
1004 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
1005 #[allow(clippy::useless_conversion)]
1006 return Ok(Self::SortsDescription(m0.into()));
1007 }
1008 if Attribute::is_start_of(offset, p) {
1009 let m0 = <Attribute<'st> as SmtlibParse<'st>>::parse(p)?;
1010 #[allow(clippy::useless_conversion)] return Ok(Self::Attribute(m0.into()));
1011 }
1012 Err(p.stuck("TheoryAttribute"))
1013 }
1014}
1015#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1017#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1018pub struct TheoryDecl<'st>(pub Symbol<'st>, pub &'st [TheoryAttribute<'st>]);
1019impl std::fmt::Display for TheoryDecl<'_> {
1020 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1021 write!(f, "(theory {} {})", self.0, self.1.iter().format(" "))
1022 }
1023}
1024impl<'st> TheoryDecl<'st> {
1025 pub fn parse(st: &'st Storage, src: &str) -> Result<TheoryDecl<'st>, ParseError> {
1026 <TheoryDecl<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1027 }
1028}
1029impl<'st> SmtlibParse<'st> for TheoryDecl<'st> {
1030 type Output = TheoryDecl<'st>;
1031 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1032 p.nth(offset) == Token::LParen
1033 && p.nth_matches(offset + 1, Token::Symbol, "theory")
1034 }
1035 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1036 p.expect(Token::LParen)?;
1037 p.expect_matches(Token::Symbol, "theory")?;
1038 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1039 let m1 = p.non_zero::<TheoryAttribute<'st>>()?;
1040 p.expect(Token::RParen)?;
1041 Ok(Self(m0, m1))
1042 }
1043}
1044#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1045#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1046pub enum LogicAttribute<'st> {
1047 Theories(&'st [Symbol<'st>]),
1049 Language(&'st str),
1051 Extensions(&'st str),
1053 Values(&'st str),
1055 Notes(&'st str),
1057 Attribute(Attribute<'st>),
1059}
1060impl std::fmt::Display for LogicAttribute<'_> {
1061 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1062 match self {
1063 Self::Theories(m0) => write!(f, ":theories ({})", m0.iter().format(" ")),
1064 Self::Language(m0) => write!(f, ":language {}", m0),
1065 Self::Extensions(m0) => write!(f, ":extensions {}", m0),
1066 Self::Values(m0) => write!(f, ":values {}", m0),
1067 Self::Notes(m0) => write!(f, ":notes {}", m0),
1068 Self::Attribute(m0) => write!(f, "{}", m0),
1069 }
1070 }
1071}
1072impl<'st> LogicAttribute<'st> {
1073 pub fn parse(
1074 st: &'st Storage,
1075 src: &str,
1076 ) -> Result<LogicAttribute<'st>, ParseError> {
1077 <LogicAttribute<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1078 }
1079}
1080impl<'st> SmtlibParse<'st> for LogicAttribute<'st> {
1081 type Output = LogicAttribute<'st>;
1082 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1083 (p.nth_matches(offset, Token::Keyword, ":theories")
1084 && p.nth(offset + 1) == Token::LParen)
1085 || (p.nth_matches(offset, Token::Keyword, ":notes"))
1086 || (p.nth_matches(offset, Token::Keyword, ":values"))
1087 || (p.nth_matches(offset, Token::Keyword, ":extensions"))
1088 || (p.nth_matches(offset, Token::Keyword, ":language"))
1089 || (Attribute::is_start_of(offset, p))
1090 }
1091 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1092 let offset = 0;
1093 if p.nth_matches(offset, Token::Keyword, ":theories")
1094 && p.nth(offset + 1) == Token::LParen
1095 {
1096 p.expect_matches(Token::Keyword, ":theories")?;
1097 p.expect(Token::LParen)?;
1098 let m0 = p.any::<Symbol<'st>>()?;
1099 p.expect(Token::RParen)?;
1100 #[allow(clippy::useless_conversion)] return Ok(Self::Theories(m0.into()));
1101 }
1102 if p.nth_matches(offset, Token::Keyword, ":notes") {
1103 p.expect_matches(Token::Keyword, ":notes")?;
1104 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
1105 #[allow(clippy::useless_conversion)] return Ok(Self::Notes(m0.into()));
1106 }
1107 if p.nth_matches(offset, Token::Keyword, ":values") {
1108 p.expect_matches(Token::Keyword, ":values")?;
1109 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
1110 #[allow(clippy::useless_conversion)] return Ok(Self::Values(m0.into()));
1111 }
1112 if p.nth_matches(offset, Token::Keyword, ":extensions") {
1113 p.expect_matches(Token::Keyword, ":extensions")?;
1114 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
1115 #[allow(clippy::useless_conversion)] return Ok(Self::Extensions(m0.into()));
1116 }
1117 if p.nth_matches(offset, Token::Keyword, ":language") {
1118 p.expect_matches(Token::Keyword, ":language")?;
1119 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
1120 #[allow(clippy::useless_conversion)] return Ok(Self::Language(m0.into()));
1121 }
1122 if Attribute::is_start_of(offset, p) {
1123 let m0 = <Attribute<'st> as SmtlibParse<'st>>::parse(p)?;
1124 #[allow(clippy::useless_conversion)] return Ok(Self::Attribute(m0.into()));
1125 }
1126 Err(p.stuck("LogicAttribute"))
1127 }
1128}
1129#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1131#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1132pub struct Logic<'st>(pub Symbol<'st>, pub &'st [LogicAttribute<'st>]);
1133impl std::fmt::Display for Logic<'_> {
1134 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1135 write!(f, "(logic {} {})", self.0, self.1.iter().format(" "))
1136 }
1137}
1138impl<'st> Logic<'st> {
1139 pub fn parse(st: &'st Storage, src: &str) -> Result<Logic<'st>, ParseError> {
1140 <Logic<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1141 }
1142}
1143impl<'st> SmtlibParse<'st> for Logic<'st> {
1144 type Output = Logic<'st>;
1145 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1146 p.nth(offset) == Token::LParen
1147 && p.nth_matches(offset + 1, Token::Symbol, "logic")
1148 }
1149 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1150 p.expect(Token::LParen)?;
1151 p.expect_matches(Token::Symbol, "logic")?;
1152 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1153 let m1 = p.non_zero::<LogicAttribute<'st>>()?;
1154 p.expect(Token::RParen)?;
1155 Ok(Self(m0, m1))
1156 }
1157}
1158#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1160#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1161pub struct SortDec<'st>(pub Symbol<'st>, pub Numeral<'st>);
1162impl std::fmt::Display for SortDec<'_> {
1163 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1164 write!(f, "({} {})", self.0, self.1)
1165 }
1166}
1167impl<'st> SortDec<'st> {
1168 pub fn parse(st: &'st Storage, src: &str) -> Result<SortDec<'st>, ParseError> {
1169 <SortDec<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1170 }
1171}
1172impl<'st> SmtlibParse<'st> for SortDec<'st> {
1173 type Output = SortDec<'st>;
1174 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1175 p.nth(offset) == Token::LParen
1176 }
1177 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1178 p.expect(Token::LParen)?;
1179 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1180 let m1 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
1181 p.expect(Token::RParen)?;
1182 Ok(Self(m0, m1))
1183 }
1184}
1185#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1187#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1188pub struct SelectorDec<'st>(pub Symbol<'st>, pub Sort<'st>);
1189impl std::fmt::Display for SelectorDec<'_> {
1190 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1191 write!(f, "({} {})", self.0, self.1)
1192 }
1193}
1194impl<'st> SelectorDec<'st> {
1195 pub fn parse(st: &'st Storage, src: &str) -> Result<SelectorDec<'st>, ParseError> {
1196 <SelectorDec<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1197 }
1198}
1199impl<'st> SmtlibParse<'st> for SelectorDec<'st> {
1200 type Output = SelectorDec<'st>;
1201 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1202 p.nth(offset) == Token::LParen
1203 }
1204 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1205 p.expect(Token::LParen)?;
1206 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1207 let m1 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
1208 p.expect(Token::RParen)?;
1209 Ok(Self(m0, m1))
1210 }
1211}
1212#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1214#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1215pub struct ConstructorDec<'st>(pub Symbol<'st>, pub &'st [SelectorDec<'st>]);
1216impl std::fmt::Display for ConstructorDec<'_> {
1217 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1218 write!(f, "({} {})", self.0, self.1.iter().format(" "))
1219 }
1220}
1221impl<'st> ConstructorDec<'st> {
1222 pub fn parse(
1223 st: &'st Storage,
1224 src: &str,
1225 ) -> Result<ConstructorDec<'st>, ParseError> {
1226 <ConstructorDec<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1227 }
1228}
1229impl<'st> SmtlibParse<'st> for ConstructorDec<'st> {
1230 type Output = ConstructorDec<'st>;
1231 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1232 p.nth(offset) == Token::LParen
1233 }
1234 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1235 p.expect(Token::LParen)?;
1236 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1237 let m1 = p.any::<SelectorDec<'st>>()?;
1238 p.expect(Token::RParen)?;
1239 Ok(Self(m0, m1))
1240 }
1241}
1242#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1243#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1244pub enum DatatypeDec<'st> {
1245 DatatypeDec(&'st [ConstructorDec<'st>]),
1247 Par(&'st [Symbol<'st>], &'st [ConstructorDec<'st>]),
1249}
1250impl std::fmt::Display for DatatypeDec<'_> {
1251 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1252 match self {
1253 Self::DatatypeDec(m0) => write!(f, "({})", m0.iter().format(" ")),
1254 Self::Par(m0, m1) => {
1255 write!(
1256 f, "(par ({}) ({}))", m0.iter().format(" "), m1.iter().format(" ")
1257 )
1258 }
1259 }
1260 }
1261}
1262impl<'st> DatatypeDec<'st> {
1263 pub fn parse(st: &'st Storage, src: &str) -> Result<DatatypeDec<'st>, ParseError> {
1264 <DatatypeDec<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1265 }
1266}
1267impl<'st> SmtlibParse<'st> for DatatypeDec<'st> {
1268 type Output = DatatypeDec<'st>;
1269 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1270 (p.nth(offset) == Token::LParen
1271 && p.nth_matches(offset + 1, Token::Reserved, "par")
1272 && p.nth(offset + 2) == Token::LParen) || (p.nth(offset) == Token::LParen)
1273 }
1274 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1275 let offset = 0;
1276 if p.nth(offset) == Token::LParen
1277 && p.nth_matches(offset + 1, Token::Reserved, "par")
1278 && p.nth(offset + 2) == Token::LParen
1279 {
1280 p.expect(Token::LParen)?;
1281 p.expect_matches(Token::Reserved, "par")?;
1282 p.expect(Token::LParen)?;
1283 let m0 = p.non_zero::<Symbol<'st>>()?;
1284 p.expect(Token::RParen)?;
1285 p.expect(Token::LParen)?;
1286 let m1 = p.non_zero::<ConstructorDec<'st>>()?;
1287 p.expect(Token::RParen)?;
1288 p.expect(Token::RParen)?;
1289 #[allow(clippy::useless_conversion)]
1290 return Ok(Self::Par(m0.into(), m1.into()));
1291 }
1292 if p.nth(offset) == Token::LParen {
1293 p.expect(Token::LParen)?;
1294 let m0 = p.non_zero::<ConstructorDec<'st>>()?;
1295 p.expect(Token::RParen)?;
1296 #[allow(clippy::useless_conversion)] return Ok(Self::DatatypeDec(m0.into()));
1297 }
1298 Err(p.stuck("DatatypeDec"))
1299 }
1300}
1301#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1303#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1304pub struct FunctionDec<'st>(pub Symbol<'st>, pub &'st [Sort<'st>], pub Sort<'st>);
1305impl std::fmt::Display for FunctionDec<'_> {
1306 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1307 write!(f, "({} ({}) {})", self.0, self.1.iter().format(" "), self.2)
1308 }
1309}
1310impl<'st> FunctionDec<'st> {
1311 pub fn parse(st: &'st Storage, src: &str) -> Result<FunctionDec<'st>, ParseError> {
1312 <FunctionDec<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1313 }
1314}
1315impl<'st> SmtlibParse<'st> for FunctionDec<'st> {
1316 type Output = FunctionDec<'st>;
1317 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1318 p.nth(offset) == Token::LParen
1319 }
1320 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1321 p.expect(Token::LParen)?;
1322 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1323 p.expect(Token::LParen)?;
1324 let m1 = p.any::<Sort<'st>>()?;
1325 p.expect(Token::RParen)?;
1326 let m2 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
1327 p.expect(Token::RParen)?;
1328 Ok(Self(m0, m1, m2))
1329 }
1330}
1331#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1333#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1334pub struct FunctionDef<'st>(
1335 pub Symbol<'st>,
1336 pub &'st [SortedVar<'st>],
1337 pub Sort<'st>,
1338 pub &'st Term<'st>,
1339);
1340impl std::fmt::Display for FunctionDef<'_> {
1341 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1342 write!(f, "{} ({}) {} {}", self.0, self.1.iter().format(" "), self.2, self.3)
1343 }
1344}
1345impl<'st> FunctionDef<'st> {
1346 pub fn parse(st: &'st Storage, src: &str) -> Result<FunctionDef<'st>, ParseError> {
1347 <FunctionDef<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1348 }
1349}
1350impl<'st> SmtlibParse<'st> for FunctionDef<'st> {
1351 type Output = FunctionDef<'st>;
1352 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1353 Symbol::is_start_of(offset, p)
1354 }
1355 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1356 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1357 p.expect(Token::LParen)?;
1358 let m1 = p.any::<SortedVar<'st>>()?;
1359 p.expect(Token::RParen)?;
1360 let m2 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
1361 let m3 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
1362 Ok(Self(m0, m1, m2, m3))
1363 }
1364}
1365#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1366#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1367pub enum PropLiteral<'st> {
1368 Symbol(Symbol<'st>),
1370 Not(Symbol<'st>),
1372}
1373impl std::fmt::Display for PropLiteral<'_> {
1374 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1375 match self {
1376 Self::Symbol(m0) => write!(f, "{}", m0),
1377 Self::Not(m0) => write!(f, "{}", m0),
1378 }
1379 }
1380}
1381impl<'st> PropLiteral<'st> {
1382 pub fn parse(st: &'st Storage, src: &str) -> Result<PropLiteral<'st>, ParseError> {
1383 <PropLiteral<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1384 }
1385}
1386impl<'st> SmtlibParse<'st> for PropLiteral<'st> {
1387 type Output = PropLiteral<'st>;
1388 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1389 (Symbol::is_start_of(offset, p)) || (Symbol::is_start_of(offset, p))
1390 }
1391 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1392 let offset = 0;
1393 if Symbol::is_start_of(offset, p) {
1394 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1395 #[allow(clippy::useless_conversion)] return Ok(Self::Not(m0.into()));
1396 }
1397 if Symbol::is_start_of(offset, p) {
1398 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1399 #[allow(clippy::useless_conversion)] return Ok(Self::Symbol(m0.into()));
1400 }
1401 Err(p.stuck("PropLiteral"))
1402 }
1403}
1404#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1405#[cfg_attr(feature = "serde", derive(serde::Serialize))]
1406pub enum Command<'st> {
1407 Assert(&'st Term<'st>),
1409 CheckSat,
1411 CheckSatAssuming(&'st [PropLiteral<'st>]),
1413 DeclareConst(Symbol<'st>, Sort<'st>),
1415 DeclareDatatype(Symbol<'st>, DatatypeDec<'st>),
1417 DeclareDatatypes(&'st [SortDec<'st>], &'st [DatatypeDec<'st>]),
1419 DeclareFun(Symbol<'st>, &'st [Sort<'st>], Sort<'st>),
1421 DeclareSort(Symbol<'st>, Numeral<'st>),
1423 DefineFun(FunctionDef<'st>),
1425 DefineFunRec(FunctionDef<'st>),
1427 DefineFunsRec(&'st [FunctionDec<'st>], &'st [&'st Term<'st>]),
1429 DefineSort(Symbol<'st>, &'st [Symbol<'st>], Sort<'st>),
1431 Echo(&'st str),
1433 Exit,
1435 GetAssertions,
1437 GetAssignment,
1439 GetInfo(InfoFlag<'st>),
1441 GetModel,
1443 GetOption(Keyword<'st>),
1445 GetProof,
1447 GetUnsatAssumptions,
1449 GetUnsatCore,
1451 GetValue(&'st [&'st Term<'st>]),
1453 Pop(Numeral<'st>),
1455 Push(Numeral<'st>),
1457 Reset,
1459 ResetAssertions,
1461 SetInfo(Attribute<'st>),
1463 SetLogic(Symbol<'st>),
1465 SetOption(Option<'st>),
1467 Simplify(&'st Term<'st>),
1469}
1470impl std::fmt::Display for Command<'_> {
1471 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1472 match self {
1473 Self::Assert(m0) => write!(f, "(assert {})", m0),
1474 Self::CheckSat => write!(f, "(check-sat)"),
1475 Self::CheckSatAssuming(m0) => {
1476 write!(f, "(check-sat-assuming ({}))", m0.iter().format(" "))
1477 }
1478 Self::DeclareConst(m0, m1) => write!(f, "(declare-const {} {})", m0, m1),
1479 Self::DeclareDatatype(m0, m1) => {
1480 write!(f, "(declare-datatype {} {})", m0, m1)
1481 }
1482 Self::DeclareDatatypes(m0, m1) => {
1483 write!(
1484 f, "(declare-datatypes ({}) ({}))", m0.iter().format(" "), m1.iter()
1485 .format(" ")
1486 )
1487 }
1488 Self::DeclareFun(m0, m1, m2) => {
1489 write!(f, "(declare-fun {} ({}) {})", m0, m1.iter().format(" "), m2)
1490 }
1491 Self::DeclareSort(m0, m1) => write!(f, "(declare-sort {} {})", m0, m1),
1492 Self::DefineFun(m0) => write!(f, "(define-fun {})", m0),
1493 Self::DefineFunRec(m0) => write!(f, "(define-fun-rec {})", m0),
1494 Self::DefineFunsRec(m0, m1) => {
1495 write!(
1496 f, "(define-funs-rec ({}) ({}))", m0.iter().format(" "), m1.iter()
1497 .format(" ")
1498 )
1499 }
1500 Self::DefineSort(m0, m1, m2) => {
1501 write!(f, "(define-sort {} ({}) {})", m0, m1.iter().format(" "), m2)
1502 }
1503 Self::Echo(m0) => write!(f, "(echo {})", m0),
1504 Self::Exit => write!(f, "(exit)"),
1505 Self::GetAssertions => write!(f, "(get-assertions)"),
1506 Self::GetAssignment => write!(f, "(get-assignment)"),
1507 Self::GetInfo(m0) => write!(f, "(get-info {})", m0),
1508 Self::GetModel => write!(f, "(get-model)"),
1509 Self::GetOption(m0) => write!(f, "(get-option {})", m0),
1510 Self::GetProof => write!(f, "(get-proof)"),
1511 Self::GetUnsatAssumptions => write!(f, "(get-unsat-assumptions)"),
1512 Self::GetUnsatCore => write!(f, "(get-unsat-core)"),
1513 Self::GetValue(m0) => write!(f, "(get-value ({}))", m0.iter().format(" ")),
1514 Self::Pop(m0) => write!(f, "(pop {})", m0),
1515 Self::Push(m0) => write!(f, "(push {})", m0),
1516 Self::Reset => write!(f, "(reset)"),
1517 Self::ResetAssertions => write!(f, "(reset-assertions)"),
1518 Self::SetInfo(m0) => write!(f, "(set-info {})", m0),
1519 Self::SetLogic(m0) => write!(f, "(set-logic {})", m0),
1520 Self::SetOption(m0) => write!(f, "(set-option {})", m0),
1521 Self::Simplify(m0) => write!(f, "(simplify {})", m0),
1522 }
1523 }
1524}
1525impl<'st> Command<'st> {
1526 pub fn parse(st: &'st Storage, src: &str) -> Result<Command<'st>, ParseError> {
1527 <Command<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
1528 }
1529}
1530impl<'st> SmtlibParse<'st> for Command<'st> {
1531 type Output = Command<'st>;
1532 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
1533 (p.nth(offset) == Token::LParen
1534 && p.nth_matches(offset + 1, Token::Symbol, "define-funs-rec")
1535 && p.nth(offset + 2) == Token::LParen)
1536 || (p.nth(offset) == Token::LParen
1537 && p.nth_matches(offset + 1, Token::Reserved, "declare-datatypes")
1538 && p.nth(offset + 2) == Token::LParen)
1539 || (p.nth(offset) == Token::LParen
1540 && p.nth_matches(offset + 1, Token::Reserved, "get-value")
1541 && p.nth(offset + 2) == Token::LParen)
1542 || (p.nth(offset) == Token::LParen
1543 && p.nth_matches(offset + 1, Token::Reserved, "define-sort"))
1544 || (p.nth(offset) == Token::LParen
1545 && p.nth_matches(offset + 1, Token::Reserved, "declare-fun"))
1546 || (p.nth(offset) == Token::LParen
1547 && p.nth_matches(offset + 1, Token::Reserved, "check-sat-assuming")
1548 && p.nth(offset + 2) == Token::LParen)
1549 || (p.nth(offset) == Token::LParen
1550 && p.nth_matches(offset + 1, Token::Symbol, "simplify"))
1551 || (p.nth(offset) == Token::LParen
1552 && p.nth_matches(offset + 1, Token::Reserved, "set-option"))
1553 || (p.nth(offset) == Token::LParen
1554 && p.nth_matches(offset + 1, Token::Reserved, "set-logic"))
1555 || (p.nth(offset) == Token::LParen
1556 && p.nth_matches(offset + 1, Token::Reserved, "set-info"))
1557 || (p.nth(offset) == Token::LParen
1558 && p.nth_matches(offset + 1, Token::Reserved, "reset-assertions")
1559 && p.nth(offset + 2) == Token::RParen)
1560 || (p.nth(offset) == Token::LParen
1561 && p.nth_matches(offset + 1, Token::Reserved, "reset")
1562 && p.nth(offset + 2) == Token::RParen)
1563 || (p.nth(offset) == Token::LParen
1564 && p.nth_matches(offset + 1, Token::Reserved, "push"))
1565 || (p.nth(offset) == Token::LParen
1566 && p.nth_matches(offset + 1, Token::Reserved, "pop"))
1567 || (p.nth(offset) == Token::LParen
1568 && p.nth_matches(offset + 1, Token::Reserved, "get-unsat-core")
1569 && p.nth(offset + 2) == Token::RParen)
1570 || (p.nth(offset) == Token::LParen
1571 && p.nth_matches(offset + 1, Token::Reserved, "get-unsat-assumptions")
1572 && p.nth(offset + 2) == Token::RParen)
1573 || (p.nth(offset) == Token::LParen
1574 && p.nth_matches(offset + 1, Token::Reserved, "get-proof")
1575 && p.nth(offset + 2) == Token::RParen)
1576 || (p.nth(offset) == Token::LParen
1577 && p.nth_matches(offset + 1, Token::Reserved, "get-option"))
1578 || (p.nth(offset) == Token::LParen
1579 && p.nth_matches(offset + 1, Token::Reserved, "get-model")
1580 && p.nth(offset + 2) == Token::RParen)
1581 || (p.nth(offset) == Token::LParen
1582 && p.nth_matches(offset + 1, Token::Reserved, "get-info"))
1583 || (p.nth(offset) == Token::LParen
1584 && p.nth_matches(offset + 1, Token::Reserved, "get-assignment")
1585 && p.nth(offset + 2) == Token::RParen)
1586 || (p.nth(offset) == Token::LParen
1587 && p.nth_matches(offset + 1, Token::Reserved, "get-assertions")
1588 && p.nth(offset + 2) == Token::RParen)
1589 || (p.nth(offset) == Token::LParen
1590 && p.nth_matches(offset + 1, Token::Reserved, "exit")
1591 && p.nth(offset + 2) == Token::RParen)
1592 || (p.nth(offset) == Token::LParen
1593 && p.nth_matches(offset + 1, Token::Reserved, "echo"))
1594 || (p.nth(offset) == Token::LParen
1595 && p.nth_matches(offset + 1, Token::Reserved, "define-fun-rec"))
1596 || (p.nth(offset) == Token::LParen
1597 && p.nth_matches(offset + 1, Token::Reserved, "define-fun"))
1598 || (p.nth(offset) == Token::LParen
1599 && p.nth_matches(offset + 1, Token::Reserved, "declare-sort"))
1600 || (p.nth(offset) == Token::LParen
1601 && p.nth_matches(offset + 1, Token::Reserved, "declare-datatype"))
1602 || (p.nth(offset) == Token::LParen
1603 && p.nth_matches(offset + 1, Token::Reserved, "declare-const"))
1604 || (p.nth(offset) == Token::LParen
1605 && p.nth_matches(offset + 1, Token::Reserved, "check-sat")
1606 && p.nth(offset + 2) == Token::RParen)
1607 || (p.nth(offset) == Token::LParen
1608 && p.nth_matches(offset + 1, Token::Reserved, "assert"))
1609 }
1610 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
1611 let offset = 0;
1612 if p.nth(offset) == Token::LParen
1613 && p.nth_matches(offset + 1, Token::Symbol, "define-funs-rec")
1614 && p.nth(offset + 2) == Token::LParen
1615 {
1616 p.expect(Token::LParen)?;
1617 p.expect_matches(Token::Symbol, "define-funs-rec")?;
1618 p.expect(Token::LParen)?;
1619 let m0 = p.n_plus_one::<FunctionDec<'st>>()?;
1620 p.expect(Token::RParen)?;
1621 p.expect(Token::LParen)?;
1622 let m1 = p.n_plus_one::<Term<'st>>()?;
1623 p.expect(Token::RParen)?;
1624 p.expect(Token::RParen)?;
1625 #[allow(clippy::useless_conversion)]
1626 return Ok(Self::DefineFunsRec(m0.into(), m1.into()));
1627 }
1628 if p.nth(offset) == Token::LParen
1629 && p.nth_matches(offset + 1, Token::Reserved, "declare-datatypes")
1630 && p.nth(offset + 2) == Token::LParen
1631 {
1632 p.expect(Token::LParen)?;
1633 p.expect_matches(Token::Reserved, "declare-datatypes")?;
1634 p.expect(Token::LParen)?;
1635 let m0 = p.n_plus_one::<SortDec<'st>>()?;
1636 p.expect(Token::RParen)?;
1637 p.expect(Token::LParen)?;
1638 let m1 = p.n_plus_one::<DatatypeDec<'st>>()?;
1639 p.expect(Token::RParen)?;
1640 p.expect(Token::RParen)?;
1641 #[allow(clippy::useless_conversion)]
1642 return Ok(Self::DeclareDatatypes(m0.into(), m1.into()));
1643 }
1644 if p.nth(offset) == Token::LParen
1645 && p.nth_matches(offset + 1, Token::Reserved, "get-value")
1646 && p.nth(offset + 2) == Token::LParen
1647 {
1648 p.expect(Token::LParen)?;
1649 p.expect_matches(Token::Reserved, "get-value")?;
1650 p.expect(Token::LParen)?;
1651 let m0 = p.non_zero::<Term<'st>>()?;
1652 p.expect(Token::RParen)?;
1653 p.expect(Token::RParen)?;
1654 #[allow(clippy::useless_conversion)] return Ok(Self::GetValue(m0.into()));
1655 }
1656 if p.nth(offset) == Token::LParen
1657 && p.nth_matches(offset + 1, Token::Reserved, "define-sort")
1658 {
1659 p.expect(Token::LParen)?;
1660 p.expect_matches(Token::Reserved, "define-sort")?;
1661 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1662 p.expect(Token::LParen)?;
1663 let m1 = p.any::<Symbol<'st>>()?;
1664 p.expect(Token::RParen)?;
1665 let m2 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
1666 p.expect(Token::RParen)?;
1667 #[allow(clippy::useless_conversion)]
1668 return Ok(Self::DefineSort(m0.into(), m1.into(), m2.into()));
1669 }
1670 if p.nth(offset) == Token::LParen
1671 && p.nth_matches(offset + 1, Token::Reserved, "declare-fun")
1672 {
1673 p.expect(Token::LParen)?;
1674 p.expect_matches(Token::Reserved, "declare-fun")?;
1675 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1676 p.expect(Token::LParen)?;
1677 let m1 = p.any::<Sort<'st>>()?;
1678 p.expect(Token::RParen)?;
1679 let m2 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
1680 p.expect(Token::RParen)?;
1681 #[allow(clippy::useless_conversion)]
1682 return Ok(Self::DeclareFun(m0.into(), m1.into(), m2.into()));
1683 }
1684 if p.nth(offset) == Token::LParen
1685 && p.nth_matches(offset + 1, Token::Reserved, "check-sat-assuming")
1686 && p.nth(offset + 2) == Token::LParen
1687 {
1688 p.expect(Token::LParen)?;
1689 p.expect_matches(Token::Reserved, "check-sat-assuming")?;
1690 p.expect(Token::LParen)?;
1691 let m0 = p.any::<PropLiteral<'st>>()?;
1692 p.expect(Token::RParen)?;
1693 p.expect(Token::RParen)?;
1694 #[allow(clippy::useless_conversion)]
1695 return Ok(Self::CheckSatAssuming(m0.into()));
1696 }
1697 if p.nth(offset) == Token::LParen
1698 && p.nth_matches(offset + 1, Token::Symbol, "simplify")
1699 {
1700 p.expect(Token::LParen)?;
1701 p.expect_matches(Token::Symbol, "simplify")?;
1702 let m0 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
1703 p.expect(Token::RParen)?;
1704 #[allow(clippy::useless_conversion)] return Ok(Self::Simplify(m0.into()));
1705 }
1706 if p.nth(offset) == Token::LParen
1707 && p.nth_matches(offset + 1, Token::Reserved, "set-option")
1708 {
1709 p.expect(Token::LParen)?;
1710 p.expect_matches(Token::Reserved, "set-option")?;
1711 let m0 = <Option<'st> as SmtlibParse<'st>>::parse(p)?;
1712 p.expect(Token::RParen)?;
1713 #[allow(clippy::useless_conversion)] return Ok(Self::SetOption(m0.into()));
1714 }
1715 if p.nth(offset) == Token::LParen
1716 && p.nth_matches(offset + 1, Token::Reserved, "set-logic")
1717 {
1718 p.expect(Token::LParen)?;
1719 p.expect_matches(Token::Reserved, "set-logic")?;
1720 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1721 p.expect(Token::RParen)?;
1722 #[allow(clippy::useless_conversion)] return Ok(Self::SetLogic(m0.into()));
1723 }
1724 if p.nth(offset) == Token::LParen
1725 && p.nth_matches(offset + 1, Token::Reserved, "set-info")
1726 {
1727 p.expect(Token::LParen)?;
1728 p.expect_matches(Token::Reserved, "set-info")?;
1729 let m0 = <Attribute<'st> as SmtlibParse<'st>>::parse(p)?;
1730 p.expect(Token::RParen)?;
1731 #[allow(clippy::useless_conversion)] return Ok(Self::SetInfo(m0.into()));
1732 }
1733 if p.nth(offset) == Token::LParen
1734 && p.nth_matches(offset + 1, Token::Reserved, "reset-assertions")
1735 && p.nth(offset + 2) == Token::RParen
1736 {
1737 p.expect(Token::LParen)?;
1738 p.expect_matches(Token::Reserved, "reset-assertions")?;
1739 p.expect(Token::RParen)?;
1740 #[allow(clippy::useless_conversion)] return Ok(Self::ResetAssertions);
1741 }
1742 if p.nth(offset) == Token::LParen
1743 && p.nth_matches(offset + 1, Token::Reserved, "reset")
1744 && p.nth(offset + 2) == Token::RParen
1745 {
1746 p.expect(Token::LParen)?;
1747 p.expect_matches(Token::Reserved, "reset")?;
1748 p.expect(Token::RParen)?;
1749 #[allow(clippy::useless_conversion)] return Ok(Self::Reset);
1750 }
1751 if p.nth(offset) == Token::LParen
1752 && p.nth_matches(offset + 1, Token::Reserved, "push")
1753 {
1754 p.expect(Token::LParen)?;
1755 p.expect_matches(Token::Reserved, "push")?;
1756 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
1757 p.expect(Token::RParen)?;
1758 #[allow(clippy::useless_conversion)] return Ok(Self::Push(m0.into()));
1759 }
1760 if p.nth(offset) == Token::LParen
1761 && p.nth_matches(offset + 1, Token::Reserved, "pop")
1762 {
1763 p.expect(Token::LParen)?;
1764 p.expect_matches(Token::Reserved, "pop")?;
1765 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
1766 p.expect(Token::RParen)?;
1767 #[allow(clippy::useless_conversion)] return Ok(Self::Pop(m0.into()));
1768 }
1769 if p.nth(offset) == Token::LParen
1770 && p.nth_matches(offset + 1, Token::Reserved, "get-unsat-core")
1771 && p.nth(offset + 2) == Token::RParen
1772 {
1773 p.expect(Token::LParen)?;
1774 p.expect_matches(Token::Reserved, "get-unsat-core")?;
1775 p.expect(Token::RParen)?;
1776 #[allow(clippy::useless_conversion)] return Ok(Self::GetUnsatCore);
1777 }
1778 if p.nth(offset) == Token::LParen
1779 && p.nth_matches(offset + 1, Token::Reserved, "get-unsat-assumptions")
1780 && p.nth(offset + 2) == Token::RParen
1781 {
1782 p.expect(Token::LParen)?;
1783 p.expect_matches(Token::Reserved, "get-unsat-assumptions")?;
1784 p.expect(Token::RParen)?;
1785 #[allow(clippy::useless_conversion)] return Ok(Self::GetUnsatAssumptions);
1786 }
1787 if p.nth(offset) == Token::LParen
1788 && p.nth_matches(offset + 1, Token::Reserved, "get-proof")
1789 && p.nth(offset + 2) == Token::RParen
1790 {
1791 p.expect(Token::LParen)?;
1792 p.expect_matches(Token::Reserved, "get-proof")?;
1793 p.expect(Token::RParen)?;
1794 #[allow(clippy::useless_conversion)] return Ok(Self::GetProof);
1795 }
1796 if p.nth(offset) == Token::LParen
1797 && p.nth_matches(offset + 1, Token::Reserved, "get-option")
1798 {
1799 p.expect(Token::LParen)?;
1800 p.expect_matches(Token::Reserved, "get-option")?;
1801 let m0 = <Keyword<'st> as SmtlibParse<'st>>::parse(p)?;
1802 p.expect(Token::RParen)?;
1803 #[allow(clippy::useless_conversion)] return Ok(Self::GetOption(m0.into()));
1804 }
1805 if p.nth(offset) == Token::LParen
1806 && p.nth_matches(offset + 1, Token::Reserved, "get-model")
1807 && p.nth(offset + 2) == Token::RParen
1808 {
1809 p.expect(Token::LParen)?;
1810 p.expect_matches(Token::Reserved, "get-model")?;
1811 p.expect(Token::RParen)?;
1812 #[allow(clippy::useless_conversion)] return Ok(Self::GetModel);
1813 }
1814 if p.nth(offset) == Token::LParen
1815 && p.nth_matches(offset + 1, Token::Reserved, "get-info")
1816 {
1817 p.expect(Token::LParen)?;
1818 p.expect_matches(Token::Reserved, "get-info")?;
1819 let m0 = <InfoFlag<'st> as SmtlibParse<'st>>::parse(p)?;
1820 p.expect(Token::RParen)?;
1821 #[allow(clippy::useless_conversion)] return Ok(Self::GetInfo(m0.into()));
1822 }
1823 if p.nth(offset) == Token::LParen
1824 && p.nth_matches(offset + 1, Token::Reserved, "get-assignment")
1825 && p.nth(offset + 2) == Token::RParen
1826 {
1827 p.expect(Token::LParen)?;
1828 p.expect_matches(Token::Reserved, "get-assignment")?;
1829 p.expect(Token::RParen)?;
1830 #[allow(clippy::useless_conversion)] return Ok(Self::GetAssignment);
1831 }
1832 if p.nth(offset) == Token::LParen
1833 && p.nth_matches(offset + 1, Token::Reserved, "get-assertions")
1834 && p.nth(offset + 2) == Token::RParen
1835 {
1836 p.expect(Token::LParen)?;
1837 p.expect_matches(Token::Reserved, "get-assertions")?;
1838 p.expect(Token::RParen)?;
1839 #[allow(clippy::useless_conversion)] return Ok(Self::GetAssertions);
1840 }
1841 if p.nth(offset) == Token::LParen
1842 && p.nth_matches(offset + 1, Token::Reserved, "exit")
1843 && p.nth(offset + 2) == Token::RParen
1844 {
1845 p.expect(Token::LParen)?;
1846 p.expect_matches(Token::Reserved, "exit")?;
1847 p.expect(Token::RParen)?;
1848 #[allow(clippy::useless_conversion)] return Ok(Self::Exit);
1849 }
1850 if p.nth(offset) == Token::LParen
1851 && p.nth_matches(offset + 1, Token::Reserved, "echo")
1852 {
1853 p.expect(Token::LParen)?;
1854 p.expect_matches(Token::Reserved, "echo")?;
1855 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
1856 p.expect(Token::RParen)?;
1857 #[allow(clippy::useless_conversion)] return Ok(Self::Echo(m0.into()));
1858 }
1859 if p.nth(offset) == Token::LParen
1860 && p.nth_matches(offset + 1, Token::Reserved, "define-fun-rec")
1861 {
1862 p.expect(Token::LParen)?;
1863 p.expect_matches(Token::Reserved, "define-fun-rec")?;
1864 let m0 = <FunctionDef<'st> as SmtlibParse<'st>>::parse(p)?;
1865 p.expect(Token::RParen)?;
1866 #[allow(clippy::useless_conversion)]
1867 return Ok(Self::DefineFunRec(m0.into()));
1868 }
1869 if p.nth(offset) == Token::LParen
1870 && p.nth_matches(offset + 1, Token::Reserved, "define-fun")
1871 {
1872 p.expect(Token::LParen)?;
1873 p.expect_matches(Token::Reserved, "define-fun")?;
1874 let m0 = <FunctionDef<'st> as SmtlibParse<'st>>::parse(p)?;
1875 p.expect(Token::RParen)?;
1876 #[allow(clippy::useless_conversion)] return Ok(Self::DefineFun(m0.into()));
1877 }
1878 if p.nth(offset) == Token::LParen
1879 && p.nth_matches(offset + 1, Token::Reserved, "declare-sort")
1880 {
1881 p.expect(Token::LParen)?;
1882 p.expect_matches(Token::Reserved, "declare-sort")?;
1883 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1884 let m1 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
1885 p.expect(Token::RParen)?;
1886 #[allow(clippy::useless_conversion)]
1887 return Ok(Self::DeclareSort(m0.into(), m1.into()));
1888 }
1889 if p.nth(offset) == Token::LParen
1890 && p.nth_matches(offset + 1, Token::Reserved, "declare-datatype")
1891 {
1892 p.expect(Token::LParen)?;
1893 p.expect_matches(Token::Reserved, "declare-datatype")?;
1894 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1895 let m1 = <DatatypeDec<'st> as SmtlibParse<'st>>::parse(p)?;
1896 p.expect(Token::RParen)?;
1897 #[allow(clippy::useless_conversion)]
1898 return Ok(Self::DeclareDatatype(m0.into(), m1.into()));
1899 }
1900 if p.nth(offset) == Token::LParen
1901 && p.nth_matches(offset + 1, Token::Reserved, "declare-const")
1902 {
1903 p.expect(Token::LParen)?;
1904 p.expect_matches(Token::Reserved, "declare-const")?;
1905 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
1906 let m1 = <Sort<'st> as SmtlibParse<'st>>::parse(p)?;
1907 p.expect(Token::RParen)?;
1908 #[allow(clippy::useless_conversion)]
1909 return Ok(Self::DeclareConst(m0.into(), m1.into()));
1910 }
1911 if p.nth(offset) == Token::LParen
1912 && p.nth_matches(offset + 1, Token::Reserved, "check-sat")
1913 && p.nth(offset + 2) == Token::RParen
1914 {
1915 p.expect(Token::LParen)?;
1916 p.expect_matches(Token::Reserved, "check-sat")?;
1917 p.expect(Token::RParen)?;
1918 #[allow(clippy::useless_conversion)] return Ok(Self::CheckSat);
1919 }
1920 if p.nth(offset) == Token::LParen
1921 && p.nth_matches(offset + 1, Token::Reserved, "assert")
1922 {
1923 p.expect(Token::LParen)?;
1924 p.expect_matches(Token::Reserved, "assert")?;
1925 let m0 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
1926 p.expect(Token::RParen)?;
1927 #[allow(clippy::useless_conversion)] return Ok(Self::Assert(m0.into()));
1928 }
1929 Err(p.stuck("Command"))
1930 }
1931}
1932impl<'st> Command<'st> {
1933 pub fn has_response(&self) -> bool {
1934 match self {
1935 Self::Assert(_) => false,
1936 Self::CheckSat => true,
1937 Self::CheckSatAssuming(_) => true,
1938 Self::DeclareConst(_, _) => false,
1939 Self::DeclareDatatype(_, _) => false,
1940 Self::DeclareDatatypes(_, _) => false,
1941 Self::DeclareFun(_, _, _) => false,
1942 Self::DeclareSort(_, _) => false,
1943 Self::DefineFun(_) => false,
1944 Self::DefineFunRec(_) => false,
1945 Self::DefineFunsRec(_, _) => false,
1946 Self::DefineSort(_, _, _) => false,
1947 Self::Echo(_) => true,
1948 Self::Exit => false,
1949 Self::GetAssertions => true,
1950 Self::GetAssignment => true,
1951 Self::GetInfo(_) => true,
1952 Self::GetModel => true,
1953 Self::GetOption(_) => true,
1954 Self::GetProof => true,
1955 Self::GetUnsatAssumptions => true,
1956 Self::GetUnsatCore => true,
1957 Self::GetValue(_) => true,
1958 Self::Pop(_) => false,
1959 Self::Push(_) => false,
1960 Self::Reset => false,
1961 Self::ResetAssertions => false,
1962 Self::SetInfo(_) => false,
1963 Self::SetLogic(_) => false,
1964 Self::SetOption(_) => false,
1965 Self::Simplify(_) => true,
1966 }
1967 }
1968 pub fn parse_response(
1969 &self,
1970 st: &'st Storage,
1971 response: &str,
1972 ) -> Result<std::option::Option<SpecificSuccessResponse<'st>>, ParseError> {
1973 match self {
1974 Self::Assert(_) => Ok(None),
1975 Self::CheckSat => {
1976 Ok(
1977 Some(
1978 SpecificSuccessResponse::CheckSatResponse(
1979 <CheckSatResponse as SmtlibParse<
1980 'st,
1981 >>::parse(&mut Parser::new(st, response))?,
1982 ),
1983 ),
1984 )
1985 }
1986 Self::CheckSatAssuming(_) => {
1987 Ok(
1988 Some(
1989 SpecificSuccessResponse::CheckSatResponse(
1990 <CheckSatResponse as SmtlibParse<
1991 'st,
1992 >>::parse(&mut Parser::new(st, response))?,
1993 ),
1994 ),
1995 )
1996 }
1997 Self::DeclareConst(_, _) => Ok(None),
1998 Self::DeclareDatatype(_, _) => Ok(None),
1999 Self::DeclareDatatypes(_, _) => Ok(None),
2000 Self::DeclareFun(_, _, _) => Ok(None),
2001 Self::DeclareSort(_, _) => Ok(None),
2002 Self::DefineFun(_) => Ok(None),
2003 Self::DefineFunRec(_) => Ok(None),
2004 Self::DefineFunsRec(_, _) => Ok(None),
2005 Self::DefineSort(_, _, _) => Ok(None),
2006 Self::Echo(_) => {
2007 Ok(
2008 Some(
2009 SpecificSuccessResponse::EchoResponse(
2010 <EchoResponse<
2011 'st,
2012 > as SmtlibParse<
2013 'st,
2014 >>::parse(&mut Parser::new(st, response))?,
2015 ),
2016 ),
2017 )
2018 }
2019 Self::Exit => Ok(None),
2020 Self::GetAssertions => {
2021 Ok(
2022 Some(
2023 SpecificSuccessResponse::GetAssertionsResponse(
2024 <GetAssertionsResponse<
2025 'st,
2026 > as SmtlibParse<
2027 'st,
2028 >>::parse(&mut Parser::new(st, response))?,
2029 ),
2030 ),
2031 )
2032 }
2033 Self::GetAssignment => {
2034 Ok(
2035 Some(
2036 SpecificSuccessResponse::GetAssignmentResponse(
2037 <GetAssignmentResponse<
2038 'st,
2039 > as SmtlibParse<
2040 'st,
2041 >>::parse(&mut Parser::new(st, response))?,
2042 ),
2043 ),
2044 )
2045 }
2046 Self::GetInfo(_) => {
2047 Ok(
2048 Some(
2049 SpecificSuccessResponse::GetInfoResponse(
2050 <GetInfoResponse<
2051 'st,
2052 > as SmtlibParse<
2053 'st,
2054 >>::parse(&mut Parser::new(st, response))?,
2055 ),
2056 ),
2057 )
2058 }
2059 Self::GetModel => {
2060 Ok(
2061 Some(
2062 SpecificSuccessResponse::GetModelResponse(
2063 <GetModelResponse<
2064 'st,
2065 > as SmtlibParse<
2066 'st,
2067 >>::parse(&mut Parser::new(st, response))?,
2068 ),
2069 ),
2070 )
2071 }
2072 Self::GetOption(_) => {
2073 Ok(
2074 Some(
2075 SpecificSuccessResponse::GetOptionResponse(
2076 <GetOptionResponse<
2077 'st,
2078 > as SmtlibParse<
2079 'st,
2080 >>::parse(&mut Parser::new(st, response))?,
2081 ),
2082 ),
2083 )
2084 }
2085 Self::GetProof => {
2086 Ok(
2087 Some(
2088 SpecificSuccessResponse::GetProofResponse(
2089 <GetProofResponse<
2090 'st,
2091 > as SmtlibParse<
2092 'st,
2093 >>::parse(&mut Parser::new(st, response))?,
2094 ),
2095 ),
2096 )
2097 }
2098 Self::GetUnsatAssumptions => {
2099 Ok(
2100 Some(
2101 SpecificSuccessResponse::GetUnsatAssumptionsResponse(
2102 <GetUnsatAssumptionsResponse<
2103 'st,
2104 > as SmtlibParse<
2105 'st,
2106 >>::parse(&mut Parser::new(st, response))?,
2107 ),
2108 ),
2109 )
2110 }
2111 Self::GetUnsatCore => {
2112 Ok(
2113 Some(
2114 SpecificSuccessResponse::GetUnsatCoreResponse(
2115 <GetUnsatCoreResponse<
2116 'st,
2117 > as SmtlibParse<
2118 'st,
2119 >>::parse(&mut Parser::new(st, response))?,
2120 ),
2121 ),
2122 )
2123 }
2124 Self::GetValue(_) => {
2125 Ok(
2126 Some(
2127 SpecificSuccessResponse::GetValueResponse(
2128 <GetValueResponse<
2129 'st,
2130 > as SmtlibParse<
2131 'st,
2132 >>::parse(&mut Parser::new(st, response))?,
2133 ),
2134 ),
2135 )
2136 }
2137 Self::Pop(_) => Ok(None),
2138 Self::Push(_) => Ok(None),
2139 Self::Reset => Ok(None),
2140 Self::ResetAssertions => Ok(None),
2141 Self::SetInfo(_) => Ok(None),
2142 Self::SetLogic(_) => Ok(None),
2143 Self::SetOption(_) => Ok(None),
2144 Self::Simplify(_) => {
2145 Ok(
2146 Some(
2147 SpecificSuccessResponse::SimplifyResponse(
2148 <SimplifyResponse<
2149 'st,
2150 > as SmtlibParse<
2151 'st,
2152 >>::parse(&mut Parser::new(st, response))?,
2153 ),
2154 ),
2155 )
2156 }
2157 }
2158 }
2159}
2160#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2162#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2163pub struct Script<'st>(pub &'st [Command<'st>]);
2164impl std::fmt::Display for Script<'_> {
2165 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2166 write!(f, "{}", self.0.iter().format("\n"))
2167 }
2168}
2169impl<'st> Script<'st> {
2170 pub fn parse(st: &'st Storage, src: &str) -> Result<Script<'st>, ParseError> {
2171 <Script<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2172 }
2173}
2174impl<'st> SmtlibParse<'st> for Script<'st> {
2175 type Output = Script<'st>;
2176 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2177 todo!("{offset:?}, {p:?}")
2178 }
2179 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2180 let m0 = p.any::<Command<'st>>()?;
2181 Ok(Self(m0))
2182 }
2183}
2184#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2185#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2186pub enum Option<'st> {
2187 DiagnosticOutputChannel(&'st str),
2189 GlobalDeclarations(BValue),
2191 InteractiveMode(BValue),
2193 PrintSuccess(BValue),
2195 ProduceAssertions(BValue),
2197 ProduceAssignments(BValue),
2199 ProduceModels(BValue),
2201 ProduceProofs(BValue),
2203 ProduceUnsatAssumptions(BValue),
2205 ProduceUnsatCores(BValue),
2207 RandomSeed(Numeral<'st>),
2209 RegularOutputChannel(&'st str),
2211 ReproducibleResourceLimit(Numeral<'st>),
2213 Verbosity(Numeral<'st>),
2215 Attribute(Attribute<'st>),
2217}
2218impl std::fmt::Display for Option<'_> {
2219 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2220 match self {
2221 Self::DiagnosticOutputChannel(m0) => {
2222 write!(f, ":diagnostic-output-channel {}", m0)
2223 }
2224 Self::GlobalDeclarations(m0) => write!(f, ":global-declarations {}", m0),
2225 Self::InteractiveMode(m0) => write!(f, ":interactive-mode {}", m0),
2226 Self::PrintSuccess(m0) => write!(f, ":print-success {}", m0),
2227 Self::ProduceAssertions(m0) => write!(f, ":produce-assertions {}", m0),
2228 Self::ProduceAssignments(m0) => write!(f, ":produce-assignments {}", m0),
2229 Self::ProduceModels(m0) => write!(f, ":produce-models {}", m0),
2230 Self::ProduceProofs(m0) => write!(f, ":produce-proofs {}", m0),
2231 Self::ProduceUnsatAssumptions(m0) => {
2232 write!(f, ":produce-unsat-assumptions {}", m0)
2233 }
2234 Self::ProduceUnsatCores(m0) => write!(f, ":produce-unsat-cores {}", m0),
2235 Self::RandomSeed(m0) => write!(f, ":random-seed {}", m0),
2236 Self::RegularOutputChannel(m0) => write!(f, ":regular-output-channel {}", m0),
2237 Self::ReproducibleResourceLimit(m0) => {
2238 write!(f, ":reproducible-resource-limit {}", m0)
2239 }
2240 Self::Verbosity(m0) => write!(f, ":verbosity {}", m0),
2241 Self::Attribute(m0) => write!(f, "{}", m0),
2242 }
2243 }
2244}
2245impl<'st> Option<'st> {
2246 pub fn parse(st: &'st Storage, src: &str) -> Result<Option<'st>, ParseError> {
2247 <Option<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2248 }
2249}
2250impl<'st> SmtlibParse<'st> for Option<'st> {
2251 type Output = Option<'st>;
2252 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2253 (p.nth_matches(offset, Token::Keyword, ":verbosity"))
2254 || (p.nth_matches(offset, Token::Keyword, ":reproducible-resource-limit"))
2255 || (p.nth_matches(offset, Token::Keyword, ":regular-output-channel"))
2256 || (p.nth_matches(offset, Token::Keyword, ":random-seed"))
2257 || (p.nth_matches(offset, Token::Keyword, ":produce-unsat-cores"))
2258 || (p.nth_matches(offset, Token::Keyword, ":produce-unsat-assumptions"))
2259 || (p.nth_matches(offset, Token::Keyword, ":produce-proofs"))
2260 || (p.nth_matches(offset, Token::Keyword, ":produce-models"))
2261 || (p.nth_matches(offset, Token::Keyword, ":produce-assignments"))
2262 || (p.nth_matches(offset, Token::Keyword, ":produce-assertions"))
2263 || (p.nth_matches(offset, Token::Keyword, ":print-success"))
2264 || (p.nth_matches(offset, Token::Keyword, ":interactive-mode"))
2265 || (p.nth_matches(offset, Token::Keyword, ":global-declarations"))
2266 || (p.nth_matches(offset, Token::Keyword, ":diagnostic-output-channel"))
2267 || (Attribute::is_start_of(offset, p))
2268 }
2269 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2270 let offset = 0;
2271 if p.nth_matches(offset, Token::Keyword, ":verbosity") {
2272 p.expect_matches(Token::Keyword, ":verbosity")?;
2273 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
2274 #[allow(clippy::useless_conversion)] return Ok(Self::Verbosity(m0.into()));
2275 }
2276 if p.nth_matches(offset, Token::Keyword, ":reproducible-resource-limit") {
2277 p.expect_matches(Token::Keyword, ":reproducible-resource-limit")?;
2278 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
2279 #[allow(clippy::useless_conversion)]
2280 return Ok(Self::ReproducibleResourceLimit(m0.into()));
2281 }
2282 if p.nth_matches(offset, Token::Keyword, ":regular-output-channel") {
2283 p.expect_matches(Token::Keyword, ":regular-output-channel")?;
2284 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
2285 #[allow(clippy::useless_conversion)]
2286 return Ok(Self::RegularOutputChannel(m0.into()));
2287 }
2288 if p.nth_matches(offset, Token::Keyword, ":random-seed") {
2289 p.expect_matches(Token::Keyword, ":random-seed")?;
2290 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
2291 #[allow(clippy::useless_conversion)] return Ok(Self::RandomSeed(m0.into()));
2292 }
2293 if p.nth_matches(offset, Token::Keyword, ":produce-unsat-cores") {
2294 p.expect_matches(Token::Keyword, ":produce-unsat-cores")?;
2295 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2296 #[allow(clippy::useless_conversion)]
2297 return Ok(Self::ProduceUnsatCores(m0.into()));
2298 }
2299 if p.nth_matches(offset, Token::Keyword, ":produce-unsat-assumptions") {
2300 p.expect_matches(Token::Keyword, ":produce-unsat-assumptions")?;
2301 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2302 #[allow(clippy::useless_conversion)]
2303 return Ok(Self::ProduceUnsatAssumptions(m0.into()));
2304 }
2305 if p.nth_matches(offset, Token::Keyword, ":produce-proofs") {
2306 p.expect_matches(Token::Keyword, ":produce-proofs")?;
2307 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2308 #[allow(clippy::useless_conversion)]
2309 return Ok(Self::ProduceProofs(m0.into()));
2310 }
2311 if p.nth_matches(offset, Token::Keyword, ":produce-models") {
2312 p.expect_matches(Token::Keyword, ":produce-models")?;
2313 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2314 #[allow(clippy::useless_conversion)]
2315 return Ok(Self::ProduceModels(m0.into()));
2316 }
2317 if p.nth_matches(offset, Token::Keyword, ":produce-assignments") {
2318 p.expect_matches(Token::Keyword, ":produce-assignments")?;
2319 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2320 #[allow(clippy::useless_conversion)]
2321 return Ok(Self::ProduceAssignments(m0.into()));
2322 }
2323 if p.nth_matches(offset, Token::Keyword, ":produce-assertions") {
2324 p.expect_matches(Token::Keyword, ":produce-assertions")?;
2325 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2326 #[allow(clippy::useless_conversion)]
2327 return Ok(Self::ProduceAssertions(m0.into()));
2328 }
2329 if p.nth_matches(offset, Token::Keyword, ":print-success") {
2330 p.expect_matches(Token::Keyword, ":print-success")?;
2331 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2332 #[allow(clippy::useless_conversion)]
2333 return Ok(Self::PrintSuccess(m0.into()));
2334 }
2335 if p.nth_matches(offset, Token::Keyword, ":interactive-mode") {
2336 p.expect_matches(Token::Keyword, ":interactive-mode")?;
2337 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2338 #[allow(clippy::useless_conversion)]
2339 return Ok(Self::InteractiveMode(m0.into()));
2340 }
2341 if p.nth_matches(offset, Token::Keyword, ":global-declarations") {
2342 p.expect_matches(Token::Keyword, ":global-declarations")?;
2343 let m0 = <BValue as SmtlibParse<'st>>::parse(p)?;
2344 #[allow(clippy::useless_conversion)]
2345 return Ok(Self::GlobalDeclarations(m0.into()));
2346 }
2347 if p.nth_matches(offset, Token::Keyword, ":diagnostic-output-channel") {
2348 p.expect_matches(Token::Keyword, ":diagnostic-output-channel")?;
2349 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
2350 #[allow(clippy::useless_conversion)]
2351 return Ok(Self::DiagnosticOutputChannel(m0.into()));
2352 }
2353 if Attribute::is_start_of(offset, p) {
2354 let m0 = <Attribute<'st> as SmtlibParse<'st>>::parse(p)?;
2355 #[allow(clippy::useless_conversion)] return Ok(Self::Attribute(m0.into()));
2356 }
2357 Err(p.stuck("Option"))
2358 }
2359}
2360#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2361#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2362pub enum InfoFlag<'st> {
2363 AllStatistics,
2365 AssertionStackLevels,
2367 Authors,
2369 ErrorBehavior,
2371 Name,
2373 ReasonUnknown,
2375 Version,
2377 Keyword(Keyword<'st>),
2379}
2380impl std::fmt::Display for InfoFlag<'_> {
2381 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2382 match self {
2383 Self::AllStatistics => write!(f, ":all-statistics"),
2384 Self::AssertionStackLevels => write!(f, ":assertion-stack-levels"),
2385 Self::Authors => write!(f, ":authors"),
2386 Self::ErrorBehavior => write!(f, ":error-behavior"),
2387 Self::Name => write!(f, ":name"),
2388 Self::ReasonUnknown => write!(f, ":reason-unknown"),
2389 Self::Version => write!(f, ":version"),
2390 Self::Keyword(m0) => write!(f, "{}", m0),
2391 }
2392 }
2393}
2394impl<'st> InfoFlag<'st> {
2395 pub fn parse(st: &'st Storage, src: &str) -> Result<InfoFlag<'st>, ParseError> {
2396 <InfoFlag<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2397 }
2398}
2399impl<'st> SmtlibParse<'st> for InfoFlag<'st> {
2400 type Output = InfoFlag<'st>;
2401 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2402 (p.nth_matches(offset, Token::Keyword, ":version"))
2403 || (p.nth_matches(offset, Token::Keyword, ":reason-unknown"))
2404 || (p.nth_matches(offset, Token::Keyword, ":name"))
2405 || (p.nth_matches(offset, Token::Keyword, ":error-behavior"))
2406 || (p.nth_matches(offset, Token::Keyword, ":authors"))
2407 || (p.nth_matches(offset, Token::Keyword, ":assertion-stack-levels"))
2408 || (p.nth_matches(offset, Token::Keyword, ":all-statistics"))
2409 || (Keyword::is_start_of(offset, p))
2410 }
2411 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2412 let offset = 0;
2413 if p.nth_matches(offset, Token::Keyword, ":version") {
2414 p.expect_matches(Token::Keyword, ":version")?;
2415 #[allow(clippy::useless_conversion)] return Ok(Self::Version);
2416 }
2417 if p.nth_matches(offset, Token::Keyword, ":reason-unknown") {
2418 p.expect_matches(Token::Keyword, ":reason-unknown")?;
2419 #[allow(clippy::useless_conversion)] return Ok(Self::ReasonUnknown);
2420 }
2421 if p.nth_matches(offset, Token::Keyword, ":name") {
2422 p.expect_matches(Token::Keyword, ":name")?;
2423 #[allow(clippy::useless_conversion)] return Ok(Self::Name);
2424 }
2425 if p.nth_matches(offset, Token::Keyword, ":error-behavior") {
2426 p.expect_matches(Token::Keyword, ":error-behavior")?;
2427 #[allow(clippy::useless_conversion)] return Ok(Self::ErrorBehavior);
2428 }
2429 if p.nth_matches(offset, Token::Keyword, ":authors") {
2430 p.expect_matches(Token::Keyword, ":authors")?;
2431 #[allow(clippy::useless_conversion)] return Ok(Self::Authors);
2432 }
2433 if p.nth_matches(offset, Token::Keyword, ":assertion-stack-levels") {
2434 p.expect_matches(Token::Keyword, ":assertion-stack-levels")?;
2435 #[allow(clippy::useless_conversion)] return Ok(Self::AssertionStackLevels);
2436 }
2437 if p.nth_matches(offset, Token::Keyword, ":all-statistics") {
2438 p.expect_matches(Token::Keyword, ":all-statistics")?;
2439 #[allow(clippy::useless_conversion)] return Ok(Self::AllStatistics);
2440 }
2441 if Keyword::is_start_of(offset, p) {
2442 let m0 = <Keyword<'st> as SmtlibParse<'st>>::parse(p)?;
2443 #[allow(clippy::useless_conversion)] return Ok(Self::Keyword(m0.into()));
2444 }
2445 Err(p.stuck("InfoFlag"))
2446 }
2447}
2448#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2449#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2450pub enum ErrorBehavior {
2451 ImmediateExit,
2453 ContinuedExecution,
2455}
2456impl std::fmt::Display for ErrorBehavior {
2457 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2458 match self {
2459 Self::ImmediateExit => write!(f, "immediate-exit"),
2460 Self::ContinuedExecution => write!(f, "continued-execution"),
2461 }
2462 }
2463}
2464impl<'st> ErrorBehavior {
2465 pub fn parse(st: &'st Storage, src: &str) -> Result<ErrorBehavior, ParseError> {
2466 <ErrorBehavior as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2467 }
2468}
2469impl<'st> SmtlibParse<'st> for ErrorBehavior {
2470 type Output = ErrorBehavior;
2471 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2472 (p.nth_matches(offset, Token::Symbol, "continued-execution"))
2473 || (p.nth_matches(offset, Token::Symbol, "immediate-exit"))
2474 }
2475 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2476 let offset = 0;
2477 if p.nth_matches(offset, Token::Symbol, "continued-execution") {
2478 p.expect_matches(Token::Symbol, "continued-execution")?;
2479 #[allow(clippy::useless_conversion)] return Ok(Self::ContinuedExecution);
2480 }
2481 if p.nth_matches(offset, Token::Symbol, "immediate-exit") {
2482 p.expect_matches(Token::Symbol, "immediate-exit")?;
2483 #[allow(clippy::useless_conversion)] return Ok(Self::ImmediateExit);
2484 }
2485 Err(p.stuck("ErrorBehavior"))
2486 }
2487}
2488#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2489#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2490pub enum ReasonUnknown<'st> {
2491 Memout,
2493 Incomplete,
2495 SExpr(SExpr<'st>),
2497}
2498impl std::fmt::Display for ReasonUnknown<'_> {
2499 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2500 match self {
2501 Self::Memout => write!(f, "memout"),
2502 Self::Incomplete => write!(f, "incomplete"),
2503 Self::SExpr(m0) => write!(f, "{}", m0),
2504 }
2505 }
2506}
2507impl<'st> ReasonUnknown<'st> {
2508 pub fn parse(st: &'st Storage, src: &str) -> Result<ReasonUnknown<'st>, ParseError> {
2509 <ReasonUnknown<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2510 }
2511}
2512impl<'st> SmtlibParse<'st> for ReasonUnknown<'st> {
2513 type Output = ReasonUnknown<'st>;
2514 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2515 (p.nth_matches(offset, Token::Symbol, "incomplete"))
2516 || (p.nth_matches(offset, Token::Symbol, "memout"))
2517 || (SExpr::is_start_of(offset, p))
2518 }
2519 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2520 let offset = 0;
2521 if p.nth_matches(offset, Token::Symbol, "incomplete") {
2522 p.expect_matches(Token::Symbol, "incomplete")?;
2523 #[allow(clippy::useless_conversion)] return Ok(Self::Incomplete);
2524 }
2525 if p.nth_matches(offset, Token::Symbol, "memout") {
2526 p.expect_matches(Token::Symbol, "memout")?;
2527 #[allow(clippy::useless_conversion)] return Ok(Self::Memout);
2528 }
2529 if SExpr::is_start_of(offset, p) {
2530 let m0 = <SExpr<'st> as SmtlibParse<'st>>::parse(p)?;
2531 #[allow(clippy::useless_conversion)] return Ok(Self::SExpr(m0.into()));
2532 }
2533 Err(p.stuck("ReasonUnknown"))
2534 }
2535}
2536#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2537#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2538pub enum ModelResponse<'st> {
2539 DefineFun(FunctionDef<'st>),
2541 DefineFunRec(FunctionDef<'st>),
2543 DefineFunsRec(&'st [FunctionDec<'st>], &'st [&'st Term<'st>]),
2545}
2546impl std::fmt::Display for ModelResponse<'_> {
2547 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2548 match self {
2549 Self::DefineFun(m0) => write!(f, "(define-fun {})", m0),
2550 Self::DefineFunRec(m0) => write!(f, "(define-fun-rec {})", m0),
2551 Self::DefineFunsRec(m0, m1) => {
2552 write!(
2553 f, "(define-funs-rec ({}) ({}))", m0.iter().format(" "), m1.iter()
2554 .format(" ")
2555 )
2556 }
2557 }
2558 }
2559}
2560impl<'st> ModelResponse<'st> {
2561 pub fn parse(st: &'st Storage, src: &str) -> Result<ModelResponse<'st>, ParseError> {
2562 <ModelResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2563 }
2564}
2565impl<'st> SmtlibParse<'st> for ModelResponse<'st> {
2566 type Output = ModelResponse<'st>;
2567 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2568 (p.nth(offset) == Token::LParen
2569 && p.nth_matches(offset + 1, Token::Symbol, "define-funs-rec")
2570 && p.nth(offset + 2) == Token::LParen)
2571 || (p.nth(offset) == Token::LParen
2572 && p.nth_matches(offset + 1, Token::Reserved, "define-fun-rec"))
2573 || (p.nth(offset) == Token::LParen
2574 && p.nth_matches(offset + 1, Token::Reserved, "define-fun"))
2575 }
2576 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2577 let offset = 0;
2578 if p.nth(offset) == Token::LParen
2579 && p.nth_matches(offset + 1, Token::Symbol, "define-funs-rec")
2580 && p.nth(offset + 2) == Token::LParen
2581 {
2582 p.expect(Token::LParen)?;
2583 p.expect_matches(Token::Symbol, "define-funs-rec")?;
2584 p.expect(Token::LParen)?;
2585 let m0 = p.n_plus_one::<FunctionDec<'st>>()?;
2586 p.expect(Token::RParen)?;
2587 p.expect(Token::LParen)?;
2588 let m1 = p.n_plus_one::<Term<'st>>()?;
2589 p.expect(Token::RParen)?;
2590 p.expect(Token::RParen)?;
2591 #[allow(clippy::useless_conversion)]
2592 return Ok(Self::DefineFunsRec(m0.into(), m1.into()));
2593 }
2594 if p.nth(offset) == Token::LParen
2595 && p.nth_matches(offset + 1, Token::Reserved, "define-fun-rec")
2596 {
2597 p.expect(Token::LParen)?;
2598 p.expect_matches(Token::Reserved, "define-fun-rec")?;
2599 let m0 = <FunctionDef<'st> as SmtlibParse<'st>>::parse(p)?;
2600 p.expect(Token::RParen)?;
2601 #[allow(clippy::useless_conversion)]
2602 return Ok(Self::DefineFunRec(m0.into()));
2603 }
2604 if p.nth(offset) == Token::LParen
2605 && p.nth_matches(offset + 1, Token::Reserved, "define-fun")
2606 {
2607 p.expect(Token::LParen)?;
2608 p.expect_matches(Token::Reserved, "define-fun")?;
2609 let m0 = <FunctionDef<'st> as SmtlibParse<'st>>::parse(p)?;
2610 p.expect(Token::RParen)?;
2611 #[allow(clippy::useless_conversion)] return Ok(Self::DefineFun(m0.into()));
2612 }
2613 Err(p.stuck("ModelResponse"))
2614 }
2615}
2616#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2617#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2618pub enum InfoResponse<'st> {
2619 AssertionStackLevels(Numeral<'st>),
2621 Authors(&'st str),
2623 ErrorBehavior(ErrorBehavior),
2625 Name(&'st str),
2627 ReasonUnknown(ReasonUnknown<'st>),
2629 Version(&'st str),
2631 Attribute(Attribute<'st>),
2633}
2634impl std::fmt::Display for InfoResponse<'_> {
2635 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2636 match self {
2637 Self::AssertionStackLevels(m0) => write!(f, ":assertion-stack-levels {}", m0),
2638 Self::Authors(m0) => write!(f, ":authors {}", m0),
2639 Self::ErrorBehavior(m0) => write!(f, ":error-behavior {}", m0),
2640 Self::Name(m0) => write!(f, ":name {}", m0),
2641 Self::ReasonUnknown(m0) => write!(f, ":reason-unknown {}", m0),
2642 Self::Version(m0) => write!(f, ":version {}", m0),
2643 Self::Attribute(m0) => write!(f, "{}", m0),
2644 }
2645 }
2646}
2647impl<'st> InfoResponse<'st> {
2648 pub fn parse(st: &'st Storage, src: &str) -> Result<InfoResponse<'st>, ParseError> {
2649 <InfoResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2650 }
2651}
2652impl<'st> SmtlibParse<'st> for InfoResponse<'st> {
2653 type Output = InfoResponse<'st>;
2654 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2655 (p.nth_matches(offset, Token::Keyword, ":version"))
2656 || (p.nth_matches(offset, Token::Keyword, ":reason-unknown"))
2657 || (p.nth_matches(offset, Token::Keyword, ":name"))
2658 || (p.nth_matches(offset, Token::Keyword, ":error-behavior"))
2659 || (p.nth_matches(offset, Token::Keyword, ":authors"))
2660 || (p.nth_matches(offset, Token::Keyword, ":assertion-stack-levels"))
2661 || (Attribute::is_start_of(offset, p))
2662 }
2663 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2664 let offset = 0;
2665 if p.nth_matches(offset, Token::Keyword, ":version") {
2666 p.expect_matches(Token::Keyword, ":version")?;
2667 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
2668 #[allow(clippy::useless_conversion)] return Ok(Self::Version(m0.into()));
2669 }
2670 if p.nth_matches(offset, Token::Keyword, ":reason-unknown") {
2671 p.expect_matches(Token::Keyword, ":reason-unknown")?;
2672 let m0 = <ReasonUnknown<'st> as SmtlibParse<'st>>::parse(p)?;
2673 #[allow(clippy::useless_conversion)]
2674 return Ok(Self::ReasonUnknown(m0.into()));
2675 }
2676 if p.nth_matches(offset, Token::Keyword, ":name") {
2677 p.expect_matches(Token::Keyword, ":name")?;
2678 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
2679 #[allow(clippy::useless_conversion)] return Ok(Self::Name(m0.into()));
2680 }
2681 if p.nth_matches(offset, Token::Keyword, ":error-behavior") {
2682 p.expect_matches(Token::Keyword, ":error-behavior")?;
2683 let m0 = <ErrorBehavior as SmtlibParse<'st>>::parse(p)?;
2684 #[allow(clippy::useless_conversion)]
2685 return Ok(Self::ErrorBehavior(m0.into()));
2686 }
2687 if p.nth_matches(offset, Token::Keyword, ":authors") {
2688 p.expect_matches(Token::Keyword, ":authors")?;
2689 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
2690 #[allow(clippy::useless_conversion)] return Ok(Self::Authors(m0.into()));
2691 }
2692 if p.nth_matches(offset, Token::Keyword, ":assertion-stack-levels") {
2693 p.expect_matches(Token::Keyword, ":assertion-stack-levels")?;
2694 let m0 = <Numeral<'st> as SmtlibParse<'st>>::parse(p)?;
2695 #[allow(clippy::useless_conversion)]
2696 return Ok(Self::AssertionStackLevels(m0.into()));
2697 }
2698 if Attribute::is_start_of(offset, p) {
2699 let m0 = <Attribute<'st> as SmtlibParse<'st>>::parse(p)?;
2700 #[allow(clippy::useless_conversion)] return Ok(Self::Attribute(m0.into()));
2701 }
2702 Err(p.stuck("InfoResponse"))
2703 }
2704}
2705#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2707#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2708pub struct ValuationPair<'st>(pub &'st Term<'st>, pub &'st Term<'st>);
2709impl std::fmt::Display for ValuationPair<'_> {
2710 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2711 write!(f, "({} {})", self.0, self.1)
2712 }
2713}
2714impl<'st> ValuationPair<'st> {
2715 pub fn parse(st: &'st Storage, src: &str) -> Result<ValuationPair<'st>, ParseError> {
2716 <ValuationPair<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2717 }
2718}
2719impl<'st> SmtlibParse<'st> for ValuationPair<'st> {
2720 type Output = ValuationPair<'st>;
2721 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2722 p.nth(offset) == Token::LParen
2723 }
2724 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2725 p.expect(Token::LParen)?;
2726 let m0 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
2727 let m1 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
2728 p.expect(Token::RParen)?;
2729 Ok(Self(m0, m1))
2730 }
2731}
2732#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2734#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2735pub struct TValuationPair<'st>(pub Symbol<'st>, pub BValue);
2736impl std::fmt::Display for TValuationPair<'_> {
2737 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2738 write!(f, "({} {})", self.0, self.1)
2739 }
2740}
2741impl<'st> TValuationPair<'st> {
2742 pub fn parse(
2743 st: &'st Storage,
2744 src: &str,
2745 ) -> Result<TValuationPair<'st>, ParseError> {
2746 <TValuationPair<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2747 }
2748}
2749impl<'st> SmtlibParse<'st> for TValuationPair<'st> {
2750 type Output = TValuationPair<'st>;
2751 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2752 p.nth(offset) == Token::LParen
2753 }
2754 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2755 p.expect(Token::LParen)?;
2756 let m0 = <Symbol<'st> as SmtlibParse<'st>>::parse(p)?;
2757 let m1 = <BValue as SmtlibParse<'st>>::parse(p)?;
2758 p.expect(Token::RParen)?;
2759 Ok(Self(m0, m1))
2760 }
2761}
2762#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2763#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2764pub enum CheckSatResponse {
2765 Sat,
2767 Unsat,
2769 Unknown,
2771}
2772impl std::fmt::Display for CheckSatResponse {
2773 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2774 match self {
2775 Self::Sat => write!(f, "sat"),
2776 Self::Unsat => write!(f, "unsat"),
2777 Self::Unknown => write!(f, "unknown"),
2778 }
2779 }
2780}
2781impl<'st> CheckSatResponse {
2782 pub fn parse(st: &'st Storage, src: &str) -> Result<CheckSatResponse, ParseError> {
2783 <CheckSatResponse as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2784 }
2785}
2786impl<'st> SmtlibParse<'st> for CheckSatResponse {
2787 type Output = CheckSatResponse;
2788 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2789 (p.nth_matches(offset, Token::Symbol, "unknown"))
2790 || (p.nth_matches(offset, Token::Symbol, "unsat"))
2791 || (p.nth_matches(offset, Token::Symbol, "sat"))
2792 }
2793 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2794 let offset = 0;
2795 if p.nth_matches(offset, Token::Symbol, "unknown") {
2796 p.expect_matches(Token::Symbol, "unknown")?;
2797 #[allow(clippy::useless_conversion)] return Ok(Self::Unknown);
2798 }
2799 if p.nth_matches(offset, Token::Symbol, "unsat") {
2800 p.expect_matches(Token::Symbol, "unsat")?;
2801 #[allow(clippy::useless_conversion)] return Ok(Self::Unsat);
2802 }
2803 if p.nth_matches(offset, Token::Symbol, "sat") {
2804 p.expect_matches(Token::Symbol, "sat")?;
2805 #[allow(clippy::useless_conversion)] return Ok(Self::Sat);
2806 }
2807 Err(p.stuck("CheckSatResponse"))
2808 }
2809}
2810#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2812#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2813pub struct EchoResponse<'st>(pub &'st str);
2814impl std::fmt::Display for EchoResponse<'_> {
2815 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2816 write!(f, "{}", self.0)
2817 }
2818}
2819impl<'st> EchoResponse<'st> {
2820 pub fn parse(st: &'st Storage, src: &str) -> Result<EchoResponse<'st>, ParseError> {
2821 <EchoResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2822 }
2823}
2824impl<'st> SmtlibParse<'st> for EchoResponse<'st> {
2825 type Output = EchoResponse<'st>;
2826 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2827 String::is_start_of(offset, p)
2828 }
2829 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2830 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
2831 Ok(Self(m0))
2832 }
2833}
2834#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2836#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2837pub struct GetAssertionsResponse<'st>(pub &'st [&'st Term<'st>]);
2838impl std::fmt::Display for GetAssertionsResponse<'_> {
2839 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2840 write!(f, "({})", self.0.iter().format(" "))
2841 }
2842}
2843impl<'st> GetAssertionsResponse<'st> {
2844 pub fn parse(
2845 st: &'st Storage,
2846 src: &str,
2847 ) -> Result<GetAssertionsResponse<'st>, ParseError> {
2848 <GetAssertionsResponse<
2849 'st,
2850 > as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2851 }
2852}
2853impl<'st> SmtlibParse<'st> for GetAssertionsResponse<'st> {
2854 type Output = GetAssertionsResponse<'st>;
2855 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2856 p.nth(offset) == Token::LParen
2857 }
2858 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2859 p.expect(Token::LParen)?;
2860 let m0 = p.any::<Term<'st>>()?;
2861 p.expect(Token::RParen)?;
2862 Ok(Self(m0))
2863 }
2864}
2865#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2867#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2868pub struct GetAssignmentResponse<'st>(pub &'st [TValuationPair<'st>]);
2869impl std::fmt::Display for GetAssignmentResponse<'_> {
2870 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2871 write!(f, "({})", self.0.iter().format(" "))
2872 }
2873}
2874impl<'st> GetAssignmentResponse<'st> {
2875 pub fn parse(
2876 st: &'st Storage,
2877 src: &str,
2878 ) -> Result<GetAssignmentResponse<'st>, ParseError> {
2879 <GetAssignmentResponse<
2880 'st,
2881 > as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2882 }
2883}
2884impl<'st> SmtlibParse<'st> for GetAssignmentResponse<'st> {
2885 type Output = GetAssignmentResponse<'st>;
2886 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2887 p.nth(offset) == Token::LParen
2888 }
2889 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2890 p.expect(Token::LParen)?;
2891 let m0 = p.any::<TValuationPair<'st>>()?;
2892 p.expect(Token::RParen)?;
2893 Ok(Self(m0))
2894 }
2895}
2896#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2898#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2899pub struct GetInfoResponse<'st>(pub &'st [InfoResponse<'st>]);
2900impl std::fmt::Display for GetInfoResponse<'_> {
2901 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2902 write!(f, "({})", self.0.iter().format(" "))
2903 }
2904}
2905impl<'st> GetInfoResponse<'st> {
2906 pub fn parse(
2907 st: &'st Storage,
2908 src: &str,
2909 ) -> Result<GetInfoResponse<'st>, ParseError> {
2910 <GetInfoResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2911 }
2912}
2913impl<'st> SmtlibParse<'st> for GetInfoResponse<'st> {
2914 type Output = GetInfoResponse<'st>;
2915 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2916 p.nth(offset) == Token::LParen
2917 }
2918 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2919 p.expect(Token::LParen)?;
2920 let m0 = p.non_zero::<InfoResponse<'st>>()?;
2921 p.expect(Token::RParen)?;
2922 Ok(Self(m0))
2923 }
2924}
2925#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2927#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2928pub struct GetModelResponse<'st>(pub &'st [ModelResponse<'st>]);
2929impl std::fmt::Display for GetModelResponse<'_> {
2930 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2931 write!(f, "({})", self.0.iter().format(" "))
2932 }
2933}
2934impl<'st> GetModelResponse<'st> {
2935 pub fn parse(
2936 st: &'st Storage,
2937 src: &str,
2938 ) -> Result<GetModelResponse<'st>, ParseError> {
2939 <GetModelResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2940 }
2941}
2942impl<'st> SmtlibParse<'st> for GetModelResponse<'st> {
2943 type Output = GetModelResponse<'st>;
2944 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2945 p.nth(offset) == Token::LParen
2946 }
2947 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2948 p.expect(Token::LParen)?;
2949 let m0 = p.any::<ModelResponse<'st>>()?;
2950 p.expect(Token::RParen)?;
2951 Ok(Self(m0))
2952 }
2953}
2954#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2956#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2957pub struct GetOptionResponse<'st>(pub AttributeValue<'st>);
2958impl std::fmt::Display for GetOptionResponse<'_> {
2959 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2960 write!(f, "{}", self.0)
2961 }
2962}
2963impl<'st> GetOptionResponse<'st> {
2964 pub fn parse(
2965 st: &'st Storage,
2966 src: &str,
2967 ) -> Result<GetOptionResponse<'st>, ParseError> {
2968 <GetOptionResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2969 }
2970}
2971impl<'st> SmtlibParse<'st> for GetOptionResponse<'st> {
2972 type Output = GetOptionResponse<'st>;
2973 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
2974 AttributeValue::is_start_of(offset, p)
2975 }
2976 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
2977 let m0 = <AttributeValue<'st> as SmtlibParse<'st>>::parse(p)?;
2978 Ok(Self(m0))
2979 }
2980}
2981#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2983#[cfg_attr(feature = "serde", derive(serde::Serialize))]
2984pub struct GetProofResponse<'st>(pub SExpr<'st>);
2985impl std::fmt::Display for GetProofResponse<'_> {
2986 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
2987 write!(f, "{}", self.0)
2988 }
2989}
2990impl<'st> GetProofResponse<'st> {
2991 pub fn parse(
2992 st: &'st Storage,
2993 src: &str,
2994 ) -> Result<GetProofResponse<'st>, ParseError> {
2995 <GetProofResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
2996 }
2997}
2998impl<'st> SmtlibParse<'st> for GetProofResponse<'st> {
2999 type Output = GetProofResponse<'st>;
3000 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3001 SExpr::is_start_of(offset, p)
3002 }
3003 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3004 let m0 = <SExpr<'st> as SmtlibParse<'st>>::parse(p)?;
3005 Ok(Self(m0))
3006 }
3007}
3008#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3010#[cfg_attr(feature = "serde", derive(serde::Serialize))]
3011pub struct GetUnsatAssumptionsResponse<'st>(pub &'st [Symbol<'st>]);
3012impl std::fmt::Display for GetUnsatAssumptionsResponse<'_> {
3013 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3014 write!(f, "({})", self.0.iter().format(" "))
3015 }
3016}
3017impl<'st> GetUnsatAssumptionsResponse<'st> {
3018 pub fn parse(
3019 st: &'st Storage,
3020 src: &str,
3021 ) -> Result<GetUnsatAssumptionsResponse<'st>, ParseError> {
3022 <GetUnsatAssumptionsResponse<
3023 'st,
3024 > as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
3025 }
3026}
3027impl<'st> SmtlibParse<'st> for GetUnsatAssumptionsResponse<'st> {
3028 type Output = GetUnsatAssumptionsResponse<'st>;
3029 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3030 p.nth(offset) == Token::LParen
3031 }
3032 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3033 p.expect(Token::LParen)?;
3034 let m0 = p.any::<Symbol<'st>>()?;
3035 p.expect(Token::RParen)?;
3036 Ok(Self(m0))
3037 }
3038}
3039#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3041#[cfg_attr(feature = "serde", derive(serde::Serialize))]
3042pub struct GetUnsatCoreResponse<'st>(pub &'st [Symbol<'st>]);
3043impl std::fmt::Display for GetUnsatCoreResponse<'_> {
3044 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3045 write!(f, "({})", self.0.iter().format(" "))
3046 }
3047}
3048impl<'st> GetUnsatCoreResponse<'st> {
3049 pub fn parse(
3050 st: &'st Storage,
3051 src: &str,
3052 ) -> Result<GetUnsatCoreResponse<'st>, ParseError> {
3053 <GetUnsatCoreResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
3054 }
3055}
3056impl<'st> SmtlibParse<'st> for GetUnsatCoreResponse<'st> {
3057 type Output = GetUnsatCoreResponse<'st>;
3058 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3059 p.nth(offset) == Token::LParen
3060 }
3061 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3062 p.expect(Token::LParen)?;
3063 let m0 = p.any::<Symbol<'st>>()?;
3064 p.expect(Token::RParen)?;
3065 Ok(Self(m0))
3066 }
3067}
3068#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3070#[cfg_attr(feature = "serde", derive(serde::Serialize))]
3071pub struct GetValueResponse<'st>(pub &'st [ValuationPair<'st>]);
3072impl std::fmt::Display for GetValueResponse<'_> {
3073 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3074 write!(f, "({})", self.0.iter().format(" "))
3075 }
3076}
3077impl<'st> GetValueResponse<'st> {
3078 pub fn parse(
3079 st: &'st Storage,
3080 src: &str,
3081 ) -> Result<GetValueResponse<'st>, ParseError> {
3082 <GetValueResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
3083 }
3084}
3085impl<'st> SmtlibParse<'st> for GetValueResponse<'st> {
3086 type Output = GetValueResponse<'st>;
3087 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3088 p.nth(offset) == Token::LParen
3089 }
3090 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3091 p.expect(Token::LParen)?;
3092 let m0 = p.non_zero::<ValuationPair<'st>>()?;
3093 p.expect(Token::RParen)?;
3094 Ok(Self(m0))
3095 }
3096}
3097#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3099#[cfg_attr(feature = "serde", derive(serde::Serialize))]
3100pub struct SimplifyResponse<'st>(pub &'st Term<'st>);
3101impl std::fmt::Display for SimplifyResponse<'_> {
3102 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3103 write!(f, "{}", self.0)
3104 }
3105}
3106impl<'st> SimplifyResponse<'st> {
3107 pub fn parse(
3108 st: &'st Storage,
3109 src: &str,
3110 ) -> Result<SimplifyResponse<'st>, ParseError> {
3111 <SimplifyResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
3112 }
3113}
3114impl<'st> SmtlibParse<'st> for SimplifyResponse<'st> {
3115 type Output = SimplifyResponse<'st>;
3116 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3117 Term::is_start_of(offset, p)
3118 }
3119 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3120 let m0 = <Term<'st> as SmtlibParse<'st>>::parse(p)?;
3121 Ok(Self(m0))
3122 }
3123}
3124#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3125#[cfg_attr(feature = "serde", derive(serde::Serialize))]
3126pub enum SpecificSuccessResponse<'st> {
3127 GetUnsatAssumptionsResponse(GetUnsatAssumptionsResponse<'st>),
3129 CheckSatResponse(CheckSatResponse),
3131 EchoResponse(EchoResponse<'st>),
3133 GetAssertionsResponse(GetAssertionsResponse<'st>),
3135 GetAssignmentResponse(GetAssignmentResponse<'st>),
3137 GetInfoResponse(GetInfoResponse<'st>),
3139 GetModelResponse(GetModelResponse<'st>),
3141 GetOptionResponse(GetOptionResponse<'st>),
3143 GetProofResponse(GetProofResponse<'st>),
3145 GetUnsatCoreResponse(GetUnsatCoreResponse<'st>),
3147 GetValueResponse(GetValueResponse<'st>),
3149 SimplifyResponse(SimplifyResponse<'st>),
3151}
3152impl std::fmt::Display for SpecificSuccessResponse<'_> {
3153 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3154 match self {
3155 Self::GetUnsatAssumptionsResponse(m0) => write!(f, "{}", m0),
3156 Self::CheckSatResponse(m0) => write!(f, "{}", m0),
3157 Self::EchoResponse(m0) => write!(f, "{}", m0),
3158 Self::GetAssertionsResponse(m0) => write!(f, "{}", m0),
3159 Self::GetAssignmentResponse(m0) => write!(f, "{}", m0),
3160 Self::GetInfoResponse(m0) => write!(f, "{}", m0),
3161 Self::GetModelResponse(m0) => write!(f, "{}", m0),
3162 Self::GetOptionResponse(m0) => write!(f, "{}", m0),
3163 Self::GetProofResponse(m0) => write!(f, "{}", m0),
3164 Self::GetUnsatCoreResponse(m0) => write!(f, "{}", m0),
3165 Self::GetValueResponse(m0) => write!(f, "{}", m0),
3166 Self::SimplifyResponse(m0) => write!(f, "{}", m0),
3167 }
3168 }
3169}
3170impl<'st> SpecificSuccessResponse<'st> {
3171 pub fn parse(
3172 st: &'st Storage,
3173 src: &str,
3174 ) -> Result<SpecificSuccessResponse<'st>, ParseError> {
3175 <SpecificSuccessResponse<
3176 'st,
3177 > as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
3178 }
3179}
3180impl<'st> SmtlibParse<'st> for SpecificSuccessResponse<'st> {
3181 type Output = SpecificSuccessResponse<'st>;
3182 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3183 (SimplifyResponse::is_start_of(offset, p))
3184 || (GetValueResponse::is_start_of(offset, p))
3185 || (GetUnsatCoreResponse::is_start_of(offset, p))
3186 || (GetProofResponse::is_start_of(offset, p))
3187 || (GetOptionResponse::is_start_of(offset, p))
3188 || (GetModelResponse::is_start_of(offset, p))
3189 || (GetInfoResponse::is_start_of(offset, p))
3190 || (GetAssignmentResponse::is_start_of(offset, p))
3191 || (GetAssertionsResponse::is_start_of(offset, p))
3192 || (EchoResponse::is_start_of(offset, p))
3193 || (CheckSatResponse::is_start_of(offset, p))
3194 || (GetUnsatAssumptionsResponse::is_start_of(offset, p))
3195 }
3196 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3197 let offset = 0;
3198 if SimplifyResponse::is_start_of(offset, p) {
3199 let m0 = <SimplifyResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3200 #[allow(clippy::useless_conversion)]
3201 return Ok(Self::SimplifyResponse(m0.into()));
3202 }
3203 if GetValueResponse::is_start_of(offset, p) {
3204 let m0 = <GetValueResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3205 #[allow(clippy::useless_conversion)]
3206 return Ok(Self::GetValueResponse(m0.into()));
3207 }
3208 if GetUnsatCoreResponse::is_start_of(offset, p) {
3209 let m0 = <GetUnsatCoreResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3210 #[allow(clippy::useless_conversion)]
3211 return Ok(Self::GetUnsatCoreResponse(m0.into()));
3212 }
3213 if GetProofResponse::is_start_of(offset, p) {
3214 let m0 = <GetProofResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3215 #[allow(clippy::useless_conversion)]
3216 return Ok(Self::GetProofResponse(m0.into()));
3217 }
3218 if GetOptionResponse::is_start_of(offset, p) {
3219 let m0 = <GetOptionResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3220 #[allow(clippy::useless_conversion)]
3221 return Ok(Self::GetOptionResponse(m0.into()));
3222 }
3223 if GetModelResponse::is_start_of(offset, p) {
3224 let m0 = <GetModelResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3225 #[allow(clippy::useless_conversion)]
3226 return Ok(Self::GetModelResponse(m0.into()));
3227 }
3228 if GetInfoResponse::is_start_of(offset, p) {
3229 let m0 = <GetInfoResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3230 #[allow(clippy::useless_conversion)]
3231 return Ok(Self::GetInfoResponse(m0.into()));
3232 }
3233 if GetAssignmentResponse::is_start_of(offset, p) {
3234 let m0 = <GetAssignmentResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3235 #[allow(clippy::useless_conversion)]
3236 return Ok(Self::GetAssignmentResponse(m0.into()));
3237 }
3238 if GetAssertionsResponse::is_start_of(offset, p) {
3239 let m0 = <GetAssertionsResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3240 #[allow(clippy::useless_conversion)]
3241 return Ok(Self::GetAssertionsResponse(m0.into()));
3242 }
3243 if EchoResponse::is_start_of(offset, p) {
3244 let m0 = <EchoResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3245 #[allow(clippy::useless_conversion)]
3246 return Ok(Self::EchoResponse(m0.into()));
3247 }
3248 if CheckSatResponse::is_start_of(offset, p) {
3249 let m0 = <CheckSatResponse as SmtlibParse<'st>>::parse(p)?;
3250 #[allow(clippy::useless_conversion)]
3251 return Ok(Self::CheckSatResponse(m0.into()));
3252 }
3253 if GetUnsatAssumptionsResponse::is_start_of(offset, p) {
3254 let m0 = <GetUnsatAssumptionsResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3255 #[allow(clippy::useless_conversion)]
3256 return Ok(Self::GetUnsatAssumptionsResponse(m0.into()));
3257 }
3258 Err(p.stuck("SpecificSuccessResponse"))
3259 }
3260}
3261#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3262#[cfg_attr(feature = "serde", derive(serde::Serialize))]
3263pub enum GeneralResponse<'st> {
3264 Success,
3266 SpecificSuccessResponse(SpecificSuccessResponse<'st>),
3268 Unsupported,
3270 Error(&'st str),
3272}
3273impl std::fmt::Display for GeneralResponse<'_> {
3274 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3275 match self {
3276 Self::Success => write!(f, "success"),
3277 Self::SpecificSuccessResponse(m0) => write!(f, "{}", m0),
3278 Self::Unsupported => write!(f, "unsupported"),
3279 Self::Error(m0) => write!(f, "(error {})", m0),
3280 }
3281 }
3282}
3283impl<'st> GeneralResponse<'st> {
3284 pub fn parse(
3285 st: &'st Storage,
3286 src: &str,
3287 ) -> Result<GeneralResponse<'st>, ParseError> {
3288 <GeneralResponse<'st> as SmtlibParse<'st>>::parse(&mut Parser::new(st, src))
3289 }
3290}
3291impl<'st> SmtlibParse<'st> for GeneralResponse<'st> {
3292 type Output = GeneralResponse<'st>;
3293 fn is_start_of(offset: usize, p: &mut Parser<'st, '_>) -> bool {
3294 (p.nth(offset) == Token::LParen
3295 && p.nth_matches(offset + 1, Token::Symbol, "error"))
3296 || (p.nth_matches(offset, Token::Symbol, "unsupported"))
3297 || (p.nth_matches(offset, Token::Symbol, "success"))
3298 || (SpecificSuccessResponse::is_start_of(offset, p))
3299 }
3300 fn parse(p: &mut Parser<'st, '_>) -> Result<Self::Output, ParseError> {
3301 let offset = 0;
3302 if p.nth(offset) == Token::LParen
3303 && p.nth_matches(offset + 1, Token::Symbol, "error")
3304 {
3305 p.expect(Token::LParen)?;
3306 p.expect_matches(Token::Symbol, "error")?;
3307 let m0 = <String as SmtlibParse<'st>>::parse(p)?;
3308 p.expect(Token::RParen)?;
3309 #[allow(clippy::useless_conversion)] return Ok(Self::Error(m0.into()));
3310 }
3311 if p.nth_matches(offset, Token::Symbol, "unsupported") {
3312 p.expect_matches(Token::Symbol, "unsupported")?;
3313 #[allow(clippy::useless_conversion)] return Ok(Self::Unsupported);
3314 }
3315 if p.nth_matches(offset, Token::Symbol, "success") {
3316 p.expect_matches(Token::Symbol, "success")?;
3317 #[allow(clippy::useless_conversion)] return Ok(Self::Success);
3318 }
3319 if SpecificSuccessResponse::is_start_of(offset, p) {
3320 let m0 = <SpecificSuccessResponse<'st> as SmtlibParse<'st>>::parse(p)?;
3321 #[allow(clippy::useless_conversion)]
3322 return Ok(Self::SpecificSuccessResponse(m0.into()));
3323 }
3324 Err(p.stuck("GeneralResponse"))
3325 }
3326}