Implement clippy thoughts into rustpython_parser

This commit is contained in:
Windel Bouwman committed 2019-02-04 18:18:40 +01:00
1 parent 7096434f95
commit 2b22cd443e
3 files changed
+27 -34

No files matched your search

+2 -2
View File
@@ -65,9 +65,9 @@ pub enum Statement {
value: Expression,
},
AugAssign {
target: Expression,
target: Box<Expression>,
op: Operator,
value: Expression,
value: Box<Expression>,
},
Expression {
expression: Expression,
+20 -31
View File
@@ -64,10 +64,7 @@ pub struct Location {
impl Location {
pub fn new(row: usize, column: usize) -> Self {
Location {
row: row,
column: column,
}
Location { row, column }
}
pub fn get_row(&self) -> usize {
@@ -126,8 +123,7 @@ pub type Spanned<Tok> = Result<(Location, Tok, Location), LexicalError>;
pub fn make_tokenizer<'a>(source: &'a str) -> impl Iterator<Item = Spanned<Tok>> + 'a {
let nlh = NewlineHandler::new(source.chars());
let lch = LineContinationHandler::new(nlh);
let lexer = Lexer::new(lch);
lexer
Lexer::new(lch)
}
// The newline handler is an iterator which collapses different newline
@@ -144,7 +140,7 @@ where
{
pub fn new(source: T) -> Self {
let mut nlh = NewlineHandler {
source: source,
source,
chr0: None,
chr1: None,
};
@@ -200,7 +196,7 @@ where
{
pub fn new(source: T) -> Self {
let mut nlh = LineContinationHandler {
source: source,
source,
chr0: None,
chr1: None,
};
@@ -313,7 +309,7 @@ where
if keywords.contains_key(&name) {
Ok((start_pos, keywords.remove(&name).unwrap(), end_pos))
} else {
Ok((start_pos, Tok::Name { name: name }, end_pos))
Ok((start_pos, Tok::Name { name }, end_pos))
}
}
@@ -358,7 +354,7 @@ where
let end_pos = self.get_pos();
let value = BigInt::from_str_radix(&value_text, radix).unwrap();
Ok((start_pos, Tok::Int { value: value }, end_pos))
Ok((start_pos, Tok::Int { value }, end_pos))
}
fn lex_normal_number(&mut self) -> Spanned<Tok> {
@@ -410,7 +406,7 @@ where
))
} else {
let end_pos = self.get_pos();
Ok((start_pos, Tok::Float { value: value }, end_pos))
Ok((start_pos, Tok::Float { value }, end_pos))
}
} else {
// Parse trailing 'j':
@@ -418,18 +414,11 @@ where
self.next_char();
let end_pos = self.get_pos();
let imag = f64::from_str(&value_text).unwrap();
Ok((
start_pos,
Tok::Complex {
real: 0.0,
imag: imag,
},
end_pos,
))
Ok((start_pos, Tok::Complex { real: 0.0, imag }, end_pos))
} else {
let end_pos = self.get_pos();
let value = value_text.parse::<BigInt>().unwrap();
Ok((start_pos, Tok::Int { value: value }, end_pos))
Ok((start_pos, Tok::Int { value }, end_pos))
}
}
}
@@ -548,33 +537,33 @@ where
}
};
return Ok((start_pos, tok, end_pos));
Ok((start_pos, tok, end_pos))
}
fn is_char(&self) -> bool {
match self.chr0 {
Some('a'...'z') | Some('A'...'Z') | Some('_') | Some('0'...'9') => return true,
_ => return false,
Some('a'...'z') | Some('A'...'Z') | Some('_') | Some('0'...'9') => true,
_ => false,
}
}
fn is_number(&self, radix: u32) -> bool {
match radix {
2 => match self.chr0 {
Some('0'...'1') => return true,
_ => return false,
Some('0'...'1') => true,
_ => false,
},
8 => match self.chr0 {
Some('0'...'7') => return true,
_ => return false,
Some('0'...'7') => true,
_ => false,
},
10 => match self.chr0 {
Some('0'...'9') => return true,
_ => return false,
Some('0'...'9') => true,
_ => false,
},
16 => match self.chr0 {
Some('0'...'9') | Some('a'...'f') | Some('A'...'F') => return true,
_ => return false,
Some('0'...'9') | Some('a'...'f') | Some('A'...'F') => true,
_ => false,
},
x => unimplemented!("Radix not implemented: {}", x),
}
+5 -1
View File
@@ -105,7 +105,11 @@ ExpressionStatement: ast::LocatedStatement = {
let rhs = e2.into_iter().next().unwrap();
ast::LocatedStatement {
location: loc,
node: ast::Statement::AugAssign { target: expr, op: op, value: rhs },
node: ast::Statement::AugAssign {
target: Box::new(expr),
op,
value: Box::new(rhs)
},
}
},
};