more clippy lints
This commit is contained in:
parent
36f06b38de
commit
ae6a79077f
@ -1,5 +1,7 @@
|
|||||||
use std::rc::Rc;
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
#![allow(clippy::enum_variant_names)]
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
use crate::derivative::Derivative;
|
use crate::derivative::Derivative;
|
||||||
|
|
||||||
mod walker;
|
mod walker;
|
||||||
|
@ -6,26 +6,28 @@ use crate::ast::*;
|
|||||||
|
|
||||||
pub trait ASTVisitor: Sized {
|
pub trait ASTVisitor: Sized {
|
||||||
fn ast(&mut self, _ast: &AST) {}
|
fn ast(&mut self, _ast: &AST) {}
|
||||||
fn block(&mut self, _statements: &Vec<Statement>) {}
|
fn block(&mut self, _statements: &[ Statement ]) {}
|
||||||
fn statement(&mut self, _statement: &Statement) {}
|
fn statement(&mut self, _statement: &Statement) {}
|
||||||
fn declaration(&mut self, _declaration: &Declaration) {}
|
fn declaration(&mut self, _declaration: &Declaration) {}
|
||||||
fn signature(&mut self, _signature: &Signature) {}
|
fn signature(&mut self, _signature: &Signature) {}
|
||||||
fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: bool) {}
|
fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: bool) {}
|
||||||
fn type_alias(&mut self, _alias: &Rc<String>, _original: &Rc<String>) {}
|
fn type_alias(&mut self, _alias: &Rc<String>, _original: &Rc<String>) {}
|
||||||
fn binding(&mut self, _name: &Rc<String>, _constant: bool, _type_anno: Option<&TypeIdentifier>, _expr: &Expression) {}
|
fn binding(&mut self, _name: &Rc<String>, _constant: bool, _type_anno: Option<&TypeIdentifier>, _expr: &Expression) {}
|
||||||
fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &Vec<Declaration>) {}
|
fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &[ Declaration ]) {}
|
||||||
fn interface(&mut self, _name: &Rc<String>, _signatures: &Vec<Signature>) {}
|
fn interface(&mut self, _name: &Rc<String>, _signatures: &[ Signature ]) {}
|
||||||
fn expression(&mut self, _expression: &Expression) {}
|
fn expression(&mut self, _expression: &Expression) {}
|
||||||
fn expression_kind(&mut self, _kind: &ExpressionKind) {}
|
fn expression_kind(&mut self, _kind: &ExpressionKind) {}
|
||||||
fn type_annotation(&mut self, _type_anno: Option<&TypeIdentifier>) {}
|
fn type_annotation(&mut self, _type_anno: Option<&TypeIdentifier>) {}
|
||||||
fn named_struct(&mut self, _name: &QualifiedName, _fields: &Vec<(Rc<String>, Expression)>) {}
|
fn named_struct(&mut self, _name: &QualifiedName, _fields: &[ (Rc<String>, Expression) ]) {}
|
||||||
fn call(&mut self, _f: &Expression, _arguments: &Vec<InvocationArgument>) {}
|
fn call(&mut self, _f: &Expression, _arguments: &[ InvocationArgument ]) {}
|
||||||
fn index(&mut self, _indexee: &Expression, _indexers: &Vec<Expression>) {}
|
fn index(&mut self, _indexee: &Expression, _indexers: &[ Expression ]) {}
|
||||||
fn if_expression(&mut self, _discrim: Option<&Expression>, _body: &IfExpressionBody) {}
|
fn if_expression(&mut self, _discrim: Option<&Expression>, _body: &IfExpressionBody) {}
|
||||||
fn condition_arm(&mut self, _arm: &ConditionArm) {}
|
fn condition_arm(&mut self, _arm: &ConditionArm) {}
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn while_expression(&mut self, _condition: Option<&Expression>, _body: &Block) {}
|
fn while_expression(&mut self, _condition: Option<&Expression>, _body: &Block) {}
|
||||||
fn for_expression(&mut self, _enumerators: &Vec<Enumerator>, _body: &ForBody) {}
|
fn for_expression(&mut self, _enumerators: &[ Enumerator ], _body: &ForBody) {}
|
||||||
fn lambda(&mut self, _params: &Vec<FormalParam>, _type_anno: Option<&TypeIdentifier>, _body: &Block) {}
|
#[allow(clippy::ptr_arg)]
|
||||||
|
fn lambda(&mut self, _params: &[ FormalParam ], _type_anno: Option<&TypeIdentifier>, _body: &Block) {}
|
||||||
fn invocation_argument(&mut self, _arg: &InvocationArgument) {}
|
fn invocation_argument(&mut self, _arg: &InvocationArgument) {}
|
||||||
fn formal_param(&mut self, _param: &FormalParam) {}
|
fn formal_param(&mut self, _param: &FormalParam) {}
|
||||||
fn import(&mut self, _import: &ImportSpecifier) {}
|
fn import(&mut self, _import: &ImportSpecifier) {}
|
||||||
|
@ -9,6 +9,7 @@ pub fn walk_ast<V: ASTVisitor>(v: &mut V, ast: &AST) {
|
|||||||
walk_block(v, &ast.statements);
|
walk_block(v, &ast.statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn walk_block<V: ASTVisitor>(v: &mut V, block: &Vec<Statement>) {
|
fn walk_block<V: ASTVisitor>(v: &mut V, block: &Vec<Statement>) {
|
||||||
for s in block {
|
for s in block {
|
||||||
v.statement(s);
|
v.statement(s);
|
||||||
@ -79,7 +80,7 @@ fn expression<V: ASTVisitor>(v: &mut V, expression: &Expression) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn call<V: ASTVisitor>(v: &mut V, f: &Expression, args: &Vec<InvocationArgument>) {
|
fn call<V: ASTVisitor>(v: &mut V, f: &Expression, args: &[ InvocationArgument ]) {
|
||||||
v.expression(f);
|
v.expression(f);
|
||||||
expression(v, f);
|
expression(v, f);
|
||||||
for arg in args.iter() {
|
for arg in args.iter() {
|
||||||
@ -103,20 +104,21 @@ fn invocation_argument<V: ASTVisitor>(v: &mut V, arg: &InvocationArgument) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index<V: ASTVisitor>(v: &mut V, indexee: &Expression, indexers: &Vec<Expression>) {
|
fn index<V: ASTVisitor>(v: &mut V, indexee: &Expression, indexers: &[ Expression ]) {
|
||||||
v.expression(indexee);
|
v.expression(indexee);
|
||||||
for i in indexers.iter() {
|
for i in indexers.iter() {
|
||||||
v.expression(i);
|
v.expression(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn named_struct<V: ASTVisitor>(v: &mut V, n: &QualifiedName, fields: &Vec<(Rc<String>, Expression)>) {
|
fn named_struct<V: ASTVisitor>(v: &mut V, n: &QualifiedName, fields: &[ (Rc<String>, Expression) ]) {
|
||||||
v.qualified_name(n);
|
v.qualified_name(n);
|
||||||
for (_, expr) in fields.iter() {
|
for (_, expr) in fields.iter() {
|
||||||
v.expression(expr);
|
v.expression(expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn lambda<V: ASTVisitor>(v: &mut V, params: &Vec<FormalParam>, type_anno: Option<&TypeIdentifier>, body: &Block) {
|
fn lambda<V: ASTVisitor>(v: &mut V, params: &Vec<FormalParam>, type_anno: Option<&TypeIdentifier>, body: &Block) {
|
||||||
for param in params {
|
for param in params {
|
||||||
v.formal_param(param);
|
v.formal_param(param);
|
||||||
@ -128,10 +130,10 @@ fn lambda<V: ASTVisitor>(v: &mut V, params: &Vec<FormalParam>, type_anno: Option
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn formal_param<V: ASTVisitor>(v: &mut V, param: &FormalParam) {
|
fn formal_param<V: ASTVisitor>(v: &mut V, param: &FormalParam) {
|
||||||
param.default.as_ref().map(|p| {
|
if let Some(p) = param.default.as_ref() {
|
||||||
v.expression(p);
|
v.expression(p);
|
||||||
expression(v, p);
|
expression(v, p);
|
||||||
});
|
};
|
||||||
v.type_annotation(param.anno.as_ref());
|
v.type_annotation(param.anno.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,10 +232,10 @@ fn condition_arm<V: ASTVisitor>(v: &mut V, arm: &ConditionArm) {
|
|||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
arm.guard.as_ref().map(|guard| {
|
if let Some(guard) = arm.guard.as_ref() {
|
||||||
v.expression(guard);
|
v.expression(guard);
|
||||||
expression(v, guard);
|
expression(v, guard);
|
||||||
});
|
};
|
||||||
v.block(&arm.body);
|
v.block(&arm.body);
|
||||||
walk_block(v, &arm.body);
|
walk_block(v, &arm.body);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
|
||||||
//! # Parsing
|
//! # Parsing
|
||||||
//! This module is where the recursive-descent parsing methods live.
|
//! This module is where the recursive-descent parsing methods live.
|
||||||
//!
|
//!
|
||||||
@ -417,15 +419,10 @@ impl Parser {
|
|||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn type_body(&mut self) -> ParseResult<TypeBody> {
|
fn type_body(&mut self) -> ParseResult<TypeBody> {
|
||||||
let mut variants = Vec::new();
|
let mut variants = vec![self.variant_specifier()?];
|
||||||
variants.push(self.variant_specifier()?);
|
while let Pipe = self.token_handler.peek_kind() {
|
||||||
loop {
|
|
||||||
if let Pipe = self.token_handler.peek_kind() {
|
|
||||||
self.token_handler.next();
|
self.token_handler.next();
|
||||||
variants.push(self.variant_specifier()?);
|
variants.push(self.variant_specifier()?);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(TypeBody(variants))
|
Ok(TypeBody(variants))
|
||||||
}
|
}
|
||||||
@ -616,6 +613,7 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this implements Pratt parsing, see http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
|
// this implements Pratt parsing, see http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
|
||||||
|
#[allow(clippy::while_let_loop)]
|
||||||
fn precedence_expr(&mut self, precedence: i32) -> ParseResult<Expression> {
|
fn precedence_expr(&mut self, precedence: i32) -> ParseResult<Expression> {
|
||||||
let record = ParseRecord {
|
let record = ParseRecord {
|
||||||
production_name: "precedence_expr".to_string(),
|
production_name: "precedence_expr".to_string(),
|
||||||
@ -799,14 +797,11 @@ impl Parser {
|
|||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn qualified_identifier(&mut self) -> ParseResult<Vec<Rc<String>>> {
|
fn qualified_identifier(&mut self) -> ParseResult<Vec<Rc<String>>> {
|
||||||
let mut components = vec![self.identifier()?];
|
let mut components = vec![self.identifier()?];
|
||||||
loop {
|
|
||||||
match (self.token_handler.peek_kind(), self.token_handler.peek_kind_n(1)) {
|
while let (Colon, Colon) = (self.token_handler.peek_kind(), self.token_handler.peek_kind_n(1)) {
|
||||||
(Colon, Colon) => {
|
self.token_handler.next();
|
||||||
self.token_handler.next(); self.token_handler.next();
|
self.token_handler.next();
|
||||||
components.push(self.identifier()?);
|
components.push(self.identifier()?);
|
||||||
},
|
|
||||||
_ => break,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(components)
|
Ok(components)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::tokenizing::Location;
|
use crate::tokenizing::Location;
|
||||||
|
@ -92,7 +92,7 @@ impl<'a> ASTVisitor for Resolver<'a> {
|
|||||||
self.symbol_table.id_to_fqsn.insert(qualified_name.id.clone(), fqsn);
|
self.symbol_table.id_to_fqsn.insert(qualified_name.id.clone(), fqsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn named_struct(&mut self, qualified_name: &QualifiedName, _fields: &Vec<(Rc<String>, Expression)>) {
|
fn named_struct(&mut self, qualified_name: &QualifiedName, _fields: &[ (Rc<String>, Expression) ]) {
|
||||||
let fqsn = self.lookup_name_in_scope(qualified_name);
|
let fqsn = self.lookup_name_in_scope(qualified_name);
|
||||||
self.symbol_table.id_to_fqsn.insert(qualified_name.id.clone(), fqsn);
|
self.symbol_table.id_to_fqsn.insert(qualified_name.id.clone(), fqsn);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::{iter::{Iterator, Peekable}, convert::TryFrom, rc::Rc, fmt};
|
use std::{iter::{Iterator, Peekable}, convert::TryFrom, rc::Rc, fmt};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
|
||||||
/// A location in a particular source file. Note that the
|
/// A location in a particular source file. Note that the
|
||||||
/// sizes of the internal unsigned integer types limit
|
/// sizes of the internal unsigned integer types limit
|
||||||
/// the size of a source file to 2^32 lines of
|
/// the size of a source file to 2^32 lines of
|
||||||
|
Loading…
Reference in New Issue
Block a user