diff options
Diffstat (limited to 'src/lang')
-rw-r--r-- | src/lang/parser.rs | 14 | ||||
-rw-r--r-- | src/lang/tokenizer.rs | 44 |
2 files changed, 26 insertions, 32 deletions
diff --git a/src/lang/parser.rs b/src/lang/parser.rs index 5264554..7419a56 100644 --- a/src/lang/parser.rs +++ b/src/lang/parser.rs @@ -24,10 +24,10 @@ impl ErrorType { desc: "".to_string(), }; - ret.desc = match &ret.kind { - &ErrorKind::Unexpected(found, expected) => format!("Found {:?}, expected {:?}", found, expected), - &ErrorKind::ExpectedOp(c, found) => format!("Expected {:?}, found {:?}", c, found), - &ErrorKind::UnknownGen(ref s) => format!("Unknown generator name {}", s), + ret.desc = match ret.kind { + ErrorKind::Unexpected(found, expected) => format!("Found {:?}, expected {:?}", found, expected), + ErrorKind::ExpectedOp(c, found) => format!("Expected {:?}, found {:?}", c, found), + ErrorKind::UnknownGen(ref s) => format!("Unknown generator name {}", s), }; ret @@ -42,7 +42,7 @@ impl ErrorType { } impl Error for ErrorType { - fn description<'a>(&'a self) -> &'a str { + fn description(&self) -> &str { &self.desc } } @@ -144,8 +144,8 @@ impl<T: Iterator<Item=char>> Parser<T> { if self.expect_op('=').is_ok() { nm } else { - match &self.token { - &Token::Oper(c) if c == '(' => { + match self.token { + Token::Oper(c) if c == '(' => { self.push_back(Token::Ident(nm)); ctr += 1; (ctr - 1).to_string() diff --git a/src/lang/tokenizer.rs b/src/lang/tokenizer.rs index 9b408d2..74b304d 100644 --- a/src/lang/tokenizer.rs +++ b/src/lang/tokenizer.rs @@ -79,20 +79,20 @@ impl ErrorType { desc: "".to_string(), }; - ret.desc = match &ret.kind { - &ErrorKind::UnexpectedEOF(ref loc) => format!("Unexpected EOF {}", match loc { - &Location::InString => "in string constant", - &Location::InStringEscape => "in string escape", + ret.desc = match ret.kind { + ErrorKind::UnexpectedEOF(ref loc) => format!("Unexpected EOF {}", match *loc { + Location::InString => "in string constant", + Location::InStringEscape => "in string escape", }), - &ErrorKind::BadEscapeValue(ref kind, ref val, ref err) => format!("Bad {} escape {}: {:?}", match kind { - &EscapeKind::Hexadecimal => "hexadecimal", - &EscapeKind::Octal => "octal", + ErrorKind::BadEscapeValue(ref kind, ref val, ref err) => format!("Bad {} escape {}: {:?}", match *kind { + EscapeKind::Hexadecimal => "hexadecimal", + EscapeKind::Octal => "octal", }, val, err), - &ErrorKind::BadNumericLiteral(ref kind, ref val, ref err) => format!("Bad {} literal {}: {:?}", match kind { - &NumericKind::Integer => "integer", - &NumericKind::Float => "floating point", + ErrorKind::BadNumericLiteral(ref kind, ref val, ref err) => format!("Bad {} literal {}: {:?}", match *kind { + NumericKind::Integer => "integer", + NumericKind::Float => "floating point", }, val, err), - &ErrorKind::UnknownChar(c) => format!("Unknown character {}", c), + ErrorKind::UnknownChar(c) => format!("Unknown character {}", c), }; ret @@ -107,22 +107,17 @@ impl ErrorType { } impl Error for ErrorType { - fn description<'a>(&'a self) -> &'a str { + fn description(&self) -> &str { &self.desc } fn cause(&self) -> Option<&Error> { - match &self.kind { - &ErrorKind::UnexpectedEOF(_) => None, - &ErrorKind::BadEscapeValue(_, _, ref err) => match err { - &Some(ref err) => Some(&**err), - &None => None, + match self.kind { + ErrorKind::BadNumericLiteral(_, _, ref err) | ErrorKind::BadEscapeValue(_, _, ref err) => match *err { + Some(ref err) => Some(&**err), + None => None, }, - &ErrorKind::BadNumericLiteral(_, _, ref err) => match err { - &Some(ref err) => Some(&**err), - &None => None, - }, - &ErrorKind::UnknownChar(_) => None, + ErrorKind::UnexpectedEOF(_) | ErrorKind::UnknownChar(_) => None, } } } @@ -392,7 +387,7 @@ impl<T: Iterator<Item=char>> Tokenizer<T> { } /* Everything else */ - return Ok(Token::Oper(cc)); + Ok(Token::Oper(cc)) } } @@ -401,8 +396,7 @@ impl<T: Iterator<Item=char>> Iterator for Tokenizer<T> { fn next(&mut self) -> Option<Token> { match self.next_token() { - Err(_) => None, - Ok(Token::EOF) => None, + Err(_) | Ok(Token::EOF) => None, Ok(t) => Some(t), } } |