1
use std::hash::Hash;
2

            
3
use merc_utilities::TagIndex;
4

            
5
/// A unique type for declarations.
6
pub struct DefTag;
7

            
8
/// The index type for a label.
9
pub type DefId = TagIndex<usize, DefTag>;
10

            
11
/// A complete mCRL2 process specification.
12
#[derive(Debug, Default, Eq, PartialEq, Hash)]
13
pub struct UntypedProcessSpecification {
14
    pub data_specification: UntypedDataSpecification,
15
    pub global_variables: Vec<IdDecl>,
16
    pub action_declarations: Vec<ActDecl>,
17
    pub process_declarations: Vec<ProcDecl>,
18
    pub init: Option<ProcessExpr>,
19
}
20

            
21
/// An mCRL2 data specification.
22
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
23
pub struct UntypedDataSpecification {
24
    pub sort_declarations: Vec<SortDecl>,
25
    pub constructor_declarations: Vec<IdDecl>,
26
    pub map_declarations: Vec<IdDecl>,
27
    pub equation_declarations: Vec<EqnSpec>,
28
}
29

            
30
impl UntypedDataSpecification {
31
    /// Returns true if the data specification is empty.
32
    pub fn is_empty(&self) -> bool {
33
        self.sort_declarations.is_empty()
34
            && self.constructor_declarations.is_empty()
35
            && self.map_declarations.is_empty()
36
            && self.equation_declarations.is_empty()
37
    }
38

            
39
    /// Merges another data specification into the current one.
40
    pub fn merge(&mut self, other_spec: &UntypedDataSpecification) {
41
        self.sort_declarations.extend_from_slice(&other_spec.sort_declarations);
42
        self.constructor_declarations
43
            .extend_from_slice(&other_spec.constructor_declarations);
44
        self.map_declarations.extend_from_slice(&other_spec.map_declarations);
45
        self.equation_declarations
46
            .extend_from_slice(&other_spec.equation_declarations);
47
    }
48
}
49

            
50
/// An mCRL2 parameterised boolean equation system (PBES).
51
#[derive(Debug, Default, Eq, PartialEq, Hash)]
52
pub struct UntypedPbes {
53
    pub data_specification: UntypedDataSpecification,
54
    pub global_variables: Vec<IdDecl>,
55
    pub equations: Vec<PbesEquation>,
56
    pub init: PropVarInst,
57
}
58

            
59
/// An mCRL2 parameterised boolean equation system (PBES).
60
#[derive(Debug, Default, Eq, PartialEq, Hash)]
61
pub struct UntypedPres {
62
    pub data_specification: UntypedDataSpecification,
63
    pub global_variables: Vec<IdDecl>,
64
    pub equations: Vec<PresEquation>,
65
    pub init: PropVarInst,
66
}
67

            
68
#[derive(Debug, Eq, PartialEq, Hash)]
69
pub struct PropVarDecl {
70
    pub identifier: String,
71
    pub parameters: Vec<IdDecl>,
72
    pub span: Span,
73
}
74

            
75
impl PropVarDecl {
76
    /// Creates a new propositional variable declaration with the given identifier and parameters.
77
3000
    pub fn new(identifier: String, parameters: Vec<IdDecl>) -> Self {
78
3000
        PropVarDecl {
79
3000
            identifier,
80
3000
            parameters,
81
3000
            span: Span::default(),
82
3000
        }
83
3000
    }
84
}
85

            
86
#[derive(Debug, Default, Eq, PartialEq, Hash)]
87
pub struct PropVarInst {
88
    pub identifier: String,
89
    pub arguments: Vec<DataExpr>,
90
}
91

            
92
impl PropVarInst {
93
    /// Creates a new instance of a propositional variable with the given identifier and arguments.
94
13340
    pub fn new(identifier: String, arguments: Vec<DataExpr>) -> Self {
95
13340
        PropVarInst { identifier, arguments }
96
13340
    }
97
}
98

            
99
/// A declaration of an identifier with its sort.
100
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
101
pub struct IdDecl {
102
    /// Identifier being declared
103
    pub identifier: String,
104
    /// Sort expression for this identifier
105
    pub sort: SortExpression,
106
    /// Source location information
107
    pub span: Span,
108
    /// Unique ID assigned to this declaration during name resolution.
109
    pub id: Option<DefId>,
110
}
111

            
112
impl IdDecl {
113
    /// Creates a new identifier declaration with the given identifier, sort, and span.
114
305510
    pub fn new(identifier: String, sort: SortExpression, span: Span) -> Self {
115
305510
        IdDecl {
116
305510
            identifier,
117
305510
            sort,
118
305510
            span,
119
305510
            id: None,
120
305510
        }
121
305510
    }
122
}
123

            
124
/// Expression representing a sort (type).
125
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
126
pub enum SortExpression {
127
    /// Product of two sorts (A # B)
128
    Product {
129
        lhs: Box<SortExpression>,
130
        rhs: Box<SortExpression>,
131
    },
132
    /// Function sort (A -> B)
133
    Function {
134
        domain: Box<SortExpression>,
135
        range: Box<SortExpression>,
136
    },
137
    Struct {
138
        inner: Vec<ConstructorDecl>,
139
    },
140
    /// Reference to a named sort    
141
    Reference(String),
142
    /// Built-in simple sort
143
    Simple(Sort),
144
    /// Parameterized complex sort
145
    Complex(ComplexSort, Box<SortExpression>),
146
    /// Resolved reference to a sort after name resolution
147
    Resolved(String, DefId),
148
    /// Function sort (A_0 # ... # A_n -> B) after flattening (performed during name resolution)
149
    FlattenedFunction {
150
        domain: Vec<SortExpression>,
151
        range: Box<SortExpression>,
152
    },
153
}
154

            
155
/// Constructor declaration
156
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
157
pub struct ConstructorDecl {
158
    pub name: String,
159
    pub args: Vec<(Option<String>, SortExpression)>,
160
    pub projection: Option<String>,
161
}
162

            
163
/// Built-in simple sorts.
164
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
165
pub enum Sort {
166
    Bool,
167
    Pos,
168
    Int,
169
    Nat,
170
    Real,
171
}
172

            
173
/// Complex (parameterized) sorts.
174
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
175
pub enum ComplexSort {
176
    List,
177
    Set,
178
    FSet,
179
    FBag,
180
    Bag,
181
}
182

            
183
/// Sort declaration
184
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
185
pub struct SortDecl {
186
    /// Sort identifier
187
    pub identifier: String,
188
    /// Sort expression (if structured)
189
    pub expr: Option<SortExpression>,
190
    /// Where the sort is defined
191
    pub span: Span,
192
    /// Unique ID assigned to this declaration during name resolution.
193
    pub id: Option<DefId>,
194
}
195

            
196
impl SortDecl {
197
    /// Creates a new sort declaration with the given identifier, expression, and span.
198
17180
    pub fn new(identifier: String, expr: Option<SortExpression>, span: Span) -> Self {
199
17180
        SortDecl {
200
17180
            identifier,
201
17180
            expr,
202
17180
            span,
203
17180
            id: None,
204
17180
        }
205
17180
    }
206
}
207

            
208
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
209
pub struct EqnSpec {
210
    pub variables: Vec<IdDecl>,
211
    pub equations: Vec<EqnDecl>,
212
}
213

            
214
/// Equation declaration
215
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
216
pub struct EqnDecl {
217
    pub condition: Option<DataExpr>,
218
    pub lhs: DataExpr,
219
    pub rhs: DataExpr,
220
    pub span: Span,
221
}
222

            
223
/// Action declaration
224
#[derive(Debug, Eq, PartialEq, Hash)]
225
pub struct ActDecl {
226
    pub identifier: String,
227
    pub args: Vec<SortExpression>,
228
    pub span: Span,
229
}
230

            
231
/// Process declaration
232
#[derive(Debug, Eq, PartialEq, Hash)]
233
pub struct ProcDecl {
234
    pub identifier: String,
235
    pub params: Vec<IdDecl>,
236
    pub body: ProcessExpr,
237
    pub span: Span,
238
}
239

            
240
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
241
pub enum DataExprUnaryOp {
242
    Negation,
243
    Minus,
244
    Size,
245
}
246

            
247
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
248
pub enum DataExprBinaryOp {
249
    Conj,
250
    Disj,
251
    Implies,
252
    Equal,
253
    NotEqual,
254
    LessThan,
255
    LessEqual,
256
    GreaterThan,
257
    GreaterEqual,
258
    Cons,
259
    Snoc,
260
    In,
261
    Concat,
262
    Add,
263
    Subtract,
264
    Div,
265
    IntDiv,
266
    Mod,
267
    Multiply,
268
    At,
269
}
270

            
271
/// Data expression
272
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
273
pub enum DataExpr {
274
    Id(String),
275
    Number(String), // Is string because the number can be any size.
276
    Bool(bool),
277
    Application {
278
        function: Box<DataExpr>,
279
        arguments: Vec<DataExpr>,
280
    },
281
    EmptyList,
282
    List(Vec<DataExpr>),
283
    EmptySet,
284
    Set(Vec<DataExpr>),
285
    EmptyBag,
286
    Bag(Vec<BagElement>),
287
    SetBagComp {
288
        variable: IdDecl,
289
        predicate: Box<DataExpr>,
290
    },
291
    Lambda {
292
        variables: Vec<IdDecl>,
293
        body: Box<DataExpr>,
294
    },
295
    Quantifier {
296
        op: Quantifier,
297
        variables: Vec<IdDecl>,
298
        body: Box<DataExpr>,
299
    },
300
    Unary {
301
        op: DataExprUnaryOp,
302
        expr: Box<DataExpr>,
303
    },
304
    Binary {
305
        op: DataExprBinaryOp,
306
        lhs: Box<DataExpr>,
307
        rhs: Box<DataExpr>,
308
    },
309
    FunctionUpdate {
310
        expr: Box<DataExpr>,
311
        update: Box<DataExprUpdate>,
312
    },
313
    Whr {
314
        expr: Box<DataExpr>,
315
        assignments: Vec<Assignment>,
316
    },
317
}
318

            
319
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
320
pub struct BagElement {
321
    pub expr: DataExpr,
322
    pub multiplicity: DataExpr,
323
}
324

            
325
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
326
pub struct DataExprUpdate {
327
    pub expr: DataExpr,
328
    pub update: DataExpr,
329
}
330

            
331
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
332
pub struct Assignment {
333
    pub identifier: String,
334
    pub expr: DataExpr,
335
}
336

            
337
#[derive(Debug, Eq, PartialEq, Hash)]
338
pub enum ProcExprBinaryOp {
339
    Sequence,
340
    Choice,
341
    Parallel,
342
    LeftMerge,
343
    CommMerge,
344
    Until,
345
}
346

            
347
/// Process expression
348
#[derive(Debug, Eq, PartialEq, Hash)]
349
pub enum ProcessExpr {
350
    Id(String, Vec<Assignment>),
351
    Action(String, Vec<DataExpr>),
352
    Delta,
353
    Tau,
354
    Sum {
355
        variables: Vec<IdDecl>,
356
        operand: Box<ProcessExpr>,
357
    },
358
    Dist {
359
        variables: Vec<IdDecl>,
360
        expr: DataExpr,
361
        operand: Box<ProcessExpr>,
362
    },
363
    Binary {
364
        op: ProcExprBinaryOp,
365
        lhs: Box<ProcessExpr>,
366
        rhs: Box<ProcessExpr>,
367
    },
368
    Hide {
369
        actions: Vec<String>,
370
        operand: Box<ProcessExpr>,
371
    },
372
    Rename {
373
        renames: Vec<Rename>,
374
        operand: Box<ProcessExpr>,
375
    },
376
    Allow {
377
        actions: Vec<MultiActionLabel>,
378
        operand: Box<ProcessExpr>,
379
    },
380
    Block {
381
        actions: Vec<String>,
382
        operand: Box<ProcessExpr>,
383
    },
384
    Comm {
385
        comm: Vec<CommExpr>,
386
        operand: Box<ProcessExpr>,
387
    },
388
    Condition {
389
        condition: DataExpr,
390
        then: Box<ProcessExpr>,
391
        else_: Option<Box<ProcessExpr>>,
392
    },
393
    At {
394
        expr: Box<ProcessExpr>,
395
        operand: DataExpr,
396
    },
397
}
398

            
399
#[derive(Debug, Eq, PartialEq, Hash)]
400
pub struct UntypedStateFrmSpec {
401
    pub data_specification: UntypedDataSpecification,
402
    pub action_declarations: Vec<ActDecl>,
403
    pub formula: StateFrm,
404
}
405

            
406
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
407
pub enum StateFrmUnaryOp {
408
    Minus,
409
    Negation,
410
}
411

            
412
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
413
pub enum StateFrmOp {
414
    Addition,
415
    Implies,
416
    Disjunction,
417
    Conjunction,
418
}
419

            
420
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
421
pub enum FixedPointOperator {
422
    Least,
423
    Greatest,
424
}
425

            
426
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
427
pub struct StateVarDecl {
428
    pub identifier: String,
429
    pub arguments: Vec<StateVarAssignment>,
430
    pub span: Span,
431
}
432

            
433
impl StateVarDecl {
434
    /// Creates a new state variable declaration.
435
27100
    pub fn new(identifier: String, arguments: Vec<StateVarAssignment>) -> Self {
436
27100
        StateVarDecl {
437
27100
            identifier,
438
27100
            arguments,
439
27100
            span: Span::default(),
440
27100
        }
441
27100
    }
442
}
443

            
444
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
445
pub struct StateVarAssignment {
446
    pub identifier: String,
447
    pub sort: SortExpression,
448
    pub expr: DataExpr,
449
}
450

            
451
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
452
pub enum ModalityOperator {
453
    Diamond,
454
    Box,
455
}
456

            
457
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
458
pub enum StateFrm {
459
    True,
460
    False,
461
    /// `delay` or `delay@t`; the optional time is `None` for a bare `delay`.
462
    Delay(Option<DataExpr>),
463
    /// `yaled` or `yaled@t`; the optional time is `None` for a bare `yaled`.
464
    Yaled(Option<DataExpr>),
465
    Id(String, Vec<DataExpr>),
466
    DataValExprLeftMult(DataExpr, Box<StateFrm>),
467
    DataValExprRightMult(Box<StateFrm>, DataExpr),
468
    DataValExpr(DataExpr),
469
    Modality {
470
        operator: ModalityOperator,
471
        formula: RegFrm,
472
        expr: Box<StateFrm>,
473
    },
474
    Unary {
475
        op: StateFrmUnaryOp,
476
        expr: Box<StateFrm>,
477
    },
478
    Binary {
479
        op: StateFrmOp,
480
        lhs: Box<StateFrm>,
481
        rhs: Box<StateFrm>,
482
    },
483
    Quantifier {
484
        quantifier: Quantifier,
485
        variables: Vec<IdDecl>,
486
        body: Box<StateFrm>,
487
    },
488
    Bound {
489
        bound: Bound,
490
        variables: Vec<IdDecl>,
491
        body: Box<StateFrm>,
492
    },
493
    FixedPoint {
494
        operator: FixedPointOperator,
495
        variable: StateVarDecl,
496
        body: Box<StateFrm>,
497
    },
498
}
499

            
500
/// Represents a multi action label `a | b | c ...`.
501
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
502
pub struct MultiActionLabel {
503
    pub actions: Vec<String>,
504
}
505

            
506
impl MultiActionLabel {
507
    /// Creates a new multi-action label from a list of action identifiers.
508
2920
    pub fn new(actions: Vec<String>) -> Self {
509
2920
        MultiActionLabel { actions }
510
2920
    }
511

            
512
    /// Returns true if the multi-action label is empty (i.e., contains no actions).
513
    pub fn is_tau_label(&self) -> bool {
514
        self.actions.is_empty()
515
    }
516
}
517

            
518
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
519
pub struct Action {
520
    pub id: String,
521
    pub args: Vec<DataExpr>,
522
}
523

            
524
impl Action {
525
    /// Creates a new action from an identifier and a list of arguments.
526
9870
    pub fn new(id: String, args: Vec<DataExpr>) -> Self {
527
9870
        Action { id, args }
528
9870
    }
529
}
530

            
531
#[derive(Clone, Debug, Eq)]
532
pub struct MultiAction {
533
    pub actions: Vec<Action>,
534
}
535

            
536
impl MultiAction {
537
    /// Creates a new multi-action from a list of actions.
538
9870
    pub fn new(actions: Vec<Action>) -> Self {
539
9870
        MultiAction { actions }
540
9870
    }
541

            
542
    /// Creates the empty multi-action, which represents the tau action.
543
19340
    pub fn tau() -> Self {
544
19340
        MultiAction { actions: Vec::new() }
545
19340
    }
546
}
547

            
548
impl PartialEq for MultiAction {
549
77720
    fn eq(&self, other: &Self) -> bool {
550
        // Check whether both multi-actions contain the same actions
551
77720
        if self.actions.len() != other.actions.len() {
552
19910
            return false;
553
57810
        }
554

            
555
        // Map every action onto the other, equal length means they must be the same.
556
57810
        for action in self.actions.iter() {
557
29210
            if !other.actions.contains(action) {
558
9420
                return false;
559
19790
            }
560
        }
561

            
562
48390
        true
563
77720
    }
564
}
565

            
566
impl Hash for MultiAction {
567
99571
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
568
99571
        let mut actions = self.actions.clone();
569
        // Sort the action ids to ensure that the hash is independent of the order.
570
99571
        actions.sort();
571
99571
        for action in actions {
572
42637
            action.hash(state);
573
42637
        }
574
99571
    }
575
}
576

            
577
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
578
pub enum Quantifier {
579
    Exists,
580
    Forall,
581
}
582

            
583
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
584
pub enum ActFrmBinaryOp {
585
    Implies,
586
    Union,
587
    Intersect,
588
}
589

            
590
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
591
pub enum ActFrm {
592
    True,
593
    False,
594
    MultAct(MultiAction),
595
    DataExprVal(DataExpr),
596
    Negation(Box<ActFrm>),
597
    Quantifier {
598
        quantifier: Quantifier,
599
        variables: Vec<IdDecl>,
600
        body: Box<ActFrm>,
601
    },
602
    Binary {
603
        op: ActFrmBinaryOp,
604
        lhs: Box<ActFrm>,
605
        rhs: Box<ActFrm>,
606
    },
607
}
608

            
609
#[derive(Debug, Eq, PartialEq, Hash)]
610
pub enum PbesExpr {
611
    DataValExpr(DataExpr),
612
    PropVarInst(PropVarInst),
613
    Quantifier {
614
        quantifier: Quantifier,
615
        variables: Vec<IdDecl>,
616
        body: Box<PbesExpr>,
617
    },
618
    Negation(Box<PbesExpr>),
619
    Binary {
620
        op: PbesExprBinaryOp,
621
        lhs: Box<PbesExpr>,
622
        rhs: Box<PbesExpr>,
623
    },
624
    True,
625
    False,
626
}
627

            
628
#[derive(Debug, Eq, PartialEq, Hash)]
629
pub enum Eq {
630
    EqInf,
631
    EqnInf,
632
}
633

            
634
#[derive(Debug, Eq, PartialEq, Hash)]
635
pub enum Condition {
636
    Condsm,
637
    Condeq,
638
}
639

            
640
// TODO: What should this be called?
641
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
642
pub enum Bound {
643
    Inf,
644
    Sup,
645
    Sum,
646
}
647

            
648
#[derive(Debug, Eq, PartialEq, Hash)]
649
pub enum PresExprBinaryOp {
650
    Implies,
651
    Disjunction,
652
    Conjunction,
653
    Add,
654
}
655

            
656
#[derive(Debug, Eq, PartialEq, Hash)]
657
pub enum PresExpr {
658
    DataValExpr(DataExpr),
659
    PropVarInst(PropVarInst),
660
    RightConstantMultiply {
661
        expr: Box<PresExpr>,
662
        constant: DataExpr,
663
    },
664
    LeftConstantMultiply {
665
        constant: DataExpr,
666
        expr: Box<PresExpr>,
667
    },
668
    Bound {
669
        op: Bound,
670
        variables: Vec<IdDecl>,
671
        expr: Box<PresExpr>,
672
    },
673
    Equal {
674
        eq: Eq,
675
        body: Box<PresExpr>,
676
    },
677
    Condition {
678
        condition: Condition,
679
        lhs: Box<PresExpr>,
680
        then: Box<PresExpr>,
681
        else_: Box<PresExpr>,
682
    },
683
    Negation(Box<PresExpr>),
684
    Binary {
685
        op: PresExprBinaryOp,
686
        lhs: Box<PresExpr>,
687
        rhs: Box<PresExpr>,
688
    },
689
    True,
690
    False,
691
}
692

            
693
#[derive(Debug, Eq, PartialEq, Hash)]
694
pub struct PbesEquation {
695
    pub operator: FixedPointOperator,
696
    pub variable: PropVarDecl,
697
    pub formula: PbesExpr,
698
    pub span: Span,
699
}
700

            
701
impl PbesEquation {
702
    /// Creates a new PBES equation with the given operator, variable and formula.
703
3000
    pub fn new(operator: FixedPointOperator, variable: PropVarDecl, formula: PbesExpr) -> Self {
704
3000
        PbesEquation {
705
3000
            operator,
706
3000
            variable,
707
3000
            formula,
708
3000
            span: Span::default(),
709
3000
        }
710
3000
    }
711
}
712

            
713
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
714
pub enum PbesExprBinaryOp {
715
    Implies,
716
    Disjunction,
717
    Conjunction,
718
}
719

            
720
#[derive(Debug, Eq, PartialEq, Hash)]
721
pub struct PresEquation {
722
    pub operator: FixedPointOperator,
723
    pub variable: PropVarDecl,
724
    pub formula: PresExpr,
725
    pub span: Span,
726
}
727

            
728
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
729
pub enum RegFrm {
730
    Action(ActFrm),
731
    Iteration(Box<RegFrm>),
732
    Plus(Box<RegFrm>),
733
    Sequence { lhs: Box<RegFrm>, rhs: Box<RegFrm> },
734
    Choice { lhs: Box<RegFrm>, rhs: Box<RegFrm> },
735
}
736

            
737
#[derive(Debug, Eq, PartialEq, Hash)]
738
pub struct Rename {
739
    pub from: String,
740
    pub to: String,
741
}
742

            
743
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
744
pub struct CommExpr {
745
    pub from: MultiActionLabel,
746
    pub to: String,
747
}
748

            
749
impl CommExpr {
750
    /// Creates a new communication expression from a multi-action label and a target action identifier.
751
660
    pub fn new(from: MultiActionLabel, to: String) -> Self {
752
660
        CommExpr { from, to }
753
660
    }
754
}
755

            
756
#[derive(Debug, Eq, PartialEq, Hash)]
757
pub struct UntypedActionRenameSpec {
758
    pub data_specification: UntypedDataSpecification,
759
    pub action_declarations: Vec<ActDecl>,
760
    pub rename_declarations: Vec<ActionRenameDecl>,
761
}
762

            
763
#[derive(Debug, Eq, PartialEq, Hash)]
764
pub struct ActionRenameDecl {
765
    pub variables_specification: Vec<IdDecl>,
766
    pub rename_rule: ActionRenameRule,
767
}
768

            
769
#[derive(Debug, Eq, PartialEq, Hash)]
770
pub struct ActionRenameRule {
771
    pub condition: Option<DataExpr>,
772
    pub action: Action,
773
    pub rhs: ActionRHS,
774
}
775

            
776
#[derive(Debug, Eq, PartialEq, Hash)]
777
pub enum ActionRHS {
778
    Tau,
779
    Delta,
780
    Action(Action),
781
}
782

            
783
/// Source location information, spanning from start to end in the source text.
784
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)]
785
pub struct Span {
786
    pub start: usize,
787
    pub end: usize,
788
}
789

            
790
impl From<pest::Span<'_>> for Span {
791
604322
    fn from(span: pest::Span) -> Self {
792
604322
        Span {
793
604322
            start: span.start(),
794
604322
            end: span.end(),
795
604322
        }
796
604322
    }
797
}