clippy cleanup

This commit is contained in:
nora 2021-11-02 21:13:20 +01:00
parent 8593ddf18d
commit 7cba55578a
4 changed files with 23 additions and 23 deletions

View file

@ -73,8 +73,8 @@ where
E: CompilerError + Debug, E: CompilerError + Debug,
{ {
let mut chars = 0; let mut chars = 0;
let mut lines = source.split_inclusive('\n').enumerate(); let lines = source.split_inclusive('\n').enumerate();
while let Some((idx, line)) = lines.next() { for (idx, line) in lines {
if chars + line.len() + 1 > error.span().start { if chars + line.len() + 1 > error.span().start {
let offset_on_line = error.span().start - chars; let offset_on_line = error.span().start - chars;

View file

@ -373,7 +373,7 @@ impl CompilerError for LexError {
fn message(&self) -> String { fn message(&self) -> String {
match &self.kind { match &self.kind {
LexErrorKind::InvalidCharacter(char) => format!("Unexpected character: '{}'", char), LexErrorKind::InvalidCharacter(char) => format!("Unexpected character: '{}'", char),
LexErrorKind::InvalidFloat(_) => format!("Invalid number"), LexErrorKind::InvalidFloat(_) => "Invalid number".to_string(),
LexErrorKind::FloatInfiniteLiteral => "Number literal too long".to_string(), LexErrorKind::FloatInfiniteLiteral => "Number literal too long".to_string(),
LexErrorKind::UnclosedStringLiteral => "String literal not closed".to_string(), LexErrorKind::UnclosedStringLiteral => "String literal not closed".to_string(),
LexErrorKind::SingleBang => "Expected '=' after '!'".to_string(), LexErrorKind::SingleBang => "Expected '=' after '!'".to_string(),

View file

@ -1,5 +1,5 @@
fn main() { fn main() {
if let Some(filename) = std::env::args().skip(1).next() { if let Some(filename) = std::env::args().nth(1) {
match std::fs::read_to_string(filename) { match std::fs::read_to_string(filename) {
Ok(contents) => { Ok(contents) => {
script_lang::run_program(&contents); script_lang::run_program(&contents);

View file

@ -65,15 +65,15 @@ impl<'code> Parser<'code> {
} }
fn statement(&mut self) -> ParseResult<'code, Stmt> { fn statement(&mut self) -> ParseResult<'code, Stmt> {
match self.peek_kind().ok_or(ParseErr::EOF("statement"))? { match *self.peek_kind().ok_or(ParseErr::Eof("statement"))? {
&TokenType::Let => self.declaration(), TokenType::Let => self.declaration(),
&TokenType::Fn => self.fn_decl(), TokenType::Fn => self.fn_decl(),
&TokenType::If => Ok(Stmt::If(self.if_stmt()?)), TokenType::If => Ok(Stmt::If(self.if_stmt()?)),
&TokenType::Loop => self.loop_stmt(), TokenType::Loop => self.loop_stmt(),
&TokenType::While => self.while_stmt(), TokenType::While => self.while_stmt(),
&TokenType::Break => self.break_stmt(), TokenType::Break => self.break_stmt(),
&TokenType::Return => self.return_stmt(), TokenType::Return => self.return_stmt(),
&TokenType::BraceO => Ok(Stmt::Block(self.block()?)), TokenType::BraceO => Ok(Stmt::Block(self.block()?)),
_ => { _ => {
let expr = self.expression()?; let expr = self.expression()?;
self.expect(TokenType::Semi)?; self.expect(TokenType::Semi)?;
@ -307,7 +307,7 @@ impl<'code> Parser<'code> {
} }
fn primary<'parser>(&'parser mut self) -> ParseResult<'code, Expr> { fn primary<'parser>(&'parser mut self) -> ParseResult<'code, Expr> {
let next = self.next().ok_or(ParseErr::EOF("primary"))?; let next = self.next().ok_or(ParseErr::Eof("primary"))?;
match next.kind { match next.kind {
TokenType::String(literal) => Ok(Expr::Literal(Literal::String(literal, next.span))), TokenType::String(literal) => Ok(Expr::Literal(Literal::String(literal, next.span))),
TokenType::Number(literal) => Ok(Expr::Literal(Literal::Number(literal, next.span))), TokenType::Number(literal) => Ok(Expr::Literal(Literal::Number(literal, next.span))),
@ -333,7 +333,7 @@ impl<'code> Parser<'code> {
} }
fn ident(&mut self) -> ParseResult<'code, Ident> { fn ident(&mut self) -> ParseResult<'code, Ident> {
let Token { kind, span } = self.next().ok_or(ParseErr::EOF("identifier"))?; let Token { kind, span } = self.next().ok_or(ParseErr::Eof("identifier"))?;
match kind { match kind {
TokenType::Ident(name) => { TokenType::Ident(name) => {
let name_owned = name.to_owned(); let name_owned = name.to_owned();
@ -384,7 +384,7 @@ impl<'code> Parser<'code> {
while self while self
.peek_kind() .peek_kind()
.ok_or_else(|| ParseErr::EOFExpecting(close.clone()))? .ok_or_else(|| ParseErr::EofExpecting(close.clone()))?
!= &close != &close
{ {
self.expect(TokenType::Comma)?; self.expect(TokenType::Comma)?;
@ -428,7 +428,7 @@ impl<'code> Parser<'code> {
}) })
} }
} else { } else {
Err(ParseErr::EOFExpecting(kind)) Err(ParseErr::EofExpecting(kind))
} }
} }
} }
@ -442,8 +442,8 @@ pub enum ParseErr<'code> {
actual: Token<'code>, actual: Token<'code>,
}, },
InvalidTokenPrimary(Token<'code>), InvalidTokenPrimary(Token<'code>),
EOFExpecting(TokenType<'code>), EofExpecting(TokenType<'code>),
EOF(&'static str), Eof(&'static str),
} }
impl CompilerError for ParseErr<'_> { impl CompilerError for ParseErr<'_> {
@ -454,8 +454,8 @@ impl CompilerError for ParseErr<'_> {
.. ..
} => *span, } => *span,
ParseErr::InvalidTokenPrimary(Token { span, .. }) => *span, ParseErr::InvalidTokenPrimary(Token { span, .. }) => *span,
ParseErr::EOFExpecting(_) => Span::dummy(), ParseErr::EofExpecting(_) => Span::dummy(),
ParseErr::EOF(_) => Span::dummy(), ParseErr::Eof(_) => Span::dummy(),
ParseErr::BreakOutsideLoop(span) => *span, ParseErr::BreakOutsideLoop(span) => *span,
ParseErr::ReturnOutsideFunction(span) => *span, ParseErr::ReturnOutsideFunction(span) => *span,
} }
@ -469,10 +469,10 @@ impl CompilerError for ParseErr<'_> {
ParseErr::InvalidTokenPrimary(token) => { ParseErr::InvalidTokenPrimary(token) => {
format!("invalid token in expression: `{:?}`", token.kind) format!("invalid token in expression: `{:?}`", token.kind)
} }
ParseErr::EOFExpecting(token) => { ParseErr::EofExpecting(token) => {
format!("reached EOF searching for `{:?}`", token) format!("reached EOF searching for `{:?}`", token)
} }
ParseErr::EOF(message) => { ParseErr::Eof(message) => {
format!("reached EOF while parsing `{}`", message) format!("reached EOF while parsing `{}`", message)
} }
ParseErr::BreakOutsideLoop(_) => "break used outside of loop".to_string(), ParseErr::BreakOutsideLoop(_) => "break used outside of loop".to_string(),