22
33//! Parsing Errors
44
5- use santiago:: lexer:: Lexeme ;
65use std:: collections:: BTreeMap ;
76use std:: sync:: { Arc , Mutex } ;
87use std:: { error, fmt, iter} ;
@@ -19,22 +18,6 @@ pub struct ErrorSet {
1918 errors : BTreeMap < Option < Position > , Vec < Error > > ,
2019}
2120
22- impl < T > From < santiago:: parser:: ParseError < T > > for ErrorSet {
23- fn from ( e : santiago:: parser:: ParseError < T > ) -> Self {
24- let lex = e. at . map ( |rc| ( * rc) . clone ( ) ) ;
25- match lex. as_ref ( ) . map ( |lex| & lex. position ) . map ( Position :: from) {
26- Some ( pos) => ErrorSet :: single ( pos, Error :: ParseFailed ( lex) ) ,
27- None => ErrorSet :: single_no_position ( Error :: ParseFailed ( lex) ) ,
28- }
29- }
30- }
31-
32- impl From < santiago:: lexer:: LexerError > for ErrorSet {
33- fn from ( e : santiago:: lexer:: LexerError ) -> Self {
34- ErrorSet :: single ( e. position , Error :: LexFailed ( e. message ) )
35- }
36- }
37-
3821impl ErrorSet {
3922 /// Constructs a new empty error set.
4023 pub fn new ( ) -> Self {
@@ -260,10 +243,10 @@ pub enum Error {
260243 NameRepeated ( Arc < str > ) ,
261244 /// Program did not have a `main` expression
262245 NoMain ,
263- /// Parsing failed ( the parser provides us some extra information, but beyond
264- /// the line and column, it does not seem very useful to a user, so we drop it) .
265- ParseFailed ( Option < Lexeme > ) ,
266- /// Lexing failed; here santiago provides us an error message which is useful
246+ /// Parsing failed; the string (if any) is a description of the token at which
247+ /// parsing failed .
248+ ParseFailed ( Option < String > ) ,
249+ /// Lexing failed
267250 LexFailed ( String ) ,
268251 /// A number was parsed in some context but was out of range.
269252 NumberOutOfRange ( String ) ,
@@ -327,7 +310,7 @@ impl fmt::Display for Error {
327310 write ! ( f, "number {} was out of allowable range" , n)
328311 }
329312 Error :: ParseFailed ( None ) => f. write_str ( "could not parse" ) ,
330- Error :: ParseFailed ( Some ( ref lex ) ) => write ! ( f, "could not parse `{}`" , lex . raw) ,
313+ Error :: ParseFailed ( Some ( ref raw ) ) => write ! ( f, "could not parse `{}`" , raw) ,
331314 Error :: LexFailed ( ref msg) => write ! ( f, "could not parse: {}" , msg) ,
332315 Error :: TypeCheck ( ref e) => fmt:: Display :: fmt ( e, f) ,
333316 Error :: Undefined ( ref s) => write ! ( f, "reference to undefined symbol `{}`" , s) ,
0 commit comments