@@ -29,7 +29,6 @@ pub enum SyntaxBindingErrorType {
29
29
Let ,
30
30
Eval ,
31
31
TupleCons ,
32
- TypeDefinition ,
33
32
}
34
33
35
34
impl fmt:: Display for SyntaxBindingErrorType {
@@ -44,7 +43,6 @@ impl DiagnosableError for SyntaxBindingErrorType {
44
43
Self :: Let => "Let-binding" . to_string ( ) ,
45
44
Self :: Eval => "Function argument definition" . to_string ( ) ,
46
45
Self :: TupleCons => "Tuple constructor" . to_string ( ) ,
47
- Self :: TypeDefinition => "Type definition" . to_string ( ) ,
48
46
}
49
47
}
50
48
@@ -57,16 +55,11 @@ impl DiagnosableError for SyntaxBindingErrorType {
57
55
#[ derive( Debug , PartialEq ) ]
58
56
pub enum SyntaxBindingError {
59
57
/// binding list item is not a list
60
- NotList ( SyntaxBindingErrorType , usize , SymbolicExpression ) ,
58
+ NotList ( SyntaxBindingErrorType , usize ) ,
61
59
/// binding list item has an invalid length (e.g. not 2)
62
- InvalidLength ( SyntaxBindingErrorType , usize , SymbolicExpression ) ,
60
+ InvalidLength ( SyntaxBindingErrorType , usize ) ,
63
61
/// binding name is not an atom
64
- NotAtom ( SyntaxBindingErrorType , usize , SymbolicExpression ) ,
65
- /// second binding item is a type signature, and the type signature itself is bad.
66
- /// NOTE: type signature parsing returns CheckErrors, so we cannot include a CheckErrors here
67
- /// directly without creating a recursive type. Instead, we just report the `Display`
68
- /// representation of the error here as the third item.
69
- BadTypeSignature ( usize , SymbolicExpression , String ) ,
62
+ NotAtom ( SyntaxBindingErrorType , usize ) ,
70
63
}
71
64
72
65
impl fmt:: Display for SyntaxBindingError {
@@ -78,30 +71,17 @@ impl fmt::Display for SyntaxBindingError {
78
71
impl DiagnosableError for SyntaxBindingError {
79
72
fn message ( & self ) -> String {
80
73
match & self {
81
- Self :: NotList ( err_type, item_index, item ) => {
74
+ Self :: NotList ( err_type, item_index) => {
82
75
let item_no = item_index + 1 ;
83
- format ! (
84
- "{err_type} item #{item_no} is not a list: {}" ,
85
- item. as_error_string( )
86
- )
76
+ format ! ( "{err_type} item #{item_no} is not a list" , )
87
77
}
88
- Self :: InvalidLength ( err_type, item_index, item ) => {
78
+ Self :: InvalidLength ( err_type, item_index) => {
89
79
let item_no = item_index + 1 ;
90
- format ! (
91
- "{err_type} item #{item_no} is not a two-element list: {}" ,
92
- item. as_error_string( )
93
- )
80
+ format ! ( "{err_type} item #{item_no} is not a two-element list" , )
94
81
}
95
- Self :: NotAtom ( err_type, item_index, item ) => {
82
+ Self :: NotAtom ( err_type, item_index) => {
96
83
let item_no = item_index + 1 ;
97
- format ! (
98
- "{err_type} item #{item_no}'s name is not an atom: {}" ,
99
- item. as_error_string( )
100
- )
101
- }
102
- Self :: BadTypeSignature ( item_index, item, error_message) => {
103
- let item_no = item_index + 1 ;
104
- format ! ( "Type definition item #{item_no} has an invalid type signature: {} (reason: {error_message})" , item. as_error_string( ) )
84
+ format ! ( "{err_type} item #{item_no}'s name is not an atom" , )
105
85
}
106
86
}
107
87
}
@@ -112,49 +92,55 @@ impl DiagnosableError for SyntaxBindingError {
112
92
}
113
93
114
94
impl SyntaxBindingError {
115
- /// Helper constructor for NotList(SyntaxBindingErrorType::Let, item_no, item)
116
- pub fn let_binding_not_list ( item_no : usize , item : SymbolicExpression ) -> Self {
117
- Self :: NotList ( SyntaxBindingErrorType :: Let , item_no, item)
95
+ /// Helper constructor for NotList(SyntaxBindingErrorType::Let, item_no)
96
+ pub fn let_binding_not_list ( item_no : usize ) -> Self {
97
+ Self :: NotList ( SyntaxBindingErrorType :: Let , item_no)
98
+ }
99
+
100
+ /// Helper constructor for InvalidLength(SyntaxBindingErrorType::Let, item_no)
101
+ pub fn let_binding_invalid_length ( item_no : usize ) -> Self {
102
+ Self :: InvalidLength ( SyntaxBindingErrorType :: Let , item_no)
118
103
}
119
104
120
- /// Helper constructor for InvalidLength (SyntaxBindingErrorType::Let, item_no, item )
121
- pub fn let_binding_invalid_length ( item_no : usize , item : SymbolicExpression ) -> Self {
122
- Self :: InvalidLength ( SyntaxBindingErrorType :: Let , item_no, item )
105
+ /// Helper constructor for NotAtom (SyntaxBindingErrorType::Let, item_no)
106
+ pub fn let_binding_not_atom ( item_no : usize ) -> Self {
107
+ Self :: NotAtom ( SyntaxBindingErrorType :: Let , item_no)
123
108
}
124
109
125
- /// Helper constructor for NotAtom (SyntaxBindingErrorType::Let , item_no, item )
126
- pub fn let_binding_not_atom ( item_no : usize , item : SymbolicExpression ) -> Self {
127
- Self :: NotAtom ( SyntaxBindingErrorType :: Let , item_no, item )
110
+ /// Helper constructor for NotList (SyntaxBindingErrorType::Eval , item_no)
111
+ pub fn eval_binding_not_list ( item_no : usize ) -> Self {
112
+ Self :: NotList ( SyntaxBindingErrorType :: Eval , item_no)
128
113
}
129
114
130
- /// Helper constructor for NotList (SyntaxBindingErrorType::Eval, item_no, item )
131
- pub fn eval_binding_not_list ( item_no : usize , item : SymbolicExpression ) -> Self {
132
- Self :: NotList ( SyntaxBindingErrorType :: Eval , item_no, item )
115
+ /// Helper constructor for InvalidLength (SyntaxBindingErrorType::Eval, item_no)
116
+ pub fn eval_binding_invalid_length ( item_no : usize ) -> Self {
117
+ Self :: InvalidLength ( SyntaxBindingErrorType :: Eval , item_no)
133
118
}
134
119
135
- /// Helper constructor for InvalidLength (SyntaxBindingErrorType::Eval, item_no, item )
136
- pub fn eval_binding_invalid_length ( item_no : usize , item : SymbolicExpression ) -> Self {
137
- Self :: InvalidLength ( SyntaxBindingErrorType :: Eval , item_no, item )
120
+ /// Helper constructor for NotAtom (SyntaxBindingErrorType::Eval, item_no)
121
+ pub fn eval_binding_not_atom ( item_no : usize ) -> Self {
122
+ Self :: NotAtom ( SyntaxBindingErrorType :: Eval , item_no)
138
123
}
139
124
140
- /// Helper constructor for NotAtom (SyntaxBindingErrorType::Eval , item_no, item )
141
- pub fn eval_binding_not_atom ( item_no : usize , item : SymbolicExpression ) -> Self {
142
- Self :: NotAtom ( SyntaxBindingErrorType :: Eval , item_no, item )
125
+ /// Helper constructor for NotList (SyntaxBindingErrorType::TupleCons , item_no)
126
+ pub fn tuple_cons_not_list ( item_no : usize ) -> Self {
127
+ Self :: NotList ( SyntaxBindingErrorType :: TupleCons , item_no)
143
128
}
144
129
145
- /// Helper constructor for NotList (SyntaxBindingErrorType::TupleCons, item_no, item )
146
- pub fn tuple_cons_not_list ( item_no : usize , item : SymbolicExpression ) -> Self {
147
- Self :: NotList ( SyntaxBindingErrorType :: TupleCons , item_no, item )
130
+ /// Helper constructor for InvalidLength (SyntaxBindingErrorType::TupleCons, item_no)
131
+ pub fn tuple_cons_invalid_length ( item_no : usize ) -> Self {
132
+ Self :: InvalidLength ( SyntaxBindingErrorType :: TupleCons , item_no)
148
133
}
149
134
150
- /// Helper constructor for InvalidLength (SyntaxBindingErrorType::TupleCons, item_no, item )
151
- pub fn tuple_cons_invalid_length ( item_no : usize , item : SymbolicExpression ) -> Self {
152
- Self :: InvalidLength ( SyntaxBindingErrorType :: TupleCons , item_no, item )
135
+ /// Helper constructor for NotAtom (SyntaxBindingErrorType::TupleCons, item_no)
136
+ pub fn tuple_cons_not_atom ( item_no : usize ) -> Self {
137
+ Self :: NotAtom ( SyntaxBindingErrorType :: TupleCons , item_no)
153
138
}
139
+ }
154
140
155
- /// Helper constructor for NotAtom(SyntaxBindingErrorType::TupleCons, item_no, item)
156
- pub fn tuple_cons_not_atom ( item_no : usize , item : SymbolicExpression ) -> Self {
157
- Self :: NotAtom ( SyntaxBindingErrorType :: TupleCons , item_no , item )
141
+ impl From < SyntaxBindingError > for CheckErrors {
142
+ fn from ( e : SyntaxBindingError ) -> Self {
143
+ Self :: BadSyntaxBinding ( e )
158
144
}
159
145
}
160
146
@@ -348,11 +334,6 @@ impl CheckErrors {
348
334
CheckErrors :: SupertypeTooLarge | CheckErrors :: Expects ( _)
349
335
)
350
336
}
351
-
352
- /// Is the given error message due to a BadSyntaxBinding?
353
- pub fn has_nested_bad_syntax_binding_message ( msg : & str ) -> bool {
354
- msg. contains ( "invalid syntax binding: " )
355
- }
356
337
}
357
338
358
339
impl CheckError {
@@ -378,6 +359,18 @@ impl CheckError {
378
359
self . diagnostic . spans = exprs. iter ( ) . map ( |e| e. span ( ) . clone ( ) ) . collect ( ) ;
379
360
self . expressions . replace ( exprs. to_vec ( ) ) ;
380
361
}
362
+
363
+ pub fn with_expression ( err : CheckErrors , expr : & SymbolicExpression ) -> Self {
364
+ let mut r = Self :: new ( err) ;
365
+ r. set_expression ( expr) ;
366
+ r
367
+ }
368
+ }
369
+
370
+ impl From < ( SyntaxBindingError , & SymbolicExpression ) > for CheckError {
371
+ fn from ( e : ( SyntaxBindingError , & SymbolicExpression ) ) -> Self {
372
+ Self :: with_expression ( CheckErrors :: BadSyntaxBinding ( e. 0 ) , e. 1 )
373
+ }
381
374
}
382
375
383
376
impl fmt:: Display for CheckErrors {
0 commit comments