1use crate::element::{
2 DamlElementVisitor, DamlTyCon, DamlTyConName, DamlType, DamlTypeVarWithKind, DamlVisitableElement,
3};
4use bounded_static::ToStatic;
5use serde::Serialize;
6use std::borrow::Cow;
7use std::fmt;
8use std::fmt::{Display, Formatter};
9
10#[derive(Debug, Serialize, Clone, ToStatic)]
12pub enum DamlExpr<'a> {
13 Var(Cow<'a, str>),
14 Val(Box<DamlValueName<'a>>),
15 Builtin(DamlBuiltinFunction),
16 PrimCon(DamlPrimCon),
17 PrimLit(DamlPrimLit<'a>),
18 RecCon(DamlRecCon<'a>),
19 RecProj(DamlRecProj<'a>),
20 RecUpd(DamlRecUpd<'a>),
21 VariantCon(DamlVariantCon<'a>),
22 EnumCon(DamlEnumCon<'a>),
23 StructCon(DamlStructCon<'a>),
24 StructProj(DamlStructProj<'a>),
25 StructUpd(DamlStructUpd<'a>),
26 App(DamlApp<'a>),
27 TyApp(DamlTyApp<'a>),
28 Abs(DamlAbs<'a>),
29 TyAbs(DamlTyAbs<'a>),
30 Case(DamlCase<'a>),
31 Let(DamlBlock<'a>),
32 Nil(DamlType<'a>),
33 Cons(DamlCons<'a>),
34 Update(DamlUpdate<'a>),
35 Scenario(DamlScenario<'a>),
36 OptionalNone(DamlType<'a>),
37 OptionalSome(DamlOptionalSome<'a>),
38 ToAny(DamlToAny<'a>),
39 FromAny(DamlFromAny<'a>),
40 TypeRep(DamlType<'a>),
41 ToAnyException(DamlToAnyException<'a>),
42 FromAnyException(DamlFromAnyException<'a>),
43 Throw(DamlThrow<'a>),
44}
45
46impl<'a> DamlVisitableElement<'a> for DamlExpr<'a> {
47 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
48 visitor.pre_visit_expr(self);
49 match self {
50 DamlExpr::Val(val) => val.accept(visitor),
51 DamlExpr::Builtin(builtin) => builtin.accept(visitor),
52 DamlExpr::PrimCon(prim_con) => prim_con.accept(visitor),
53 DamlExpr::PrimLit(prim_lit) => prim_lit.accept(visitor),
54 DamlExpr::RecCon(rec_con) => rec_con.accept(visitor),
55 DamlExpr::RecProj(rec_proj) => rec_proj.accept(visitor),
56 DamlExpr::RecUpd(rec_upd) => rec_upd.accept(visitor),
57 DamlExpr::VariantCon(variant_con) => variant_con.accept(visitor),
58 DamlExpr::EnumCon(enum_con) => enum_con.accept(visitor),
59 DamlExpr::StructCon(struct_con) => struct_con.accept(visitor),
60 DamlExpr::StructProj(struct_proj) => struct_proj.accept(visitor),
61 DamlExpr::StructUpd(struct_upd) => struct_upd.accept(visitor),
62 DamlExpr::App(app) => app.accept(visitor),
63 DamlExpr::TyApp(ty_app) => ty_app.accept(visitor),
64 DamlExpr::Abs(abs) => abs.accept(visitor),
65 DamlExpr::TyAbs(ty_abs) => ty_abs.accept(visitor),
66 DamlExpr::Case(case) => case.accept(visitor),
67 DamlExpr::Let(block) => block.accept(visitor),
68 DamlExpr::Cons(cons) => cons.accept(visitor),
69 DamlExpr::Update(update) => update.accept(visitor),
70 DamlExpr::Scenario(scenario) => scenario.accept(visitor),
71 DamlExpr::OptionalSome(opt_some) => opt_some.accept(visitor),
72 DamlExpr::ToAny(to_any) => to_any.accept(visitor),
73 DamlExpr::FromAny(from_any) => from_any.accept(visitor),
74 DamlExpr::TypeRep(ty) | DamlExpr::OptionalNone(ty) | DamlExpr::Nil(ty) => ty.accept(visitor),
75 DamlExpr::ToAnyException(to_any_exception) => to_any_exception.accept(visitor),
76 DamlExpr::FromAnyException(from_any_exception) => from_any_exception.accept(visitor),
77 DamlExpr::Throw(throw) => throw.accept(visitor),
78 DamlExpr::Var(_) => {},
79 }
80 visitor.post_visit_expr(self);
81 }
82}
83
84#[derive(Debug, Serialize, Clone, ToStatic)]
86pub enum DamlValueName<'a> {
87 Local(DamlLocalValueName<'a>),
88 NonLocal(DamlNonLocalValueName<'a>),
89}
90
91impl DamlValueName<'_> {
92 pub fn name(&self) -> &str {
93 match self {
94 DamlValueName::Local(local) => local.name(),
95 DamlValueName::NonLocal(non_local) => non_local.name(),
96 }
97 }
98
99 pub fn package_id(&self) -> &str {
100 match self {
101 DamlValueName::Local(local) => local.package_id(),
102 DamlValueName::NonLocal(non_local) => non_local.target_package_id(),
103 }
104 }
105
106 pub fn package_name(&self) -> &str {
107 match self {
108 DamlValueName::Local(local) => local.package_name(),
109 DamlValueName::NonLocal(non_local) => non_local.target_package_name(),
110 }
111 }
112
113 pub fn module_path(&self) -> impl Iterator<Item = &str> {
114 match self {
115 DamlValueName::Local(local) => local.module_path.iter().map(AsRef::as_ref),
116 DamlValueName::NonLocal(non_local) => non_local.target_module_path.iter().map(AsRef::as_ref),
117 }
118 }
119
120 #[doc(hidden)]
122 pub(crate) fn reference_parts(&self) -> (&str, &[Cow<'_, str>], &str) {
123 match self {
124 DamlValueName::Local(local) => (&local.package_id, &local.module_path, &local.name),
125 DamlValueName::NonLocal(non_local) =>
126 (&non_local.target_package_id, &non_local.target_module_path, &non_local.name),
127 }
128 }
129}
130
131impl Display for DamlValueName<'_> {
132 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
133 match self {
134 DamlValueName::Local(local) =>
135 write!(f, "{}:{}:{}", local.package_name, &local.module_path.join("."), local.name),
136 DamlValueName::NonLocal(non_local) => write!(
137 f,
138 "{}:{}:{}",
139 non_local.target_package_name,
140 &non_local.target_module_path.join("."),
141 non_local.name
142 ),
143 }
144 }
145}
146
147impl<'a> DamlVisitableElement<'a> for DamlValueName<'a> {
148 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
149 visitor.pre_visit_value_name(self);
150 match self {
151 DamlValueName::Local(local) => local.accept(visitor),
152 DamlValueName::NonLocal(non_local) => non_local.accept(visitor),
153 }
154 visitor.post_visit_value_name(self);
155 }
156}
157
158#[derive(Debug, Serialize, Clone, ToStatic)]
160pub struct DamlLocalValueName<'a> {
161 pub name: Cow<'a, str>,
162 pub package_id: Cow<'a, str>,
163 pub package_name: Cow<'a, str>,
164 pub module_path: Vec<Cow<'a, str>>,
165}
166
167impl<'a> DamlLocalValueName<'a> {
168 pub fn new(
169 name: Cow<'a, str>,
170 package_id: Cow<'a, str>,
171 package_name: Cow<'a, str>,
172 module_path: Vec<Cow<'a, str>>,
173 ) -> Self {
174 Self {
175 name,
176 package_id,
177 package_name,
178 module_path,
179 }
180 }
181
182 pub fn name(&self) -> &str {
183 &self.name
184 }
185
186 pub fn package_id(&self) -> &str {
187 &self.package_id
188 }
189
190 pub fn package_name(&self) -> &str {
191 &self.package_name
192 }
193
194 pub fn module_path(&self) -> impl Iterator<Item = &str> {
195 self.module_path.iter().map(AsRef::as_ref)
196 }
197}
198
199impl<'a> DamlVisitableElement<'a> for DamlLocalValueName<'a> {
200 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
201 visitor.pre_visit_local_value_name(self);
202 visitor.post_visit_local_value_name(self);
203 }
204}
205
206#[derive(Debug, Serialize, Clone, ToStatic)]
208pub struct DamlNonLocalValueName<'a> {
209 name: Cow<'a, str>,
210 source_package_id: Cow<'a, str>,
211 source_package_name: Cow<'a, str>,
212 source_module_path: Vec<Cow<'a, str>>,
213 target_package_id: Cow<'a, str>,
214 target_package_name: Cow<'a, str>,
215 target_module_path: Vec<Cow<'a, str>>,
216}
217
218impl<'a> DamlNonLocalValueName<'a> {
219 pub fn new(
220 name: Cow<'a, str>,
221 source_package_id: Cow<'a, str>,
222 source_package_name: Cow<'a, str>,
223 source_module_path: Vec<Cow<'a, str>>,
224 target_package_id: Cow<'a, str>,
225 target_package_name: Cow<'a, str>,
226 target_module_path: Vec<Cow<'a, str>>,
227 ) -> Self {
228 Self {
229 name,
230 source_package_id,
231 source_package_name,
232 source_module_path,
233 target_package_id,
234 target_package_name,
235 target_module_path,
236 }
237 }
238
239 pub fn name(&self) -> &str {
240 &self.name
241 }
242
243 pub fn source_package_id(&self) -> &str {
244 &self.source_package_id
245 }
246
247 pub fn source_package_name(&self) -> &str {
248 &self.source_package_name
249 }
250
251 pub fn source_module_path(&self) -> impl Iterator<Item = &str> {
252 self.source_module_path.iter().map(AsRef::as_ref)
253 }
254
255 pub fn target_package_id(&self) -> &str {
256 &self.target_package_id
257 }
258
259 pub fn target_package_name(&self) -> &str {
260 &self.target_package_name
261 }
262
263 pub fn target_module_path(&self) -> impl Iterator<Item = &str> {
264 self.target_module_path.iter().map(AsRef::as_ref)
265 }
266}
267
268impl<'a> DamlVisitableElement<'a> for DamlNonLocalValueName<'a> {
269 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
270 visitor.pre_visit_non_local_value_name(self);
271 visitor.post_visit_non_local_value_name(self);
272 }
273}
274
275#[derive(Debug, Serialize, Clone, ToStatic)]
277pub enum DamlBuiltinFunction {
278 AddDecimal,
279 SubDecimal,
280 MulDecimal,
281 DivDecimal,
282 RoundDecimal,
283 AddNumeric,
284 SubNumeric,
285 MulNumeric,
286 DivNumeric,
287 RoundNumeric,
288 CastNumeric,
289 ShiftNumeric,
290 AddInt64,
291 SubInt64,
292 MulInt64,
293 DivInt64,
294 ModInt64,
295 ExpInt64,
296 Foldl,
297 Foldr,
298 TextmapEmpty,
299 TextmapInsert,
300 TextmapLookup,
301 TextmapDelete,
302 TextmapToList,
303 TextmapSize,
304 ExplodeText,
305 AppendText,
306 Error,
307 AnyExceptionMessage,
308 LeqInt64,
309 LeqDecimal,
310 LeqNumeric,
311 LeqText,
312 LeqTimestamp,
313 LeqDate,
314 LeqParty,
315 LessInt64,
316 LessDecimal,
317 LessNumeric,
318 LessText,
319 LessTimestamp,
320 LessDate,
321 LessParty,
322 GeqInt64,
323 GeqDecimal,
324 GeqNumeric,
325 GeqText,
326 GeqTimestamp,
327 GeqDate,
328 GeqParty,
329 GreaterInt64,
330 GreaterDecimal,
331 GreaterNumeric,
332 GreaterText,
333 GreaterTimestamp,
334 GreaterDate,
335 GreaterParty,
336 Int64ToText,
337 DecimalToText,
338 NumericToText,
339 TextToText,
340 TimestampToText,
341 DateToText,
342 PartyToQuotedText,
343 PartyToText,
344 TextToParty,
345 TextToInt64,
346 TextToDecimal,
347 TextToNumeric,
348 ContractIdToText,
349 Sha256Text,
350 DateToUnixDays,
351 UnixDaysToDate,
352 TimestampToUnixMicroseconds,
353 UnixMicrosecondsToTimestamp,
354 Int64ToDecimal,
355 DecimalToInt64,
356 Int64ToNumeric,
357 NumericToInt64,
358 ImplodeText,
359 EqualInt64,
360 EqualDecimal,
361 EqualNumeric,
362 EqualText,
363 EqualTimestamp,
364 EqualDate,
365 EqualParty,
366 EqualBool,
367 EqualContractId,
368 EqualList,
369 EqualTypeRep,
370 Trace,
371 CoerceContractId,
372 CodePointsToText,
373 TextPointsToCode,
374 ScaleBignumeric,
375 PrecisionBignumeric,
376 AddBignumeric,
377 SubBignumeric,
378 MulBignumeric,
379 DivBignumeric,
380 ShiftBignumeric,
381 ShiftRightBignumeric,
382 BigNumericToNumeric,
383 NumericToBigNumeric,
384 BigNumericToText,
385 GenmapEmpty,
386 GenmapInsert,
387 GenmapLookup,
388 GenmapDelete,
389 GenmapKeys,
390 GenmapValues,
391 GenmapSize,
392 Equal,
393 LessEq,
394 Less,
395 GreaterEq,
396 Greater,
397}
398
399impl<'a> DamlVisitableElement<'a> for DamlBuiltinFunction {
400 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
401 visitor.pre_visit_builtin_function(self);
402 visitor.post_visit_builtin_function(self);
403 }
404}
405
406#[derive(Debug, Serialize, Copy, Clone, ToStatic)]
408pub enum DamlPrimCon {
409 Unit,
410 False,
411 True,
412}
413
414impl<'a> DamlVisitableElement<'a> for DamlPrimCon {
415 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
416 visitor.pre_visit_prim_con(*self);
417 visitor.post_visit_prim_con(*self);
418 }
419}
420
421#[derive(Debug, Serialize, Clone, ToStatic)]
423pub enum DamlPrimLit<'a> {
424 Int64(i64),
426 Text(Cow<'a, str>),
428 Party(Cow<'a, str>),
430 Date(i32),
433 Timestamp(i64),
437 Numeric(Cow<'a, str>),
442 RoundingMode(RoundingMode),
443}
444
445impl<'a> DamlVisitableElement<'a> for DamlPrimLit<'a> {
446 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
447 visitor.pre_visit_prim_lit(self);
448 visitor.post_visit_prim_lit(self);
449 }
450}
451
452#[derive(Debug, Serialize, Clone, ToStatic)]
454pub enum RoundingMode {
455 Up,
456 Down,
457 Ceiling,
458 Floor,
459 HalfUp,
460 HalfDown,
461 HalfEven,
462 Unnecessary,
463}
464
465impl<'a> DamlVisitableElement<'a> for RoundingMode {
466 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
467 visitor.pre_visit_rounding_mode(self);
468 visitor.post_visit_rounding_mode(self);
469 }
470}
471
472#[derive(Debug, Serialize, Clone, ToStatic)]
474pub struct DamlRecCon<'a> {
475 tycon: DamlTyCon<'a>,
476 fields: Vec<DamlFieldWithExpr<'a>>,
477}
478
479impl<'a> DamlRecCon<'a> {
480 pub fn new(tycon: DamlTyCon<'a>, fields: Vec<DamlFieldWithExpr<'a>>) -> Self {
481 Self {
482 tycon,
483 fields,
484 }
485 }
486
487 pub fn tycon(&self) -> &DamlTyCon<'a> {
488 &self.tycon
489 }
490
491 pub fn fields(&self) -> &[DamlFieldWithExpr<'a>] {
492 &self.fields
493 }
494}
495
496impl<'a> DamlVisitableElement<'a> for DamlRecCon<'a> {
497 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
498 visitor.pre_visit_rec_con(self);
499 self.tycon.accept(visitor);
500 self.fields.iter().for_each(|field| field.accept(visitor));
501 visitor.post_visit_rec_con(self);
502 }
503}
504
505#[derive(Debug, Serialize, Clone, ToStatic)]
507pub struct DamlFieldWithExpr<'a> {
508 field: Cow<'a, str>,
509 expr: DamlExpr<'a>,
510}
511
512impl<'a> DamlFieldWithExpr<'a> {
513 pub fn new(field: Cow<'a, str>, expr: DamlExpr<'a>) -> Self {
514 Self {
515 field,
516 expr,
517 }
518 }
519
520 pub fn field(&self) -> &str {
521 &self.field
522 }
523
524 pub fn expr(&self) -> &DamlExpr<'a> {
525 &self.expr
526 }
527}
528
529impl<'a> DamlVisitableElement<'a> for DamlFieldWithExpr<'a> {
530 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
531 visitor.pre_visit_field_with_expr(self);
532 self.expr.accept(visitor);
533 visitor.post_visit_field_with_expr(self);
534 }
535}
536
537#[derive(Debug, Serialize, Clone, ToStatic)]
539pub struct DamlRecProj<'a> {
540 tycon: DamlTyCon<'a>,
541 record: Box<DamlExpr<'a>>,
542 field: Cow<'a, str>,
543}
544
545impl<'a> DamlRecProj<'a> {
546 pub fn new(tycon: DamlTyCon<'a>, record: Box<DamlExpr<'a>>, field: Cow<'a, str>) -> Self {
547 Self {
548 tycon,
549 record,
550 field,
551 }
552 }
553
554 pub fn tycon(&self) -> &DamlTyCon<'a> {
555 &self.tycon
556 }
557
558 pub fn record(&self) -> &DamlExpr<'a> {
559 self.record.as_ref()
560 }
561
562 pub fn field(&self) -> &str {
563 &self.field
564 }
565}
566
567impl<'a> DamlVisitableElement<'a> for DamlRecProj<'a> {
568 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
569 visitor.pre_visit_rec_proj(self);
570 self.tycon.accept(visitor);
571 self.record.accept(visitor);
572 visitor.post_visit_rec_proj(self);
573 }
574}
575
576#[derive(Debug, Serialize, Clone, ToStatic)]
578pub struct DamlRecUpd<'a> {
579 tycon: DamlTyCon<'a>,
580 record: Box<DamlExpr<'a>>,
581 update: Box<DamlExpr<'a>>,
582 field: Cow<'a, str>,
583}
584
585impl<'a> DamlRecUpd<'a> {
586 pub fn new(
587 tycon: DamlTyCon<'a>,
588 record: Box<DamlExpr<'a>>,
589 update: Box<DamlExpr<'a>>,
590 field: Cow<'a, str>,
591 ) -> Self {
592 Self {
593 tycon,
594 record,
595 update,
596 field,
597 }
598 }
599
600 pub fn tycon(&self) -> &DamlTyCon<'a> {
601 &self.tycon
602 }
603
604 pub fn record(&self) -> &DamlExpr<'a> {
605 self.record.as_ref()
606 }
607
608 pub fn update(&self) -> &DamlExpr<'a> {
609 self.update.as_ref()
610 }
611
612 pub fn field(&self) -> &str {
613 &self.field
614 }
615}
616
617impl<'a> DamlVisitableElement<'a> for DamlRecUpd<'a> {
618 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
619 visitor.pre_visit_rec_upd(self);
620 self.tycon.accept(visitor);
621 self.record.accept(visitor);
622 self.update.accept(visitor);
623 visitor.post_visit_rec_upd(self);
624 }
625}
626
627#[derive(Debug, Serialize, Clone, ToStatic)]
629pub struct DamlVariantCon<'a> {
630 tycon: DamlTyCon<'a>,
631 variant_arg: Box<DamlExpr<'a>>,
632 variant_con: Cow<'a, str>,
633}
634
635impl<'a> DamlVariantCon<'a> {
636 pub fn new(tycon: DamlTyCon<'a>, variant_arg: Box<DamlExpr<'a>>, variant_con: Cow<'a, str>) -> Self {
637 Self {
638 tycon,
639 variant_arg,
640 variant_con,
641 }
642 }
643
644 pub fn tycon(&self) -> &DamlTyCon<'a> {
645 &self.tycon
646 }
647
648 pub fn variant_arg(&self) -> &DamlExpr<'a> {
649 self.variant_arg.as_ref()
650 }
651
652 pub fn variant_con(&self) -> &str {
653 &self.variant_con
654 }
655}
656
657impl<'a> DamlVisitableElement<'a> for DamlVariantCon<'a> {
658 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
659 visitor.pre_visit_variant_con(self);
660 self.tycon.accept(visitor);
661 self.variant_arg.accept(visitor);
662 visitor.post_visit_variant_con(self);
663 }
664}
665
666#[derive(Debug, Serialize, Clone, ToStatic)]
668pub struct DamlEnumCon<'a> {
669 tycon: Box<DamlTyConName<'a>>,
670 enum_con: Cow<'a, str>,
671}
672
673impl<'a> DamlEnumCon<'a> {
674 pub fn new(tycon: Box<DamlTyConName<'a>>, enum_con: Cow<'a, str>) -> Self {
675 Self {
676 tycon,
677 enum_con,
678 }
679 }
680
681 pub fn tycon(&self) -> &DamlTyConName<'a> {
682 &self.tycon
683 }
684
685 pub fn enum_con(&self) -> &str {
686 &self.enum_con
687 }
688}
689
690impl<'a> DamlVisitableElement<'a> for DamlEnumCon<'a> {
691 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
692 visitor.pre_visit_enum_con(self);
693 self.tycon.accept(visitor);
694 visitor.post_visit_enum_con(self);
695 }
696}
697
698#[derive(Debug, Serialize, Clone, ToStatic)]
700pub struct DamlStructCon<'a> {
701 fields: Vec<DamlFieldWithExpr<'a>>,
702}
703
704impl<'a> DamlStructCon<'a> {
705 pub fn new(fields: Vec<DamlFieldWithExpr<'a>>) -> Self {
706 Self {
707 fields,
708 }
709 }
710
711 pub fn fields(&self) -> &[DamlFieldWithExpr<'a>] {
712 &self.fields
713 }
714}
715
716impl<'a> DamlVisitableElement<'a> for DamlStructCon<'a> {
717 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
718 visitor.pre_visit_struct_con(self);
719 self.fields.iter().for_each(|field| field.accept(visitor));
720 visitor.post_visit_struct_con(self);
721 }
722}
723
724#[derive(Debug, Serialize, Clone, ToStatic)]
726pub struct DamlStructProj<'a> {
727 struct_expr: Box<DamlExpr<'a>>,
728 field: Cow<'a, str>,
729}
730
731impl<'a> DamlStructProj<'a> {
732 pub fn new(struct_expr: Box<DamlExpr<'a>>, field: Cow<'a, str>) -> Self {
733 Self {
734 struct_expr,
735 field,
736 }
737 }
738
739 pub fn struct_expr(&self) -> &DamlExpr<'a> {
740 self.struct_expr.as_ref()
741 }
742
743 pub fn field(&self) -> &str {
744 &self.field
745 }
746}
747
748impl<'a> DamlVisitableElement<'a> for DamlStructProj<'a> {
749 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
750 visitor.pre_visit_struct_proj(self);
751 self.struct_expr.accept(visitor);
752 visitor.post_visit_struct_proj(self);
753 }
754}
755
756#[derive(Debug, Serialize, Clone, ToStatic)]
758pub struct DamlStructUpd<'a> {
759 struct_expr: Box<DamlExpr<'a>>,
760 update: Box<DamlExpr<'a>>,
761 field: Cow<'a, str>,
762}
763
764impl<'a> DamlStructUpd<'a> {
765 pub fn new(struct_expr: Box<DamlExpr<'a>>, update: Box<DamlExpr<'a>>, field: Cow<'a, str>) -> Self {
766 Self {
767 struct_expr,
768 update,
769 field,
770 }
771 }
772
773 pub fn struct_expr(&self) -> &DamlExpr<'a> {
774 self.struct_expr.as_ref()
775 }
776
777 pub fn update(&self) -> &DamlExpr<'a> {
778 self.update.as_ref()
779 }
780
781 pub fn field(&self) -> &str {
782 &self.field
783 }
784}
785
786impl<'a> DamlVisitableElement<'a> for DamlStructUpd<'a> {
787 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
788 visitor.pre_visit_struct_upd(self);
789 self.struct_expr.accept(visitor);
790 self.update.accept(visitor);
791 visitor.post_visit_struct_upd(self);
792 }
793}
794
795#[derive(Debug, Serialize, Clone, ToStatic)]
797pub struct DamlApp<'a> {
798 fun: Box<DamlExpr<'a>>,
799 args: Vec<DamlExpr<'a>>,
800}
801
802impl<'a> DamlApp<'a> {
803 pub fn new(fun: Box<DamlExpr<'a>>, args: Vec<DamlExpr<'a>>) -> Self {
804 Self {
805 fun,
806 args,
807 }
808 }
809
810 pub fn fun(&self) -> &DamlExpr<'a> {
811 self.fun.as_ref()
812 }
813
814 pub fn args(&self) -> &[DamlExpr<'a>] {
815 &self.args
816 }
817}
818
819impl<'a> DamlVisitableElement<'a> for DamlApp<'a> {
820 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
821 visitor.pre_visit_app(self);
822 self.fun.accept(visitor);
823 self.args.iter().for_each(|arg| arg.accept(visitor));
824 visitor.post_visit_app(self);
825 }
826}
827
828#[derive(Debug, Serialize, Clone, ToStatic)]
830pub struct DamlTyApp<'a> {
831 expr: Box<DamlExpr<'a>>,
832 types: Vec<DamlType<'a>>,
833}
834
835impl<'a> DamlTyApp<'a> {
836 pub fn new(expr: Box<DamlExpr<'a>>, types: Vec<DamlType<'a>>) -> Self {
837 Self {
838 expr,
839 types,
840 }
841 }
842
843 pub fn expr(&self) -> &DamlExpr<'a> {
844 self.expr.as_ref()
845 }
846
847 pub fn types(&self) -> &[DamlType<'a>] {
848 &self.types
849 }
850}
851
852impl<'a> DamlVisitableElement<'a> for DamlTyApp<'a> {
853 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
854 visitor.pre_visit_ty_app(self);
855 self.expr.accept(visitor);
856 self.types.iter().for_each(|ty| ty.accept(visitor));
857 visitor.post_visit_ty_app(self);
858 }
859}
860
861#[derive(Debug, Serialize, Clone, ToStatic)]
863pub struct DamlAbs<'a> {
864 params: Vec<DamlVarWithType<'a>>,
865 body: Box<DamlExpr<'a>>,
866}
867
868impl<'a> DamlAbs<'a> {
869 pub fn new(params: Vec<DamlVarWithType<'a>>, body: Box<DamlExpr<'a>>) -> Self {
870 Self {
871 params,
872 body,
873 }
874 }
875
876 pub fn params(&self) -> &[DamlVarWithType<'a>] {
877 &self.params
878 }
879
880 pub fn body(&self) -> &DamlExpr<'a> {
881 self.body.as_ref()
882 }
883}
884
885impl<'a> DamlVisitableElement<'a> for DamlAbs<'a> {
886 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
887 visitor.pre_visit_abs(self);
888 self.params.iter().for_each(|param| param.accept(visitor));
889 self.body.accept(visitor);
890 visitor.post_visit_abs(self);
891 }
892}
893
894#[derive(Debug, Serialize, Clone, ToStatic)]
896pub struct DamlVarWithType<'a> {
897 ty: DamlType<'a>,
898 var: Cow<'a, str>,
899}
900
901impl<'a> DamlVarWithType<'a> {
902 pub fn new(ty: DamlType<'a>, var: Cow<'a, str>) -> Self {
903 Self {
904 ty,
905 var,
906 }
907 }
908
909 pub fn ty(&self) -> &DamlType<'a> {
910 &self.ty
911 }
912
913 pub fn var(&self) -> &str {
914 &self.var
915 }
916}
917
918impl<'a> DamlVisitableElement<'a> for DamlVarWithType<'a> {
919 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
920 visitor.pre_visit_var_with_type(self);
921 self.ty.accept(visitor);
922 visitor.post_visit_var_with_type(self);
923 }
924}
925
926#[derive(Debug, Serialize, Clone, ToStatic)]
928pub struct DamlTyAbs<'a> {
929 params: Vec<DamlTypeVarWithKind<'a>>,
930 body: Box<DamlExpr<'a>>,
931}
932
933impl<'a> DamlTyAbs<'a> {
934 pub fn new(params: Vec<DamlTypeVarWithKind<'a>>, body: Box<DamlExpr<'a>>) -> Self {
935 Self {
936 params,
937 body,
938 }
939 }
940
941 pub fn params(&self) -> &[DamlTypeVarWithKind<'a>] {
942 &self.params
943 }
944
945 pub fn body(&self) -> &DamlExpr<'a> {
946 self.body.as_ref()
947 }
948}
949
950impl<'a> DamlVisitableElement<'a> for DamlTyAbs<'a> {
951 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
952 visitor.pre_visit_ty_abs(self);
953 self.params.iter().for_each(|type_var| type_var.accept(visitor));
954 self.body.accept(visitor);
955 visitor.post_visit_ty_abs(self);
956 }
957}
958
959#[derive(Debug, Serialize, Clone, ToStatic)]
961pub struct DamlBlock<'a> {
962 bindings: Vec<DamlBinding<'a>>,
963 body: Box<DamlExpr<'a>>,
964}
965
966impl<'a> DamlBlock<'a> {
967 pub fn new(bindings: Vec<DamlBinding<'a>>, body: Box<DamlExpr<'a>>) -> Self {
968 Self {
969 bindings,
970 body,
971 }
972 }
973
974 pub fn bindings(&self) -> &[DamlBinding<'a>] {
975 &self.bindings
976 }
977
978 pub fn body(&self) -> &DamlExpr<'a> {
979 self.body.as_ref()
980 }
981}
982
983impl<'a> DamlVisitableElement<'a> for DamlBlock<'a> {
984 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
985 visitor.pre_visit_block(self);
986 self.bindings.iter().for_each(|binding| binding.accept(visitor));
987 self.body.accept(visitor);
988 visitor.post_visit_block(self);
989 }
990}
991
992#[derive(Debug, Serialize, Clone, ToStatic)]
994pub struct DamlBinding<'a> {
995 binder: DamlVarWithType<'a>,
996 bound: DamlExpr<'a>,
997}
998
999impl<'a> DamlBinding<'a> {
1000 pub fn new(binder: DamlVarWithType<'a>, bound: DamlExpr<'a>) -> Self {
1001 Self {
1002 binder,
1003 bound,
1004 }
1005 }
1006
1007 pub fn binder(&self) -> &DamlVarWithType<'a> {
1008 &self.binder
1009 }
1010
1011 pub fn bound(&self) -> &DamlExpr<'a> {
1012 &self.bound
1013 }
1014}
1015
1016impl<'a> DamlVisitableElement<'a> for DamlBinding<'a> {
1017 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1018 visitor.pre_visit_binding(self);
1019 self.binder.accept(visitor);
1020 self.bound.accept(visitor);
1021 visitor.post_visit_binding(self);
1022 }
1023}
1024
1025#[derive(Debug, Serialize, Clone, ToStatic)]
1027pub struct DamlCons<'a> {
1028 ty: DamlType<'a>,
1029 front: Vec<DamlExpr<'a>>,
1030 tail: Box<DamlExpr<'a>>,
1031}
1032
1033impl<'a> DamlCons<'a> {
1034 pub fn new(ty: DamlType<'a>, front: Vec<DamlExpr<'a>>, tail: Box<DamlExpr<'a>>) -> Self {
1035 Self {
1036 ty,
1037 front,
1038 tail,
1039 }
1040 }
1041
1042 pub fn ty(&self) -> &DamlType<'a> {
1043 &self.ty
1044 }
1045
1046 pub fn front(&self) -> &[DamlExpr<'a>] {
1047 &self.front
1048 }
1049
1050 pub fn tail(&self) -> &DamlExpr<'a> {
1051 self.tail.as_ref()
1052 }
1053}
1054
1055impl<'a> DamlVisitableElement<'a> for DamlCons<'a> {
1056 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1057 visitor.pre_visit_cons(self);
1058 self.ty.accept(visitor);
1059 self.front.iter().for_each(|expr| expr.accept(visitor));
1060 self.tail.accept(visitor);
1061 visitor.post_visit_cons(self);
1062 }
1063}
1064
1065#[derive(Debug, Serialize, Clone, ToStatic)]
1067pub struct DamlCase<'a> {
1068 scrut: Box<DamlExpr<'a>>,
1069 alts: Vec<DamlCaseAlt<'a>>,
1070}
1071
1072impl<'a> DamlCase<'a> {
1073 pub fn new(scrut: Box<DamlExpr<'a>>, alts: Vec<DamlCaseAlt<'a>>) -> Self {
1074 Self {
1075 scrut,
1076 alts,
1077 }
1078 }
1079
1080 pub fn scrut(&self) -> &DamlExpr<'a> {
1081 self.scrut.as_ref()
1082 }
1083
1084 pub fn alts(&self) -> &[DamlCaseAlt<'a>] {
1085 &self.alts
1086 }
1087}
1088
1089impl<'a> DamlVisitableElement<'a> for DamlCase<'a> {
1090 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1091 visitor.pre_visit_case(self);
1092 self.scrut.accept(visitor);
1093 self.alts.iter().for_each(|alt| alt.accept(visitor));
1094 visitor.post_visit_case(self);
1095 }
1096}
1097
1098#[derive(Debug, Serialize, Clone, ToStatic)]
1100pub struct DamlCaseAlt<'a> {
1101 body: DamlExpr<'a>,
1102 sum: DamlCaseAltSum<'a>,
1103}
1104
1105impl<'a> DamlCaseAlt<'a> {
1106 pub fn new(body: DamlExpr<'a>, sum: DamlCaseAltSum<'a>) -> Self {
1107 Self {
1108 body,
1109 sum,
1110 }
1111 }
1112
1113 pub fn body(&self) -> &DamlExpr<'a> {
1114 &self.body
1115 }
1116
1117 pub fn sum(&self) -> &DamlCaseAltSum<'a> {
1118 &self.sum
1119 }
1120}
1121
1122impl<'a> DamlVisitableElement<'a> for DamlCaseAlt<'a> {
1123 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1124 visitor.pre_visit_case_alt(self);
1125 self.body.accept(visitor);
1126 self.sum.accept(visitor);
1127 visitor.post_visit_case_alt(self);
1128 }
1129}
1130
1131#[derive(Debug, Serialize, Clone, ToStatic)]
1133#[allow(clippy::large_enum_variant)] pub enum DamlCaseAltSum<'a> {
1135 Default,
1136 Variant(DamlCaseAltVariant<'a>),
1137 PrimCon(DamlPrimCon),
1138 Nil,
1139 Cons(DamlCaseAltCons<'a>),
1140 OptionalNone,
1141 OptionalSome(DamlCaseAltOptionalSome<'a>),
1142 Enum(DamlCaseAltEnum<'a>),
1143}
1144
1145impl<'a> DamlVisitableElement<'a> for DamlCaseAltSum<'a> {
1146 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1147 visitor.pre_visit_case_alt_sum(self);
1148 match self {
1149 DamlCaseAltSum::Variant(variant) => variant.accept(visitor),
1150 DamlCaseAltSum::PrimCon(prim_con) => prim_con.accept(visitor),
1151 DamlCaseAltSum::Cons(cons) => cons.accept(visitor),
1152 DamlCaseAltSum::OptionalSome(opt_some) => opt_some.accept(visitor),
1153 DamlCaseAltSum::Enum(enum_alt) => enum_alt.accept(visitor),
1154 DamlCaseAltSum::Default | DamlCaseAltSum::Nil | DamlCaseAltSum::OptionalNone => {},
1155 }
1156 visitor.post_visit_case_alt_sum(self);
1157 }
1158}
1159
1160#[derive(Debug, Serialize, Clone, ToStatic)]
1162pub struct DamlCaseAltVariant<'a> {
1163 con: DamlTyConName<'a>,
1164 variant: Cow<'a, str>,
1165 binder: Cow<'a, str>,
1166}
1167
1168impl<'a> DamlCaseAltVariant<'a> {
1169 pub fn new(con: DamlTyConName<'a>, variant: Cow<'a, str>, binder: Cow<'a, str>) -> Self {
1170 Self {
1171 con,
1172 variant,
1173 binder,
1174 }
1175 }
1176
1177 pub fn con(&self) -> &DamlTyConName<'a> {
1178 &self.con
1179 }
1180
1181 pub fn variant(&self) -> &str {
1182 &self.variant
1183 }
1184
1185 pub fn binder(&self) -> &str {
1186 &self.binder
1187 }
1188}
1189
1190impl<'a> DamlVisitableElement<'a> for DamlCaseAltVariant<'a> {
1191 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1192 visitor.pre_visit_case_alt_variant(self);
1193 self.con.accept(visitor);
1194 visitor.post_visit_case_alt_variant(self);
1195 }
1196}
1197
1198#[derive(Debug, Serialize, Clone, ToStatic)]
1200pub struct DamlCaseAltCons<'a> {
1201 var_head: Cow<'a, str>,
1202 var_tail: Cow<'a, str>,
1203}
1204
1205impl<'a> DamlCaseAltCons<'a> {
1206 pub fn new(var_head: Cow<'a, str>, var_tail: Cow<'a, str>) -> Self {
1207 Self {
1208 var_head,
1209 var_tail,
1210 }
1211 }
1212
1213 pub fn var_head(&self) -> &str {
1214 &self.var_head
1215 }
1216
1217 pub fn var_tail(&self) -> &str {
1218 &self.var_tail
1219 }
1220}
1221
1222impl<'a> DamlVisitableElement<'a> for DamlCaseAltCons<'a> {
1223 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1224 visitor.pre_visit_case_alt_cons(self);
1225 visitor.post_visit_case_alt_cons(self);
1226 }
1227}
1228
1229#[derive(Debug, Serialize, Clone, ToStatic)]
1231pub struct DamlCaseAltOptionalSome<'a> {
1232 var_body: Cow<'a, str>,
1233}
1234
1235impl<'a> DamlCaseAltOptionalSome<'a> {
1236 pub fn new(var_body: Cow<'a, str>) -> Self {
1237 Self {
1238 var_body,
1239 }
1240 }
1241
1242 pub fn var_body(&self) -> &str {
1243 &self.var_body
1244 }
1245}
1246
1247impl<'a> DamlVisitableElement<'a> for DamlCaseAltOptionalSome<'a> {
1248 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1249 visitor.pre_visit_case_alt_opt_some(self);
1250 visitor.post_visit_case_alt_opt_some(self);
1251 }
1252}
1253
1254#[derive(Debug, Serialize, Clone, ToStatic)]
1256pub struct DamlCaseAltEnum<'a> {
1257 con: DamlTyConName<'a>,
1258 constructor: Cow<'a, str>,
1259}
1260
1261impl<'a> DamlCaseAltEnum<'a> {
1262 pub fn new(con: DamlTyConName<'a>, constructor: Cow<'a, str>) -> Self {
1263 Self {
1264 con,
1265 constructor,
1266 }
1267 }
1268
1269 pub fn con(&self) -> &DamlTyConName<'a> {
1270 &self.con
1271 }
1272
1273 pub fn constructor(&self) -> &str {
1274 &self.constructor
1275 }
1276}
1277
1278impl<'a> DamlVisitableElement<'a> for DamlCaseAltEnum<'a> {
1279 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1280 visitor.pre_visit_case_alt_enum(self);
1281 self.con.accept(visitor);
1282 visitor.post_visit_case_alt_enum(self);
1283 }
1284}
1285
1286#[derive(Debug, Serialize, Clone, ToStatic)]
1288pub struct DamlOptionalSome<'a> {
1289 ty: DamlType<'a>,
1290 body: Box<DamlExpr<'a>>,
1291}
1292
1293impl<'a> DamlOptionalSome<'a> {
1294 pub fn new(ty: DamlType<'a>, body: Box<DamlExpr<'a>>) -> Self {
1295 Self {
1296 ty,
1297 body,
1298 }
1299 }
1300
1301 pub fn ty(&self) -> &DamlType<'a> {
1302 &self.ty
1303 }
1304
1305 pub fn body(&self) -> &DamlExpr<'a> {
1306 self.body.as_ref()
1307 }
1308}
1309
1310impl<'a> DamlVisitableElement<'a> for DamlOptionalSome<'a> {
1311 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1312 visitor.pre_visit_optional_some(self);
1313 self.ty.accept(visitor);
1314 self.body.accept(visitor);
1315 visitor.post_visit_optional_some(self);
1316 }
1317}
1318
1319#[derive(Debug, Serialize, Clone, ToStatic)]
1321pub struct DamlToAny<'a> {
1322 ty: DamlType<'a>,
1323 expr: Box<DamlExpr<'a>>,
1324}
1325
1326impl<'a> DamlToAny<'a> {
1327 pub fn new(ty: DamlType<'a>, expr: Box<DamlExpr<'a>>) -> Self {
1328 Self {
1329 ty,
1330 expr,
1331 }
1332 }
1333
1334 pub fn ty(&self) -> &DamlType<'a> {
1335 &self.ty
1336 }
1337
1338 pub fn expr(&self) -> &DamlExpr<'a> {
1339 self.expr.as_ref()
1340 }
1341}
1342
1343impl<'a> DamlVisitableElement<'a> for DamlToAny<'a> {
1344 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1345 visitor.pre_visit_to_any(self);
1346 self.ty.accept(visitor);
1347 self.expr.accept(visitor);
1348 visitor.post_visit_to_any(self);
1349 }
1350}
1351
1352#[derive(Debug, Serialize, Clone, ToStatic)]
1354pub struct DamlFromAny<'a> {
1355 ty: DamlType<'a>,
1356 expr: Box<DamlExpr<'a>>,
1357}
1358
1359impl<'a> DamlFromAny<'a> {
1360 pub fn new(ty: DamlType<'a>, expr: Box<DamlExpr<'a>>) -> Self {
1361 Self {
1362 ty,
1363 expr,
1364 }
1365 }
1366
1367 pub fn ty(&self) -> &DamlType<'a> {
1368 &self.ty
1369 }
1370
1371 pub fn expr(&self) -> &DamlExpr<'a> {
1372 self.expr.as_ref()
1373 }
1374}
1375
1376impl<'a> DamlVisitableElement<'a> for DamlFromAny<'a> {
1377 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1378 visitor.pre_visit_from_any(self);
1379 self.ty.accept(visitor);
1380 self.expr.accept(visitor);
1381 visitor.post_visit_from_any(self);
1382 }
1383}
1384
1385#[derive(Debug, Serialize, Clone, ToStatic)]
1387pub enum DamlUpdate<'a> {
1388 Pure(DamlPure<'a>),
1389 Block(DamlBlock<'a>),
1390 Create(DamlCreate<'a>),
1391 Exercise(DamlExercise<'a>),
1392 ExerciseByKey(DamlExerciseByKey<'a>),
1393 Fetch(DamlFetch<'a>),
1394 GetTime,
1395 LookupByKey(DamlRetrieveByKey<'a>),
1396 FetchByKey(DamlRetrieveByKey<'a>),
1397 EmbedExpr(DamlUpdateEmbedExpr<'a>),
1398 TryCatch(DamlTryCatch<'a>),
1399}
1400
1401impl<'a> DamlVisitableElement<'a> for DamlUpdate<'a> {
1402 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1403 visitor.pre_visit_update(self);
1404 match self {
1405 DamlUpdate::Pure(pure) => pure.accept(visitor),
1406 DamlUpdate::Block(block) => block.accept(visitor),
1407 DamlUpdate::Create(create) => create.accept(visitor),
1408 DamlUpdate::Exercise(exercise) => exercise.accept(visitor),
1409 DamlUpdate::ExerciseByKey(exercise_by_key) => exercise_by_key.accept(visitor),
1410 DamlUpdate::Fetch(fetch) => fetch.accept(visitor),
1411 DamlUpdate::LookupByKey(retrieve_by_key) | DamlUpdate::FetchByKey(retrieve_by_key) =>
1412 retrieve_by_key.accept(visitor),
1413 DamlUpdate::EmbedExpr(embed_expr) => embed_expr.accept(visitor),
1414 DamlUpdate::TryCatch(try_catch) => try_catch.accept(visitor),
1415 DamlUpdate::GetTime => {},
1416 }
1417 visitor.post_visit_update(self);
1418 }
1419}
1420
1421#[derive(Debug, Serialize, Clone, ToStatic)]
1423pub struct DamlPure<'a> {
1424 ty: DamlType<'a>,
1425 expr: Box<DamlExpr<'a>>,
1426}
1427
1428impl<'a> DamlPure<'a> {
1429 pub fn new(ty: DamlType<'a>, expr: Box<DamlExpr<'a>>) -> Self {
1430 Self {
1431 ty,
1432 expr,
1433 }
1434 }
1435
1436 pub fn ty(&self) -> &DamlType<'a> {
1437 &self.ty
1438 }
1439
1440 pub fn expr(&self) -> &DamlExpr<'a> {
1441 self.expr.as_ref()
1442 }
1443}
1444
1445impl<'a> DamlVisitableElement<'a> for DamlPure<'a> {
1446 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1447 visitor.pre_visit_pure(self);
1448 self.ty.accept(visitor);
1449 self.expr.accept(visitor);
1450 visitor.post_visit_pure(self);
1451 }
1452}
1453
1454#[derive(Debug, Serialize, Clone, ToStatic)]
1456pub struct DamlCreate<'a> {
1457 template: Box<DamlTyConName<'a>>,
1458 expr: Box<DamlExpr<'a>>,
1459}
1460
1461impl<'a> DamlCreate<'a> {
1462 pub fn new(template: Box<DamlTyConName<'a>>, expr: Box<DamlExpr<'a>>) -> Self {
1463 Self {
1464 template,
1465 expr,
1466 }
1467 }
1468
1469 pub fn template(&self) -> &DamlTyConName<'a> {
1470 &self.template
1471 }
1472
1473 pub fn expr(&self) -> &DamlExpr<'a> {
1474 self.expr.as_ref()
1475 }
1476}
1477
1478impl<'a> DamlVisitableElement<'a> for DamlCreate<'a> {
1479 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1480 visitor.pre_visit_create(self);
1481 self.template.accept(visitor);
1482 self.expr.accept(visitor);
1483 visitor.post_visit_create(self);
1484 }
1485}
1486
1487#[derive(Debug, Serialize, Clone, ToStatic)]
1489pub struct DamlExercise<'a> {
1490 template: Box<DamlTyConName<'a>>,
1491 cid: Box<DamlExpr<'a>>,
1492 arg: Box<DamlExpr<'a>>,
1493 choice: Cow<'a, str>,
1494}
1495
1496impl<'a> DamlExercise<'a> {
1497 pub fn new(
1498 template: Box<DamlTyConName<'a>>,
1499 cid: Box<DamlExpr<'a>>,
1500 arg: Box<DamlExpr<'a>>,
1501 choice: Cow<'a, str>,
1502 ) -> Self {
1503 Self {
1504 template,
1505 cid,
1506 arg,
1507 choice,
1508 }
1509 }
1510
1511 pub fn template(&self) -> &DamlTyConName<'a> {
1512 &self.template
1513 }
1514
1515 pub fn cid(&self) -> &DamlExpr<'a> {
1516 self.cid.as_ref()
1517 }
1518
1519 pub fn arg(&self) -> &DamlExpr<'a> {
1520 self.arg.as_ref()
1521 }
1522
1523 pub fn choice(&self) -> &str {
1524 &self.choice
1525 }
1526}
1527
1528impl<'a> DamlVisitableElement<'a> for DamlExercise<'a> {
1529 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1530 visitor.pre_visit_exercise(self);
1531 self.template.accept(visitor);
1532 self.cid.accept(visitor);
1533 self.arg.accept(visitor);
1534 visitor.post_visit_exercise(self);
1535 }
1536}
1537
1538#[derive(Debug, Serialize, Clone, ToStatic)]
1540pub struct DamlExerciseByKey<'a> {
1541 template: Box<DamlTyConName<'a>>,
1542 choice: Cow<'a, str>,
1543 key: Box<DamlExpr<'a>>,
1544 arg: Box<DamlExpr<'a>>,
1545}
1546
1547impl<'a> DamlExerciseByKey<'a> {
1548 pub fn new(
1549 template: Box<DamlTyConName<'a>>,
1550 choice: Cow<'a, str>,
1551 key: Box<DamlExpr<'a>>,
1552 arg: Box<DamlExpr<'a>>,
1553 ) -> Self {
1554 Self {
1555 template,
1556 choice,
1557 key,
1558 arg,
1559 }
1560 }
1561
1562 pub fn template(&self) -> &DamlTyConName<'a> {
1563 &self.template
1564 }
1565
1566 pub fn choice(&self) -> &str {
1567 &self.choice
1568 }
1569
1570 pub fn key(&self) -> &DamlExpr<'a> {
1571 self.key.as_ref()
1572 }
1573
1574 pub fn arg(&self) -> &DamlExpr<'a> {
1575 self.arg.as_ref()
1576 }
1577}
1578
1579impl<'a> DamlVisitableElement<'a> for DamlExerciseByKey<'a> {
1580 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1581 visitor.pre_visit_exercise_by_key(self);
1582 self.template.accept(visitor);
1583 self.key.accept(visitor);
1584 self.arg.accept(visitor);
1585 visitor.post_visit_exercise_by_key(self);
1586 }
1587}
1588
1589#[derive(Debug, Serialize, Clone, ToStatic)]
1591pub struct DamlFetch<'a> {
1592 template: Box<DamlTyConName<'a>>,
1593 cid: Box<DamlExpr<'a>>,
1594}
1595
1596impl<'a> DamlFetch<'a> {
1597 pub fn new(template: Box<DamlTyConName<'a>>, cid: Box<DamlExpr<'a>>) -> Self {
1598 Self {
1599 template,
1600 cid,
1601 }
1602 }
1603
1604 pub fn template(&self) -> &DamlTyConName<'a> {
1605 &self.template
1606 }
1607
1608 pub fn cid(&self) -> &DamlExpr<'a> {
1609 self.cid.as_ref()
1610 }
1611}
1612
1613impl<'a> DamlVisitableElement<'a> for DamlFetch<'a> {
1614 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1615 visitor.pre_visit_fetch(self);
1616 self.template.accept(visitor);
1617 self.cid.accept(visitor);
1618 visitor.post_visit_fetch(self);
1619 }
1620}
1621
1622#[derive(Debug, Serialize, Clone, ToStatic)]
1624pub struct DamlRetrieveByKey<'a> {
1625 template: Box<DamlTyConName<'a>>,
1626 key: Box<DamlExpr<'a>>,
1627}
1628
1629impl<'a> DamlRetrieveByKey<'a> {
1630 pub fn new(template: Box<DamlTyConName<'a>>, key: Box<DamlExpr<'a>>) -> Self {
1631 Self {
1632 template,
1633 key,
1634 }
1635 }
1636
1637 pub fn template(&self) -> &DamlTyConName<'a> {
1638 &self.template
1639 }
1640
1641 pub fn key(&self) -> &DamlExpr<'a> {
1642 self.key.as_ref()
1643 }
1644}
1645
1646impl<'a> DamlVisitableElement<'a> for DamlRetrieveByKey<'a> {
1647 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1648 visitor.pre_visit_retrieve_by_key(self);
1649 self.template.accept(visitor);
1650 self.key.accept(visitor);
1651 visitor.post_visit_retrieve_by_key(self);
1652 }
1653}
1654
1655#[derive(Debug, Serialize, Clone, ToStatic)]
1657pub struct DamlUpdateEmbedExpr<'a> {
1658 ty: DamlType<'a>,
1659 body: Box<DamlExpr<'a>>,
1660}
1661
1662impl<'a> DamlUpdateEmbedExpr<'a> {
1663 pub fn new(ty: DamlType<'a>, body: Box<DamlExpr<'a>>) -> Self {
1664 Self {
1665 ty,
1666 body,
1667 }
1668 }
1669
1670 pub fn ty(&self) -> &DamlType<'a> {
1671 &self.ty
1672 }
1673
1674 pub fn body(&self) -> &DamlExpr<'a> {
1675 self.body.as_ref()
1676 }
1677}
1678
1679impl<'a> DamlVisitableElement<'a> for DamlUpdateEmbedExpr<'a> {
1680 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1681 visitor.pre_visit_update_embed_expr(self);
1682 self.ty.accept(visitor);
1683 self.body.accept(visitor);
1684 visitor.post_visit_update_embed_expr(self);
1685 }
1686}
1687
1688#[derive(Debug, Serialize, Clone, ToStatic)]
1690pub enum DamlScenario<'a> {
1691 Pure(DamlPure<'a>),
1692 Block(DamlBlock<'a>),
1693 Commit(DamlCommit<'a>),
1694 MustFailAt(DamlCommit<'a>),
1695 Pass(Box<DamlExpr<'a>>),
1696 GetTime,
1697 GetParty(Box<DamlExpr<'a>>),
1698 EmbedExpr(DamlScenarioEmbedExpr<'a>),
1699}
1700
1701impl<'a> DamlVisitableElement<'a> for DamlScenario<'a> {
1702 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1703 visitor.pre_visit_scenario(self);
1704 match self {
1705 DamlScenario::Pure(pure) => pure.accept(visitor),
1706 DamlScenario::Block(block) => block.accept(visitor),
1707 DamlScenario::Commit(commit) | DamlScenario::MustFailAt(commit) => commit.accept(visitor),
1708 DamlScenario::Pass(expr) | DamlScenario::GetParty(expr) => expr.accept(visitor),
1709 DamlScenario::GetTime => {},
1710 DamlScenario::EmbedExpr(embed_expr) => embed_expr.accept(visitor),
1711 }
1712 visitor.post_visit_scenario(self);
1713 }
1714}
1715
1716#[derive(Debug, Serialize, Clone, ToStatic)]
1718pub struct DamlCommit<'a> {
1719 party: Box<DamlExpr<'a>>,
1720 expr: Box<DamlExpr<'a>>,
1721 ret_type: DamlType<'a>,
1722}
1723
1724impl<'a> DamlCommit<'a> {
1725 pub fn new(party: Box<DamlExpr<'a>>, expr: Box<DamlExpr<'a>>, ret_type: DamlType<'a>) -> Self {
1726 Self {
1727 party,
1728 expr,
1729 ret_type,
1730 }
1731 }
1732
1733 pub fn party(&self) -> &DamlExpr<'a> {
1734 self.party.as_ref()
1735 }
1736
1737 pub fn expr(&self) -> &DamlExpr<'a> {
1738 self.expr.as_ref()
1739 }
1740
1741 pub fn ret_type(&self) -> &DamlType<'a> {
1742 &self.ret_type
1743 }
1744}
1745
1746impl<'a> DamlVisitableElement<'a> for DamlCommit<'a> {
1747 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1748 visitor.pre_visit_commit(self);
1749 self.party.accept(visitor);
1750 self.expr.accept(visitor);
1751 self.ret_type.accept(visitor);
1752 visitor.post_visit_commit(self);
1753 }
1754}
1755
1756#[derive(Debug, Serialize, Clone, ToStatic)]
1758pub struct DamlScenarioEmbedExpr<'a> {
1759 ty: DamlType<'a>,
1760 body: Box<DamlExpr<'a>>,
1761}
1762
1763impl<'a> DamlScenarioEmbedExpr<'a> {
1764 pub fn new(ty: DamlType<'a>, body: Box<DamlExpr<'a>>) -> Self {
1765 Self {
1766 ty,
1767 body,
1768 }
1769 }
1770
1771 pub fn ty(&self) -> &DamlType<'a> {
1772 &self.ty
1773 }
1774
1775 pub fn body(&self) -> &DamlExpr<'a> {
1776 self.body.as_ref()
1777 }
1778}
1779
1780impl<'a> DamlVisitableElement<'a> for DamlScenarioEmbedExpr<'a> {
1781 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1782 visitor.pre_visit_scenario_embed_expr(self);
1783 self.ty.accept(visitor);
1784 self.body.accept(visitor);
1785 visitor.post_visit_scenario_embed_expr(self);
1786 }
1787}
1788
1789#[derive(Debug, Serialize, Clone, ToStatic)]
1791pub struct DamlToAnyException<'a> {
1792 ty: DamlType<'a>,
1793 expr: Box<DamlExpr<'a>>,
1794}
1795
1796impl<'a> DamlToAnyException<'a> {
1797 pub fn new(ty: DamlType<'a>, expr: Box<DamlExpr<'a>>) -> Self {
1798 Self {
1799 ty,
1800 expr,
1801 }
1802 }
1803
1804 pub fn ty(&self) -> &DamlType<'a> {
1805 &self.ty
1806 }
1807
1808 pub fn expr(&self) -> &DamlExpr<'a> {
1809 self.expr.as_ref()
1810 }
1811}
1812
1813impl<'a> DamlVisitableElement<'a> for DamlToAnyException<'a> {
1814 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1815 visitor.pre_visit_to_any_exception(self);
1816 self.ty.accept(visitor);
1817 self.expr.accept(visitor);
1818 visitor.post_visit_to_any_exception(self);
1819 }
1820}
1821
1822#[derive(Debug, Serialize, Clone, ToStatic)]
1824pub struct DamlFromAnyException<'a> {
1825 ty: DamlType<'a>,
1826 expr: Box<DamlExpr<'a>>,
1827}
1828
1829impl<'a> DamlFromAnyException<'a> {
1830 pub fn new(ty: DamlType<'a>, expr: Box<DamlExpr<'a>>) -> Self {
1831 Self {
1832 ty,
1833 expr,
1834 }
1835 }
1836
1837 pub fn ty(&self) -> &DamlType<'a> {
1838 &self.ty
1839 }
1840
1841 pub fn expr(&self) -> &DamlExpr<'a> {
1842 self.expr.as_ref()
1843 }
1844}
1845
1846impl<'a> DamlVisitableElement<'a> for DamlFromAnyException<'a> {
1847 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1848 visitor.pre_visit_from_any_exception(self);
1849 self.ty.accept(visitor);
1850 self.expr.accept(visitor);
1851 visitor.post_visit_from_any_exception(self);
1852 }
1853}
1854
1855#[derive(Debug, Serialize, Clone, ToStatic)]
1857pub struct DamlThrow<'a> {
1858 return_type: DamlType<'a>,
1859 exception_type: DamlType<'a>,
1860 exception_expr: Box<DamlExpr<'a>>,
1861}
1862
1863impl<'a> DamlThrow<'a> {
1864 pub fn new(return_type: DamlType<'a>, exception_type: DamlType<'a>, exception_expr: Box<DamlExpr<'a>>) -> Self {
1865 Self {
1866 return_type,
1867 exception_type,
1868 exception_expr,
1869 }
1870 }
1871
1872 pub fn return_type(&self) -> &DamlType<'a> {
1873 &self.return_type
1874 }
1875
1876 pub fn exception_type(&self) -> &DamlType<'a> {
1877 &self.exception_type
1878 }
1879
1880 pub fn exception_expr(&self) -> &DamlExpr<'a> {
1881 self.exception_expr.as_ref()
1882 }
1883}
1884
1885impl<'a> DamlVisitableElement<'a> for DamlThrow<'a> {
1886 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1887 visitor.pre_visit_throw(self);
1888 self.return_type.accept(visitor);
1889 self.exception_type.accept(visitor);
1890 self.exception_expr.accept(visitor);
1891 visitor.post_visit_throw(self);
1892 }
1893}
1894
1895#[derive(Debug, Serialize, Clone, ToStatic)]
1897pub struct DamlTryCatch<'a> {
1898 return_type: DamlType<'a>,
1899 try_expr: Box<DamlExpr<'a>>,
1900 var: Cow<'a, str>,
1901 catch_expr: Box<DamlExpr<'a>>,
1902}
1903
1904impl<'a> DamlTryCatch<'a> {
1905 pub fn new(
1906 return_type: DamlType<'a>,
1907 try_expr: Box<DamlExpr<'a>>,
1908 var: Cow<'a, str>,
1909 catch_expr: Box<DamlExpr<'a>>,
1910 ) -> Self {
1911 Self {
1912 return_type,
1913 try_expr,
1914 var,
1915 catch_expr,
1916 }
1917 }
1918
1919 pub fn return_type(&self) -> &DamlType<'a> {
1920 &self.return_type
1921 }
1922
1923 pub fn try_expr(&self) -> &DamlExpr<'a> {
1924 self.try_expr.as_ref()
1925 }
1926
1927 pub fn var(&self) -> &str {
1928 &self.var
1929 }
1930
1931 pub fn catch_expr(&self) -> &DamlExpr<'a> {
1932 self.catch_expr.as_ref()
1933 }
1934}
1935
1936impl<'a> DamlVisitableElement<'a> for DamlTryCatch<'a> {
1937 fn accept(&'a self, visitor: &'a mut impl DamlElementVisitor) {
1938 visitor.pre_visit_try_catch(self);
1939 self.return_type.accept(visitor);
1940 self.try_expr.accept(visitor);
1941 self.catch_expr.accept(visitor);
1942 visitor.post_visit_try_catch(self);
1943 }
1944}