1
use std::fmt;
2

            
3
use itertools::Itertools;
4

            
5
use crate::ActDecl;
6
use crate::ActFrm;
7
use crate::ActFrmBinaryOp;
8
use crate::Action;
9
use crate::Assignment;
10
use crate::Bound;
11
use crate::Comm;
12
use crate::ComplexSort;
13
use crate::ConstructorDecl;
14
use crate::DataExpr;
15
use crate::DataExprBinaryOp;
16
use crate::DataExprUnaryOp;
17
use crate::DataExprUpdate;
18
use crate::EqnDecl;
19
use crate::EqnSpec;
20
use crate::FixedPointOperator;
21
use crate::IdDecl;
22
use crate::ModalityOperator;
23
use crate::MultiAction;
24
use crate::MultiActionLabel;
25
use crate::PbesEquation;
26
use crate::PbesExpr;
27
use crate::PbesExprBinaryOp;
28
use crate::ProcDecl;
29
use crate::ProcExprBinaryOp;
30
use crate::ProcessExpr;
31
use crate::PropVarDecl;
32
use crate::PropVarInst;
33
use crate::Quantifier;
34
use crate::RegFrm;
35
use crate::Rename;
36
use crate::Sort;
37
use crate::SortDecl;
38
use crate::SortExpression;
39
use crate::Span;
40
use crate::StateFrm;
41
use crate::StateFrmOp;
42
use crate::StateFrmUnaryOp;
43
use crate::StateVarAssignment;
44
use crate::StateVarDecl;
45
use crate::UntypedDataSpecification;
46
use crate::UntypedPbes;
47
use crate::UntypedProcessSpecification;
48
use crate::UntypedStateFrmSpec;
49

            
50
/// Prints location information for a span in the source.
51
pub fn print_location(input: &str, span: &Span) {
52
    input.lines().enumerate().fold(span.start, |current, (number, line)| {
53
        if current < line.len() {
54
            println!("ln {number}, col {}", span.start - current);
55
        }
56
        current - line.len()
57
    });
58
}
59

            
60
// Display implementations
61
impl fmt::Display for Sort {
62
29676
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63
29676
        write!(f, "{self:?}")
64
29676
    }
65
}
66

            
67
impl fmt::Display for ComplexSort {
68
7314
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69
7314
        write!(f, "{self:?}")
70
7314
    }
71
}
72

            
73
impl fmt::Display for Assignment {
74
3498
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
75
3498
        write!(f, "{} = {}", self.identifier, self.expr)
76
3498
    }
77
}
78

            
79
impl fmt::Display for UntypedProcessSpecification {
80
1026
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81
1026
        writeln!(f, "{}", self.data_specification)?;
82

            
83
1026
        if !self.action_declarations.is_empty() {
84
942
            writeln!(f, "act")?;
85
11958
            for act_decl in &self.action_declarations {
86
11958
                writeln!(f, "   {act_decl};")?;
87
            }
88

            
89
942
            writeln!(f)?;
90
84
        }
91

            
92
1026
        if !self.process_declarations.is_empty() {
93
942
            writeln!(f, "proc")?;
94
5436
            for proc_decl in &self.process_declarations {
95
5436
                writeln!(f, "   {proc_decl};")?;
96
            }
97

            
98
942
            writeln!(f)?;
99
84
        }
100

            
101
1026
        if !self.global_variables.is_empty() {
102
6
            writeln!(f, "glob")?;
103
6
            for var_decl in &self.global_variables {
104
6
                writeln!(f, "   {var_decl};")?;
105
            }
106

            
107
6
            writeln!(f)?;
108
1020
        }
109

            
110
1026
        if let Some(init) = &self.init {
111
1014
            writeln!(f, "init {init};")?;
112
12
        }
113
1026
        Ok(())
114
1026
    }
115
}
116

            
117
impl fmt::Display for UntypedDataSpecification {
118
2484
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119
2484
        if !self.sort_declarations.is_empty() {
120
1182
            writeln!(f, "sort")?;
121
5154
            for decl in &self.sort_declarations {
122
5154
                writeln!(f, "   {decl};")?;
123
            }
124

            
125
1182
            writeln!(f)?;
126
1302
        }
127

            
128
2484
        if !self.constructor_declarations.is_empty() {
129
54
            writeln!(f, "cons")?;
130
102
            for decl in &self.constructor_declarations {
131
102
                writeln!(f, "   {decl};")?;
132
            }
133

            
134
54
            writeln!(f)?;
135
2430
        }
136

            
137
2484
        if !self.map_declarations.is_empty() {
138
1338
            writeln!(f, "map")?;
139
42246
            for decl in &self.map_declarations {
140
42246
                writeln!(f, "   {decl};")?;
141
            }
142

            
143
1338
            writeln!(f)?;
144
1146
        }
145

            
146
3792
        for decl in &self.equation_declarations {
147
3792
            writeln!(f, "{decl}")?;
148
        }
149
2484
        Ok(())
150
2484
    }
151
}
152

            
153
impl fmt::Display for UntypedPbes {
154
18
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
155
18
        writeln!(f, "{}", self.data_specification)?;
156
18
        writeln!(f)?;
157
18
        if !self.global_variables.is_empty() {
158
            writeln!(f, "glob")?;
159
            for var_decl in &self.global_variables {
160
                writeln!(f, "   {var_decl};")?;
161
            }
162

            
163
            writeln!(f)?;
164
18
        }
165
18
        writeln!(f)?;
166

            
167
18
        if !self.equations.is_empty() {
168
18
            writeln!(f, "pbes")?;
169
30
            for equation in &self.equations {
170
30
                writeln!(f, "   {equation};")?;
171
            }
172
        }
173

            
174
18
        writeln!(f, "init {};", self.init)
175
18
    }
176
}
177

            
178
impl fmt::Display for PropVarInst {
179
42
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
180
42
        if self.arguments.is_empty() {
181
24
            write!(f, "{}", self.identifier)
182
        } else {
183
18
            write!(f, "{}({})", self.identifier, self.arguments.iter().format(", "))
184
        }
185
42
    }
186
}
187

            
188
impl fmt::Display for PbesEquation {
189
30
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
190
30
        write!(f, "{} {} = {}", self.operator, self.variable, self.formula)
191
30
    }
192
}
193

            
194
impl fmt::Display for PropVarDecl {
195
30
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
196
30
        if self.parameters.is_empty() {
197
18
            write!(f, "{}", self.identifier)
198
        } else {
199
12
            write!(f, "{}({})", self.identifier, self.parameters.iter().format(", "))
200
        }
201
30
    }
202
}
203

            
204
impl fmt::Display for PbesExpr {
205
60
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
206
60
        match self {
207
6
            PbesExpr::True => write!(f, "true"),
208
            PbesExpr::False => write!(f, "false"),
209
24
            PbesExpr::PropVarInst(instance) => write!(f, "{instance}"),
210
6
            PbesExpr::Negation(expr) => write!(f, "(! {expr})"),
211
12
            PbesExpr::Binary { op, lhs, rhs } => write!(f, "({lhs} {op} {rhs})"),
212
            PbesExpr::Quantifier {
213
                quantifier,
214
                variables,
215
                body,
216
            } => write!(f, "({} {} . {})", quantifier, variables.iter().format(", "), body),
217
12
            PbesExpr::DataValExpr(data_expr) => write!(f, "val({data_expr})"),
218
        }
219
60
    }
220
}
221

            
222
impl fmt::Display for PbesExprBinaryOp {
223
12
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
224
12
        match self {
225
12
            PbesExprBinaryOp::Conjunction => write!(f, "&&"),
226
            PbesExprBinaryOp::Disjunction => write!(f, "||"),
227
            PbesExprBinaryOp::Implies => write!(f, "=>"),
228
        }
229
12
    }
230
}
231

            
232
impl fmt::Display for EqnSpec {
233
3792
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
234
3792
        writeln!(f, "var")?;
235
18546
        for decl in &self.variables {
236
18546
            writeln!(f, "   {decl};")?;
237
        }
238

            
239
3792
        writeln!(f, "eqn")?;
240
68760
        for decl in &self.equations {
241
68760
            writeln!(f, "   {decl};")?;
242
        }
243
3792
        Ok(())
244
3792
    }
245
}
246

            
247
impl fmt::Display for SortDecl {
248
5154
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
249
5154
        write!(f, "{}", self.identifier)?;
250

            
251
5154
        if let Some(expr) = &self.expr {
252
5100
            write!(f, " = {expr}")?;
253
54
        }
254

            
255
5154
        Ok(())
256
5154
    }
257
}
258

            
259
impl fmt::Display for ActDecl {
260
11958
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
261
11958
        if self.args.is_empty() {
262
1518
            write!(f, "{}", self.identifier)
263
        } else {
264
10440
            write!(f, "{}({})", self.identifier, self.args.iter().format(", "))
265
        }
266
11958
    }
267
}
268

            
269
impl fmt::Display for EqnDecl {
270
68760
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
271
68760
        match &self.condition {
272
4680
            Some(condition) => write!(f, "{} -> {} = {}", condition, self.lhs, self.rhs),
273
64080
            None => write!(f, "{} = {}", self.lhs, self.rhs),
274
        }
275
68760
    }
276
}
277

            
278
impl fmt::Display for DataExprUnaryOp {
279
3444
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
280
3444
        match self {
281
2682
            DataExprUnaryOp::Negation => write!(f, "!"),
282
354
            DataExprUnaryOp::Minus => write!(f, "-"),
283
408
            DataExprUnaryOp::Size => write!(f, "#"),
284
        }
285
3444
    }
286
}
287

            
288
impl fmt::Display for DataExpr {
289
1190556
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
290
1190556
        match self {
291
3414
            DataExpr::EmptyList => write!(f, "[]"),
292
498
            DataExpr::EmptyBag => write!(f, "{{:}}"),
293
1248
            DataExpr::EmptySet => write!(f, "{{}}"),
294
2850
            DataExpr::List(expressions) => write!(f, "[{}]", expressions.iter().format(", ")),
295
276
            DataExpr::Bag(expressions) => write!(
296
276
                f,
297
                "{{ {} }}",
298
276
                expressions
299
276
                    .iter()
300
300
                    .format_with(", ", |e, f| f(&format_args!("{}: {}", e.expr, e.multiplicity)))
301
            ),
302
2088
            DataExpr::Set(expressions) => write!(f, "{{ {} }}", expressions.iter().format(", ")),
303
822282
            DataExpr::Id(identifier) => write!(f, "{identifier}"),
304
66816
            DataExpr::Binary { op, lhs, rhs } => write!(f, "({lhs} {op} {rhs})"),
305
3444
            DataExpr::Unary { op, expr } => write!(f, "({op} {expr})"),
306
7836
            DataExpr::Bool(value) => write!(f, "{value}"),
307
390
            DataExpr::Quantifier { op, variables, body } => {
308
390
                write!(f, "({} {} . {})", op, variables.iter().format(", "), body)
309
            }
310
174
            DataExpr::Lambda { variables, body } => write!(f, "(lambda {} . {})", variables.iter().format(", "), body),
311
241530
            DataExpr::Application { function, arguments } => {
312
241530
                if arguments.is_empty() {
313
                    write!(f, "{function}")
314
                } else {
315
241530
                    write!(f, "{}({})", function, arguments.iter().format(", "))
316
                }
317
            }
318
35784
            DataExpr::Number(value) => write!(f, "{value}"),
319
1716
            DataExpr::FunctionUpdate { expr, update } => write!(f, "{expr}[{update}]"),
320
66
            DataExpr::SetBagComp { variable, predicate } => write!(f, "{{ {variable} | {predicate} }}"),
321
144
            DataExpr::Whr { expr, assignments } => write!(f, "{} whr {} end", expr, assignments.iter().format(", ")),
322
        }
323
1190556
    }
324
}
325

            
326
impl fmt::Display for IdDecl {
327
82170
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
328
82170
        write!(f, "{}: {}", self.identifier, self.sort)
329
82170
    }
330
}
331

            
332
impl fmt::Display for DataExprUpdate {
333
1716
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
334
1716
        write!(f, "{} -> {}", self.expr, self.update)
335
1716
    }
336
}
337

            
338
impl fmt::Display for SortExpression {
339
225714
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
340
225714
        match self {
341
30048
            SortExpression::Product { lhs, rhs } => write!(f, "({lhs} # {rhs})"),
342
22152
            SortExpression::Function { domain, range } => write!(f, "({domain} -> {range})"),
343
132396
            SortExpression::Reference(ident) => write!(f, "{ident}"),
344
29676
            SortExpression::Simple(sort) => write!(f, "{sort}"),
345
7314
            SortExpression::Complex(complex, inner) => write!(f, "{complex}({inner})"),
346
4128
            SortExpression::Struct { inner } => {
347
4128
                write!(f, "struct ")?;
348
4128
                write!(f, "{}", inner.iter().format(" | "))
349
            }
350
        }
351
225714
    }
352
}
353

            
354
impl fmt::Display for UntypedStateFrmSpec {
355
870
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
356
870
        writeln!(f, "{}", self.data_specification)?;
357

            
358
870
        writeln!(f, "{}", self.formula)
359
870
    }
360
}
361

            
362
impl fmt::Display for StateFrmUnaryOp {
363
90
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
364
90
        match self {
365
            StateFrmUnaryOp::Minus => write!(f, "-"),
366
90
            StateFrmUnaryOp::Negation => write!(f, "!"),
367
        }
368
90
    }
369
}
370

            
371
impl fmt::Display for FixedPointOperator {
372
1212
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
373
1212
        match self {
374
654
            FixedPointOperator::Greatest => write!(f, "nu"),
375
558
            FixedPointOperator::Least => write!(f, "mu"),
376
        }
377
1212
    }
378
}
379

            
380
impl fmt::Display for StateFrm {
381
38298
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
382
38298
        match self {
383
1842
            StateFrm::True => write!(f, "true"),
384
1830
            StateFrm::False => write!(f, "false"),
385
            StateFrm::DataValExpr(expr) => write!(f, "val({expr})"),
386
6348
            StateFrm::Id(identifier, args) => {
387
6348
                if args.is_empty() {
388
594
                    write!(f, "{identifier}")
389
                } else {
390
5754
                    write!(f, "{}({})", identifier, args.iter().format(", "))
391
                }
392
            }
393
90
            StateFrm::Unary { op, expr } => write!(f, "({op} {expr})"),
394
            StateFrm::Modality {
395
17838
                operator,
396
17838
                formula,
397
17838
                expr,
398
17838
            } => match operator {
399
6252
                ModalityOperator::Box => write!(f, "[{formula}]{expr}"),
400
11586
                ModalityOperator::Diamond => write!(f, "<{formula}>{expr}"),
401
            },
402
            StateFrm::Quantifier {
403
1590
                quantifier,
404
1590
                variables,
405
1590
                body,
406
            } => {
407
1590
                write!(f, "({} {} . {})", quantifier, variables.iter().format(", "), body)
408
            }
409
            StateFrm::Bound {
410
6
                bound: quantifier,
411
6
                variables,
412
6
                body,
413
            } => {
414
6
                write!(f, "({} {} . {})", quantifier, variables.iter().format(", "), body)
415
            }
416
7584
            StateFrm::Binary { op, lhs, rhs } => {
417
7584
                write!(f, "({lhs} {op} {rhs})")
418
            }
419
            StateFrm::FixedPoint {
420
1158
                operator,
421
1158
                variable,
422
1158
                body,
423
            } => {
424
1158
                write!(f, "({operator} {variable} . {body})")
425
            }
426
            StateFrm::Delay(expr) => write!(f, "delay@({expr})"),
427
            StateFrm::Yaled(expr) => write!(f, "yaled@({expr})"),
428
12
            StateFrm::DataValExprLeftMult(value, expr) => write!(f, "({value} * {expr})"),
429
            StateFrm::DataValExprRightMult(expr, value) => write!(f, "({expr} * {value})"),
430
        }
431
38298
    }
432
}
433

            
434
impl fmt::Display for StateVarDecl {
435
1182
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
436
1182
        if self.arguments.is_empty() {
437
594
            write!(f, "{}", self.identifier)
438
        } else {
439
588
            write!(f, "{}({})", self.identifier, self.arguments.iter().format(","))
440
        }
441
1182
    }
442
}
443

            
444
impl fmt::Display for StateVarAssignment {
445
804
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
446
804
        write!(f, "{} : {} = {}", self.identifier, self.sort, self.expr)
447
804
    }
448
}
449

            
450
impl fmt::Display for StateFrmOp {
451
7584
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
452
7584
        match self {
453
1542
            StateFrmOp::Implies => write!(f, "=>"),
454
4866
            StateFrmOp::Conjunction => write!(f, "&&"),
455
1170
            StateFrmOp::Disjunction => write!(f, "||"),
456
6
            StateFrmOp::Addition => write!(f, "+"),
457
        }
458
7584
    }
459
}
460

            
461
impl fmt::Display for RegFrm {
462
26088
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
463
26088
        match self {
464
18522
            RegFrm::Action(action) => write!(f, "{action}"),
465
6876
            RegFrm::Iteration(body) => write!(f, "({body})*"),
466
6
            RegFrm::Plus(body) => write!(f, "({body})+"),
467
30
            RegFrm::Choice { lhs, rhs } => write!(f, "({lhs} + {rhs})"),
468
654
            RegFrm::Sequence { lhs, rhs } => write!(f, "({lhs} . {rhs})"),
469
        }
470
26088
    }
471
}
472

            
473
impl fmt::Display for DataExprBinaryOp {
474
66816
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
475
66816
        match self {
476
5682
            DataExprBinaryOp::At => write!(f, "."),
477
282
            DataExprBinaryOp::Concat => write!(f, "++"),
478
4878
            DataExprBinaryOp::Cons => write!(f, "|>"),
479
12630
            DataExprBinaryOp::Equal => write!(f, "=="),
480
3552
            DataExprBinaryOp::NotEqual => write!(f, "!="),
481
2658
            DataExprBinaryOp::LessThan => write!(f, "<"),
482
2796
            DataExprBinaryOp::LessEqual => write!(f, "<="),
483
1476
            DataExprBinaryOp::GreaterThan => write!(f, ">"),
484
954
            DataExprBinaryOp::GreaterEqual => write!(f, ">="),
485
9270
            DataExprBinaryOp::Conj => write!(f, "&&"),
486
2910
            DataExprBinaryOp::Disj => write!(f, "||"),
487
9126
            DataExprBinaryOp::Add => write!(f, "+"),
488
4128
            DataExprBinaryOp::Subtract => write!(f, "-"),
489
504
            DataExprBinaryOp::Div => write!(f, "/"),
490
366
            DataExprBinaryOp::Implies => write!(f, "=>"),
491
2934
            DataExprBinaryOp::In => write!(f, "in"),
492
126
            DataExprBinaryOp::IntDiv => write!(f, "div"),
493
570
            DataExprBinaryOp::Mod => write!(f, "mod"),
494
1890
            DataExprBinaryOp::Multiply => write!(f, "*"),
495
84
            DataExprBinaryOp::Snoc => write!(f, "<|"),
496
        }
497
66816
    }
498
}
499

            
500
impl fmt::Display for ActFrm {
501
21780
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
502
21780
        match self {
503
6
            ActFrm::False => write!(f, "false"),
504
738
            ActFrm::True => write!(f, "true"),
505
18414
            ActFrm::MultAct(action) => write!(f, "{action}"),
506
762
            ActFrm::Binary { op, lhs, rhs } => {
507
762
                write!(f, "({lhs}) {op} ({rhs})")
508
            }
509
126
            ActFrm::DataExprVal(expr) => write!(f, "val({expr})"),
510
            ActFrm::Quantifier {
511
804
                quantifier,
512
804
                variables,
513
804
                body,
514
804
            } => write!(f, "({} {} . {})", quantifier, variables.iter().format(", "), body),
515
930
            ActFrm::Negation(expr) => write!(f, "(!{expr})"),
516
        }
517
21780
    }
518
}
519

            
520
impl fmt::Display for ActFrmBinaryOp {
521
762
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
522
762
        match self {
523
12
            ActFrmBinaryOp::Implies => write!(f, "=>"),
524
300
            ActFrmBinaryOp::Intersect => write!(f, "&&"),
525
450
            ActFrmBinaryOp::Union => write!(f, "||"),
526
        }
527
762
    }
528
}
529

            
530
impl fmt::Display for Bound {
531
6
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
532
6
        match self {
533
            Bound::Inf => write!(f, "inf"),
534
            Bound::Sum => write!(f, "sum"),
535
6
            Bound::Sup => write!(f, "sup"),
536
        }
537
6
    }
538
}
539

            
540
impl fmt::Display for MultiAction {
541
18414
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
542
18414
        if self.actions.is_empty() {
543
6678
            write!(f, "tau")
544
        } else {
545
11736
            write!(f, "{}", self.actions.iter().format("|"))
546
        }
547
18414
    }
548
}
549

            
550
impl fmt::Display for Action {
551
11892
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
552
11892
        if self.args.is_empty() {
553
8610
            write!(f, "{}", self.id)
554
        } else {
555
3282
            write!(f, "{}({})", self.id, self.args.iter().format(", "))
556
        }
557
11892
    }
558
}
559

            
560
impl fmt::Display for Quantifier {
561
2784
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
562
2784
        match self {
563
1554
            Quantifier::Exists => write!(f, "exists"),
564
1230
            Quantifier::Forall => write!(f, "forall"),
565
        }
566
2784
    }
567
}
568

            
569
impl fmt::Display for ConstructorDecl {
570
11520
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
571
11520
        if self.args.is_empty() {
572
8196
            write!(f, "{}", self.name)
573
        } else {
574
3324
            write!(f, "{}(", self.name)?;
575
7146
            for (i, (name, sort)) in self.args.iter().enumerate() {
576
7146
                if i > 0 {
577
3822
                    write!(f, ", ")?;
578
3324
                }
579
7146
                match name {
580
2748
                    Some(name) => write!(f, "{name} : {sort}")?,
581
4398
                    None => write!(f, "{sort}")?,
582
                }
583
            }
584
3324
            write!(f, ")")?;
585

            
586
3324
            if let Some(projection) = &self.projection {
587
300
                write!(f, "?{projection}")?;
588
3024
            }
589

            
590
3324
            Ok(())
591
        }
592
11520
    }
593
}
594

            
595
impl fmt::Display for ProcDecl {
596
5436
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
597
5436
        if self.params.is_empty() {
598
828
            write!(f, "{} = {};", self.identifier, self.body)
599
        } else {
600
4608
            write!(
601
4608
                f,
602
                "{}({}) = {};",
603
                self.identifier,
604
4608
                self.params.iter().format(", "),
605
                self.body
606
            )
607
        }
608
5436
    }
609
}
610

            
611
impl fmt::Display for ProcExprBinaryOp {
612
27954
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
613
27954
        match self {
614
16038
            ProcExprBinaryOp::Sequence => write!(f, "."),
615
6252
            ProcExprBinaryOp::Choice => write!(f, "+"),
616
3222
            ProcExprBinaryOp::Parallel => write!(f, "||"),
617
            ProcExprBinaryOp::LeftMerge => write!(f, "_||"),
618
2442
            ProcExprBinaryOp::CommMerge => write!(f, "|"),
619
        }
620
27954
    }
621
}
622

            
623
impl fmt::Display for ProcessExpr {
624
82308
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
625
82308
        match self {
626
3510
            ProcessExpr::Id(identifier, assignments) => {
627
3510
                if assignments.is_empty() {
628
1110
                    write!(f, "{identifier}")
629
                } else {
630
2400
                    write!(f, "{}({})", identifier, assignments.iter().format(", "))
631
                }
632
            }
633
33708
            ProcessExpr::Action(identifier, data_exprs) => {
634
33708
                if data_exprs.is_empty() {
635
3696
                    write!(f, "{identifier}")
636
                } else {
637
30012
                    write!(f, "{}({})", identifier, data_exprs.iter().format(", "))
638
                }
639
            }
640
552
            ProcessExpr::Delta => write!(f, "delta"),
641
36
            ProcessExpr::Tau => write!(f, "tau"),
642
5688
            ProcessExpr::Sum { variables, operand } => {
643
5688
                write!(f, "(sum {} . {})", variables.iter().format(", "), operand)
644
            }
645
            ProcessExpr::Dist {
646
156
                variables,
647
156
                expr,
648
156
                operand,
649
156
            } => write!(f, "(dist {} [{}] . {})", variables.iter().format(", "), expr, operand),
650
27954
            ProcessExpr::Binary { op, lhs, rhs } => write!(f, "({lhs} {op} {rhs})"),
651
276
            ProcessExpr::Hide { actions, operand } => {
652
276
                if !actions.is_empty() {
653
276
                    write!(f, "hide({{{}}}, {})", actions.iter().format(", "), operand)
654
                } else {
655
                    Ok(())
656
                }
657
            }
658
54
            ProcessExpr::Rename { renames, operand } => {
659
54
                if !renames.is_empty() {
660
54
                    write!(f, "rename({{{}}}, {})", renames.iter().format(", "), operand)
661
                } else {
662
                    Ok(())
663
                }
664
            }
665
594
            ProcessExpr::Allow { actions, operand } => {
666
594
                if !actions.is_empty() {
667
594
                    write!(f, "allow({{{}}}, {})", actions.iter().format(", "), operand)
668
                } else {
669
                    Ok(())
670
                }
671
            }
672
42
            ProcessExpr::Block { actions, operand } => {
673
42
                if !actions.is_empty() {
674
42
                    write!(f, "block({{{}}}, {})", actions.iter().format(", "), operand)
675
                } else {
676
                    Ok(())
677
                }
678
            }
679
606
            ProcessExpr::Comm { comm, operand } => {
680
606
                if !comm.is_empty() {
681
606
                    write!(f, "comm({{{}}}, {})", comm.iter().format(", "), operand)
682
                } else {
683
                    Ok(())
684
                }
685
            }
686
9048
            ProcessExpr::Condition { condition, then, else_ } => {
687
9048
                if let Some(else_) = else_ {
688
3402
                    write!(f, "({condition}) -> ({then}) <> ({else_})")
689
                } else {
690
5646
                    write!(f, "({condition}) -> ({then})")
691
                }
692
            }
693
84
            ProcessExpr::At { expr, operand } => write!(f, "({expr})@({operand})"),
694
        }
695
82308
    }
696
}
697

            
698
impl fmt::Display for Comm {
699
2766
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
700
2766
        write!(f, "{} -> {}", self.from, self.to)
701
2766
    }
702
}
703

            
704
impl fmt::Display for Rename {
705
168
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
706
168
        write!(f, "{} -> {}", self.from, self.to)
707
168
    }
708
}
709

            
710
impl fmt::Display for MultiActionLabel {
711
8388
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
712
8388
        if self.actions.is_empty() {
713
            write!(f, "tau")
714
        } else {
715
8388
            write!(f, "{}", self.actions.iter().format("|"))
716
        }
717
8388
    }
718
}