From 836445d5e2d6872fcace73843c535de45cc86412 Mon Sep 17 00:00:00 2001 From: nothendev Date: Thu, 4 May 2023 16:51:31 +0300 Subject: [PATCH] cargo fmt why not --- Cargo.lock | 1 + programs/aidl/src/ast.rs | 4 ++-- programs/aidl/src/lexer.rs | 11 +++++++---- programs/aidl/src/main.rs | 8 +++++--- programs/aidl/src/parser.rs | 14 +++++++------- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8b2084..0f837b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,7 @@ name = "aidl" version = "0.1.0" dependencies = [ "logos 0.13.0", + "thiserror", ] [[package]] diff --git a/programs/aidl/src/ast.rs b/programs/aidl/src/ast.rs index 3d8665f..364f4e4 100644 --- a/programs/aidl/src/ast.rs +++ b/programs/aidl/src/ast.rs @@ -74,11 +74,11 @@ pub enum NumberLiteral { U64(u64), I64(i64), - Infer(i64) + Infer(i64), } /// seg1.seg2.seg3.segN #[derive(Debug)] pub struct ModulePath { - pub segments: Vec + pub segments: Vec, } diff --git a/programs/aidl/src/lexer.rs b/programs/aidl/src/lexer.rs index 7377123..7ec404c 100644 --- a/programs/aidl/src/lexer.rs +++ b/programs/aidl/src/lexer.rs @@ -1,4 +1,7 @@ -use std::{ops::{Range, Add}, fmt::Display}; +use std::{ + fmt::Display, + ops::{Add, Range}, +}; use logos::Logos; @@ -60,7 +63,7 @@ pub enum Ident { #[token("Use")] Use, #[regex(r"[A-z]+", |lex| lex.slice().parse().ok())] - Other(String) + Other(String), } #[derive(Debug, Clone)] @@ -76,7 +79,7 @@ impl Span { } pub fn concat(self, other: Span) -> Self { - use std::cmp::{min, max}; + use std::cmp::{max, min}; Self(min(self.lower(), other.lower())..max(self.upper(), other.upper())) } @@ -90,7 +93,7 @@ impl Add for Span { type Output = Self; fn add(self, rhs: Self) -> Self::Output { - self.concat(rhs) + self.concat(rhs) } } diff --git a/programs/aidl/src/main.rs b/programs/aidl/src/main.rs index 1ddd593..e331ad8 100644 --- a/programs/aidl/src/main.rs +++ b/programs/aidl/src/main.rs @@ -11,8 +11,10 @@ const TEST: &str = include_str!("../assets/why.idl"); fn main() { let res = Parser::new(TEST).parse(); match res { - Ok(ast) => { dbg!(ast); } - Err(e) => println!("{}", e) + Ok(ast) => { + dbg!(ast); + } + Err(e) => println!("{}", e), } } @@ -21,7 +23,7 @@ macro_rules! unwrap_match { ($x:expr, $m:pat => $a:expr) => { match $x { $m => $a, - _ => unreachable!() + _ => unreachable!(), } }; } diff --git a/programs/aidl/src/parser.rs b/programs/aidl/src/parser.rs index 9277e3d..8586682 100644 --- a/programs/aidl/src/parser.rs +++ b/programs/aidl/src/parser.rs @@ -73,11 +73,11 @@ impl<'a> Parser<'a> { if matcher(self.tokens.peek()?.0) { self.tokens.next() } else { - Err(self.unexpected(expected)) + Err(self.expected(expected)) } } - fn unexpected(&self, expected: &'static str) -> ParserError { + fn expected(&self, expected: &'static str) -> ParserError { ParserError::Unexpected(expected.to_owned(), self.tokens.current()) } @@ -123,7 +123,7 @@ impl<'a> Parser<'a> { span = span + v.1; break; } - _ => return Err(self.unexpected("a path segment")), + _ => return Err(self.expected("a path segment")), } } @@ -163,21 +163,21 @@ impl<'a> Parser<'a> { } fn ask_constant(&mut self) -> Result, ParserError> { - Err(self.unexpected("")) + Err(self.expected("the constant to be implemented")) } fn ask_item(&mut self) -> Result, ParserError> { Ok(match self.tokens.peek()?.0 { Token::Ident(Ident::Other(_)) => { - Err(self.unexpected("a keyword, not just an identifier"))? + Err(self.expected("a keyword, not just an identifier"))? } Token::Ident(keyword) => match keyword { //Ident::Interface => self.ask_interface()?.map(Item::Interface), Ident::Alias => self.ask_alias()?.map(Item::Alias), Ident::Constant => self.ask_constant()?.map(Item::Constant), - _ => Err(self.unexpected("`Alias` or `Constant`"))?, + _ => Err(self.expected("`Alias` or `Constant`"))?, }, - _ => Err(self.unexpected("a keyword"))?, + _ => Err(self.expected("a keyword"))?, }) }