@@ -20,17 +20,18 @@ pub(all) enum Edn {
2020 Buffer (EdnBufferView )
2121 /// reference to Rust data, not interpretable in Calcit
2222 // AnyRef(EdnAnyRef)
23+ Atom (Edn )
2324} derive (Eq , Hash , Default )
2425
2526///|
2627pub fn to_string (self : Edn ) -> String {
2728 match self {
28- Edn :: Nil => "nil" .to_string ()
29- Edn :: Tag (t ) => t .to_string ()
30- Edn :: Bool (b ) => if b { "true" } else { "false" }
31- Edn :: Number (n ) => n .to_string ()
32- Edn :: Symbol (s ) => s
33- Edn :: Str (s ) =>
29+ Nil => "nil" .to_string ()
30+ Tag (t ) => t .to_string ()
31+ Bool (b ) => if b { "true" } else { "false" }
32+ Number (n ) => n .to_string ()
33+ Symbol (s ) => s
34+ Str (s ) =>
3435 if is_simple_token (s ) {
3536 s
3637 } else {
@@ -44,60 +45,69 @@ pub fn to_string(self : Edn) -> String {
4445 }
4546 ret
4647 }
47- Edn ::Quote (e ) => e .to_string ()
48- Edn ::Buffer (b ) => b .to_string ()
49- Edn ::Tuple (t ) => t .to_string ()
50- Edn ::List (l ) => l .to_string ()
51- Edn ::Set (s ) => s .to_string ()
52- Edn ::Map (m ) => m .to_string ()
53- Edn ::Record (r ) => r .to_string ()
48+ Quote (e ) => e .to_string ()
49+ Buffer (b ) => b .to_string ()
50+ Tuple (t ) => t .to_string ()
51+ List (l ) => l .to_string ()
52+ Set (s ) => s .to_string ()
53+ Map (m ) => m .to_string ()
54+ Record (r ) => r .to_string ()
55+ Atom (a ) => "atom " + a .to_string ()
5456 }
5557}
5658
59+ ///|
60+ pub impl Show for Edn with output (self , logger ) -> Unit {
61+ logger .write_string (self .to_string ())
62+ }
63+
5764// TODO Hash
5865
5966///|
6067pub fn compare (self : Edn , right : Edn ) -> Int {
6168 let ret = match (self , right ) {
62- (Edn ::Nil , Edn ::Nil ) => 0
63- (Edn ::Nil , _ ) => - 1
64- (_ , Edn ::Nil ) => 1
65- (Edn ::Bool (a ), Edn ::Bool (b )) => a .compare (b )
66- (Edn ::Bool (_ ), _ ) => - 1
67- (_ , Edn ::Bool (_ )) => 1
68- (Edn ::Number (a ), Edn ::Number (b )) => a .compare (b )
69- (Edn ::Number (_ ), _ ) => - 1
70- (_ , Edn ::Number (_ )) => 1
71- (Edn ::Symbol (a ), Edn ::Symbol (b )) => a .compare (b )
72- (Edn ::Symbol (_ ), _ ) => - 1
73- (_ , Edn ::Symbol (_ )) => 1
74- (Edn ::Tag (a ), Edn ::Tag (b )) => a .compare (b )
75- (Edn ::Tag (_ ), _ ) => - 1
76- (_ , Edn ::Tag (_ )) => 1
77- (Edn ::Str (a ), Edn ::Str (b )) => a .compare (b )
78- (Edn ::Str (_ ), _ ) => - 1
79- (_ , Edn ::Str (_ )) => 1
80- (Edn ::Quote (a ), Edn ::Quote (b )) => a .compare (b )
81- (Edn ::Quote (_ ), _ ) => - 1
82- (_ , Edn ::Quote (_ )) => 1
83- (Edn ::Tuple (a ), Edn ::Tuple (b )) => a .compare (b )
84- (Edn ::Tuple (_ ), _ ) => - 1
85- (_ , Edn ::Tuple (_ )) => 1
86- (Edn ::List (a ), Edn ::List (b )) => a .compare (b )
87- (Edn ::List (_ ), _ ) => - 1
88- (_ , Edn ::List (_ )) => 1
89- (Edn ::Buffer (a ), Edn ::Buffer (b )) => a .compare (b )
90- (Edn ::Buffer (_ ), _ ) => - 1
91- (_ , Edn ::Buffer (_ )) => 1
92- (Edn ::Set (a ), Edn ::Set (b )) => a .compare (b )
93- (Edn ::Set (_ ), _ ) => - 1
94- (_ , Edn ::Set (_ )) => 1
95- (Edn ::Map (a ), Edn ::Map (b )) => a .compare (b )
96- (Edn ::Map (_ ), _ ) => - 1
97- (_ , Edn ::Map (_ )) => 1
98- (Edn ::Record (a ), Edn ::Record (b )) => a .compare (b )
99- // (Edn::Record(_), _) => -1
100- // (_, Edn::Record(_)) => 1
69+ (Nil , Nil ) => 0
70+ (Nil , _ ) => - 1
71+ (_ , Nil ) => 1
72+ (Bool (a ), Bool (b )) => a .compare (b )
73+ (Bool (_ ), _ ) => - 1
74+ (_ , Bool (_ )) => 1
75+ (Number (a ), Number (b )) => a .compare (b )
76+ (Number (_ ), _ ) => - 1
77+ (_ , Number (_ )) => 1
78+ (Symbol (a ), Symbol (b )) => a .compare (b )
79+ (Symbol (_ ), _ ) => - 1
80+ (_ , Symbol (_ )) => 1
81+ (Tag (a ), Tag (b )) => a .compare (b )
82+ (Tag (_ ), _ ) => - 1
83+ (_ , Tag (_ )) => 1
84+ (Str (a ), Str (b )) => a .compare (b )
85+ (Str (_ ), _ ) => - 1
86+ (_ , Str (_ )) => 1
87+ (Quote (a ), Quote (b )) => a .compare (b )
88+ (Quote (_ ), _ ) => - 1
89+ (_ , Quote (_ )) => 1
90+ (Tuple (a ), Tuple (b )) => a .compare (b )
91+ (Tuple (_ ), _ ) => - 1
92+ (_ , Tuple (_ )) => 1
93+ (List (a ), List (b )) => a .compare (b )
94+ (List (_ ), _ ) => - 1
95+ (_ , List (_ )) => 1
96+ (Buffer (a ), Buffer (b )) => a .compare (b )
97+ (Buffer (_ ), _ ) => - 1
98+ (_ , Buffer (_ )) => 1
99+ (Set (a ), Set (b )) => a .compare (b )
100+ (Set (_ ), _ ) => - 1
101+ (_ , Set (_ )) => 1
102+ (Map (a ), Map (b )) => a .compare (b )
103+ (Map (_ ), _ ) => - 1
104+ (_ , Map (_ )) => 1
105+ (Atom (a ), Atom (b )) => a .compare (b )
106+ (Atom (_ ), _ ) => - 1
107+ (_ , Atom (_ )) => 1
108+ (Record (a ), Record (b )) => a .compare (b )
109+ // (Record(_), _) => -1
110+ // (_, Record(_)) => 1
101111 }
102112 ret
103113}
@@ -127,12 +137,12 @@ pub fn Edn::tuple(tag : Edn, extra : Array[Edn]) -> Edn {
127137///|
128138pub fn Edn ::is_literal (self : Edn ) -> Bool {
129139 match self {
130- Edn :: Nil => true
131- Edn :: Bool (_ ) => true
132- Edn :: Number (_ ) => true
133- Edn :: Symbol (_ ) => true
134- Edn :: Str (_ ) => true
135- Edn :: Tag (_ ) => true
140+ Nil => true
141+ Bool (_ ) => true
142+ Number (_ ) => true
143+ Symbol (_ ) => true
144+ Str (_ ) => true
145+ Tag (_ ) => true
136146 _ => false
137147 }
138148}
0 commit comments