@@ -25,7 +25,7 @@ fn index_declaration(state: &mut IndexState, declaration: cst::Declaration) {
2525 match declaration {
2626 cst:: Declaration :: ValueSignature ( s) => index_value_signature ( state, s) ,
2727 cst:: Declaration :: ValueEquation ( e) => index_value_equation ( state, e) ,
28- cst:: Declaration :: InfixDeclaration ( _ ) => todo ! ( ) ,
28+ cst:: Declaration :: InfixDeclaration ( i ) => index_infix ( state , i ) ,
2929 cst:: Declaration :: TypeRoleDeclaration ( r) => index_type_role ( state, r) ,
3030 cst:: Declaration :: ClassSignature ( s) => index_class_signature ( state, s) ,
3131 cst:: Declaration :: ClassDeclaration ( d) => index_class_declaration ( state, d) ,
@@ -97,6 +97,35 @@ fn index_value_equation(state: &mut IndexState, equation: cst::ValueEquation) {
9797 }
9898}
9999
100+ fn index_infix ( state : & mut IndexState , infix : cst:: InfixDeclaration ) {
101+ let type_token = infix. type_token ( ) ;
102+ let operator_token = infix. operator_token ( ) ;
103+
104+ let declaration = cst:: Declaration :: InfixDeclaration ( infix) ;
105+ let declaration_id = state. source_map . insert_declaration ( & declaration) ;
106+
107+ let Some ( operator_token) = operator_token else { return } ;
108+ let operator = operator_token. text ( ) ;
109+
110+ if type_token. is_none ( ) {
111+ if let Some ( ( _, item_id) ) = state. nominal . expr_get_mut ( operator) {
112+ let duplicate = Duplicate :: Declaration ( declaration_id) ;
113+ state. errors . push ( IndexingError :: DuplicateExprItem { item_id, duplicate } ) ;
114+ } else {
115+ let operator: SmolStr = operator. into ( ) ;
116+ state. nominal . insert_expr ( operator, ExprItem :: Operator ( declaration_id) ) ;
117+ }
118+ } else {
119+ if let Some ( ( _, item_id) ) = state. nominal . type_get_mut ( operator) {
120+ let duplicate = Duplicate :: Declaration ( declaration_id) ;
121+ state. errors . push ( IndexingError :: DuplicateTypeItem { item_id, duplicate } ) ;
122+ } else {
123+ let operator: SmolStr = operator. into ( ) ;
124+ state. nominal . insert_type ( operator, TypeItem :: Operator ( declaration_id) ) ;
125+ }
126+ }
127+ }
128+
100129fn index_type_role ( state : & mut IndexState , role : cst:: TypeRoleDeclaration ) {
101130 let name_token = role. name_token ( ) ;
102131
@@ -108,7 +137,7 @@ fn index_type_role(state: &mut IndexState, role: cst::TypeRoleDeclaration) {
108137
109138 if let Some ( ( item, item_id) ) = state. nominal . type_get_mut ( name) {
110139 match item {
111- TypeItem :: Class ( _) | TypeItem :: Synonym ( _) => {
140+ TypeItem :: Class ( _) | TypeItem :: Synonym ( _) | TypeItem :: Operator ( _ ) => {
112141 state. errors . push ( IndexingError :: InvalidRoleDeclaration {
113142 item_id : Some ( item_id) ,
114143 declaration : declaration_id,
0 commit comments