@@ -4,12 +4,16 @@ mod conversions;
44pub mod node;
55mod traits;
66pub mod unary;
7+
78use core:: fmt;
89
910use node:: Ast ;
1011use traits:: { Associativity , Operator } ;
1112
13+ use super :: keyword:: types:: attributes:: AttributeKeyword ;
14+ use super :: keyword:: types:: functions:: FunctionKeyword ;
1215use crate :: lexer:: api:: Number ;
16+ use crate :: EMPTY ;
1317
1418#[ derive( Debug , PartialEq ) ]
1519pub struct CompoundLiteral {
@@ -43,8 +47,9 @@ impl Operator for CompoundLiteralOperator {
4347pub struct FunctionCall {
4448 args : Vec < Ast > ,
4549 full : bool ,
46- name : String ,
50+ name : VariableName ,
4751 op : FunctionOperator ,
52+ return_attrs : Vec < AttributeKeyword > ,
4853}
4954
5055#[ expect( clippy:: min_ident_chars) ]
@@ -94,28 +99,28 @@ impl fmt::Display for ListInitialiser {
9499 }
95100}
96101
97- #[ derive( Debug , PartialEq , Default ) ]
102+ #[ derive( Debug , PartialEq ) ]
98103pub enum Literal {
99104 Char ( char ) ,
100105 ConstantBool ( bool ) ,
101- #[ default]
102106 Empty ,
103107 Nullptr ,
104108 Number ( Number ) ,
105109 Str ( String ) ,
106- Variable ( String ) ,
110+ Variable ( Variable ) ,
107111}
108112
109113#[ expect( clippy:: min_ident_chars) ]
110114impl fmt:: Display for Literal {
111115 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
112116 match self {
113- Self :: Empty => " \u{2205} " . fmt ( f) ,
117+ Self :: Empty => EMPTY . fmt ( f) ,
114118 Self :: Nullptr => "NULL" . fmt ( f) ,
115119 Self :: Char ( val) => val. fmt ( f) ,
120+ Self :: Str ( val) => val. fmt ( f) ,
116121 Self :: Number ( val) => val. fmt ( f) ,
117122 Self :: ConstantBool ( val) => val. fmt ( f) ,
118- Self :: Variable ( val) | Self :: Str ( val ) => val. fmt ( f) ,
123+ Self :: Variable ( val) => val. fmt ( f) ,
119124 }
120125 }
121126}
@@ -161,9 +166,78 @@ impl fmt::Display for TernaryOperator {
161166 }
162167}
163168
169+ #[ derive( Debug , PartialEq , Eq ) ]
170+ pub struct Variable {
171+ attrs : Vec < AttributeKeyword > ,
172+ name : VariableName ,
173+ }
174+
175+ impl Variable {
176+ pub const fn from_keyword ( keyword : FunctionKeyword ) -> Self {
177+ Self {
178+ name : VariableName :: Keyword ( keyword) ,
179+ attrs : vec ! [ ] ,
180+ }
181+ }
182+ }
183+
184+ impl From < String > for Variable {
185+ fn from ( name : String ) -> Self {
186+ Self {
187+ name : VariableName :: UserDefined ( name) ,
188+ attrs : vec ! [ ] ,
189+ }
190+ }
191+ }
192+
193+ #[ expect( clippy:: min_ident_chars) ]
194+ impl fmt:: Display for Variable {
195+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
196+ if self . attrs . is_empty ( ) {
197+ self . name . fmt ( f)
198+ } else {
199+ write ! (
200+ f,
201+ "({} {})" ,
202+ self . attrs
203+ . iter( )
204+ . map( |attr| format!( "{attr}" ) )
205+ . collect:: <Vec <_>>( )
206+ . join( " " ) ,
207+ self . name
208+ )
209+ }
210+ }
211+ }
212+
213+ #[ derive( Debug , PartialEq , Eq , Default ) ]
214+ enum VariableName {
215+ #[ default]
216+ Empty ,
217+ Keyword ( FunctionKeyword ) ,
218+ UserDefined ( String ) ,
219+ }
220+
221+ impl From < & str > for VariableName {
222+ fn from ( name : & str ) -> Self {
223+ Self :: UserDefined ( name. to_owned ( ) )
224+ }
225+ }
226+
227+ #[ expect( clippy:: min_ident_chars) ]
228+ impl fmt:: Display for VariableName {
229+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
230+ match self {
231+ Self :: Empty => EMPTY . fmt ( f) ,
232+ Self :: UserDefined ( val) => val. fmt ( f) ,
233+ Self :: Keyword ( val) => val. fmt ( f) ,
234+ }
235+ }
236+ }
237+
164238#[ expect( clippy:: borrowed_box) ]
165239fn repr_option_node ( opt : Option < & Box < Ast > > ) -> String {
166- opt. map_or_else ( || " \u{2205} " . to_owned ( ) , Box :: < Ast > :: to_string)
240+ opt. map_or_else ( || EMPTY . to_owned ( ) , Box :: < Ast > :: to_string)
167241}
168242
169243fn repr_vec_node ( vec : & [ Ast ] ) -> String {
0 commit comments