1
+ use indexmap:: IndexMap ;
1
2
use serde:: { Deserialize , Serialize } ;
2
3
use std:: fmt;
4
+ use std:: hash:: { Hash , Hasher } ;
3
5
4
6
derive_alias ! {
5
7
#[ derive( CommonTraits !) ] = #[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ] ;
@@ -53,7 +55,7 @@ impl NodeData {
53
55
54
56
impl fmt:: Debug for NodeData {
55
57
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
56
- write ! ( f, "( id: {:?}, span: {:?}) " , self . id, self . span)
58
+ write ! ( f, "NodeData {{ id: {:?}, span: {:?}}} " , self . id, self . span)
57
59
}
58
60
}
59
61
@@ -62,11 +64,11 @@ impl fmt::Debug for NodeData {
62
64
#[ derive( CommonTraits !, Default ) ]
63
65
pub struct StoredDefinition {
64
66
pub node_data : NodeData ,
65
- pub classes : Vec < ClassDefinition > ,
66
67
pub within : Option < Name > ,
67
68
pub model_md5 : String ,
68
69
pub rumoca_parser_version : String ,
69
70
pub rumoca_parser_git : String ,
71
+ pub classes : IndexMap < String , ClassDefinition > ,
70
72
}
71
73
72
74
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -109,7 +111,18 @@ pub struct ClassDefinition {
109
111
pub flags : ClassFlags ,
110
112
pub modification : Vec < Argument > ,
111
113
pub description : DescriptionString ,
112
- pub composition : Vec < CompositionPart > ,
114
+ //pub composition: Vec<CompositionPart>,
115
+ pub components : IndexMap < String , ComponentDeclaration > ,
116
+ pub equations : Vec < Equation > ,
117
+ pub algorithms : Vec < Vec < Statement > > ,
118
+ pub initial_equations : Vec < Equation > ,
119
+ pub initial_algorithms : Vec < Vec < Statement > > ,
120
+ }
121
+
122
+ impl Hash for ClassDefinition {
123
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
124
+ self . node_data . id . hash ( state) ;
125
+ }
113
126
}
114
127
115
128
#[ derive( CommonTraits !, Default ) ]
@@ -399,15 +412,15 @@ pub struct StatementIfBlock {
399
412
pub enum Expression {
400
413
#[ default]
401
414
Empty ,
402
- Array ( ExpressionArray ) ,
403
- Binary ( ExpressionBinary ) ,
404
- Boolean ( ExpressionBoolean ) ,
415
+ Array ( Array ) ,
416
+ Binary ( Binary ) ,
417
+ Boolean ( Boolean ) ,
405
418
FunctionCall ( FunctionCall ) ,
406
419
If ( ExpressionIf ) ,
407
420
Ref ( ComponentReference ) ,
408
- Unary ( ExpressionUnary ) ,
409
- UnsignedInteger ( ExpressionUnsignedInteger ) ,
410
- UnsignedReal ( ExpressionUnsignedReal ) ,
421
+ Unary ( Unary ) ,
422
+ UnsignedInteger ( UnsignedInteger ) ,
423
+ UnsignedReal ( UnsignedReal ) ,
411
424
}
412
425
413
426
impl_debug_for_enum ! ( Expression {
@@ -423,20 +436,20 @@ impl_debug_for_enum!(Expression {
423
436
} ) ;
424
437
425
438
#[ derive( CommonTraits !, Default ) ]
426
- pub struct ExpressionArray {
439
+ pub struct Array {
427
440
pub node_data : NodeData ,
428
441
pub args : Vec < Expression > ,
429
442
}
430
443
431
444
#[ derive( CommonTraits !, Default ) ]
432
- pub struct ExpressionUnary {
445
+ pub struct Unary {
433
446
pub node_data : NodeData ,
434
447
pub op : UnaryOp ,
435
448
pub rhs : Box < Expression > ,
436
449
}
437
450
438
451
#[ derive( CommonTraits !, Default ) ]
439
- pub struct ExpressionBinary {
452
+ pub struct Binary {
440
453
pub node_data : NodeData ,
441
454
pub op : BinaryOp ,
442
455
pub lhs : Box < Expression > ,
@@ -465,19 +478,19 @@ pub struct ExpressionIfBlock {
465
478
}
466
479
467
480
#[ derive( CommonTraits !, Default ) ]
468
- pub struct ExpressionUnsignedInteger {
481
+ pub struct UnsignedInteger {
469
482
pub node_data : NodeData ,
470
483
pub val : String ,
471
484
}
472
485
473
486
#[ derive( CommonTraits !, Default ) ]
474
- pub struct ExpressionUnsignedReal {
487
+ pub struct UnsignedReal {
475
488
pub node_data : NodeData ,
476
489
pub val : String ,
477
490
}
478
491
479
492
#[ derive( CommonTraits !, Default ) ]
480
- pub struct ExpressionBoolean {
493
+ pub struct Boolean {
481
494
pub node_data : NodeData ,
482
495
pub val : bool ,
483
496
}
@@ -494,15 +507,16 @@ impl fmt::Debug for ComponentReference {
494
507
let parts = self
495
508
. parts
496
509
. iter ( )
497
- . map ( |part| format ! ( "{:# ?}" , part) )
510
+ . map ( |part| format ! ( "{:?}" , part) )
498
511
. collect :: < Vec < _ > > ( )
499
512
. join ( "." ) ;
500
513
write ! (
501
514
f,
502
- "ComponentReference({ }{}: {:#?}) " ,
515
+ "ComponentReference {{{ }{}, id : {}, span: {:?}}} " ,
503
516
if self . local { "." } else { "" } ,
504
517
parts,
505
- self . node_data,
518
+ self . node_data. id,
519
+ self . node_data. span,
506
520
)
507
521
}
508
522
}
@@ -517,9 +531,9 @@ pub struct RefPart {
517
531
impl fmt:: Debug for RefPart {
518
532
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
519
533
if self . array_subscripts . is_empty ( ) {
520
- write ! ( f, "{:# ?}" , self . name)
534
+ write ! ( f, "{:?}" , self . name)
521
535
} else {
522
- write ! ( f, "{:# ?}{:?}" , self . name, self . array_subscripts)
536
+ write ! ( f, "{:?}{:?}" , self . name, self . array_subscripts)
523
537
}
524
538
}
525
539
}
@@ -612,13 +626,19 @@ pub struct ModExprBreak {
612
626
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
613
627
// Common
614
628
615
- #[ derive( CommonTraits ! , Default ) ]
629
+ #[ derive( Clone , PartialEq , Eq , Serialize , Deserialize , Default ) ]
616
630
pub struct Description {
617
631
pub node_data : NodeData ,
618
632
pub strings : Vec < String > ,
619
633
pub annotation : Vec < Argument > ,
620
634
}
621
635
636
+ impl fmt:: Debug for Description {
637
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
638
+ write ! ( f, "{} {:?}" , self . strings. join( " " ) , self . annotation)
639
+ }
640
+ }
641
+
622
642
#[ derive( CommonTraits !, Default ) ]
623
643
pub struct TypePrefix {
624
644
pub connection : Connection ,
@@ -754,7 +774,16 @@ pub enum ClassType {
754
774
Type ,
755
775
}
756
776
757
- pub type DescriptionString = Vec < String > ;
777
+ #[ derive( Clone , PartialEq , Eq , Serialize , Deserialize , Default ) ]
778
+ pub struct DescriptionString {
779
+ pub parts : Vec < String > ,
780
+ }
781
+
782
+ impl fmt:: Debug for DescriptionString {
783
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
784
+ write ! ( f, "{}" , self . parts. join( " " ) )
785
+ }
786
+ }
758
787
759
788
#[ derive( Clone , PartialEq , Eq , Serialize , Deserialize , Default ) ]
760
789
pub struct Name {
@@ -766,21 +795,3 @@ impl fmt::Debug for Name {
766
795
write ! ( f, "{}" , self . parts. join( "." ) )
767
796
}
768
797
}
769
-
770
- // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
771
- // Unit Testing
772
- #[ cfg( test) ]
773
- mod tests {
774
- use super :: * ;
775
-
776
- #[ test]
777
- fn test_ast ( ) {
778
- let mut def = StoredDefinition :: default ( ) ;
779
-
780
- // class ball
781
- let class_ball = ClassDefinition {
782
- ..Default :: default ( )
783
- } ;
784
- def. classes . push ( class_ball) ;
785
- }
786
- }
0 commit comments