From c32da018adc3d8047e0534ee177140240ad8be23 Mon Sep 17 00:00:00 2001 From: NotAFile Date: Tue, 1 Feb 2022 19:46:06 +0100 Subject: [PATCH] cargo fmt --- src/frontend.rs | 8 ++------ src/frontend/typed_ir.rs | 5 ++--- src/main.rs | 12 ++++++++---- src/parser.rs | 20 +++++++++----------- src/parser/error.rs | 25 +++++++++---------------- src/parser/literals.rs | 3 ++- src/parser/module.rs | 25 ++++++++++++------------- 7 files changed, 44 insertions(+), 54 deletions(-) diff --git a/src/frontend.rs b/src/frontend.rs index 8b340ba..51a98de 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -8,8 +8,8 @@ pub use callable::Callable; pub use types::{Type, TypeStruct}; mod callable; -pub mod types; pub mod typed_ir; +pub mod types; /// lots of code is still not width-aware, this constant keeps track of that const TODO_WIDTH: u32 = 1; @@ -316,11 +316,7 @@ pub fn lower_module(pa_module: parser::Module) -> Result { parser::PortDirection::Input => rtlil::PortOption::Input(idx as i32 + 1), parser::PortDirection::Output => rtlil::PortOption::Output(idx as i32 + 1), }; - let wire = rtlil::Wire::new( - sig.il_id.to_owned(), - TODO_WIDTH, - Some(dir_option), - ); + let wire = rtlil::Wire::new(sig.il_id.to_owned(), TODO_WIDTH, Some(dir_option)); ir_module.add_wire(wire); } for item in pa_module.items { diff --git a/src/frontend/typed_ir.rs b/src/frontend/typed_ir.rs index c090722..d25bb64 100644 --- a/src/frontend/typed_ir.rs +++ b/src/frontend/typed_ir.rs @@ -9,8 +9,7 @@ struct Element<'ty> { struct Signal<'ty> { pub id: u32, - pub typ: Type<'ty> + pub typ: Type<'ty>, } -struct Expression { -} +struct Expression {} diff --git a/src/main.rs b/src/main.rs index dec7247..a97885e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,9 +8,8 @@ use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; -use structopt::StructOpt; -use nom_greedyerror::convert_error; use ariadne::Source; +use structopt::StructOpt; #[derive(Debug, StructOpt)] #[structopt(name = "example", about = "An example of StructOpt usage.")] @@ -45,9 +44,14 @@ fn main() { let parsed = parser::parse(input); match parsed { Err(nom::Err::Error(err) | nom::Err::Failure(err)) => { - parser::error::convert_error(input, err).eprint(Source::from(input.fragment())).unwrap(); + if opt.debug { + println!("{err:#?}"); + } + parser::error::convert_error(input, err) + .eprint(Source::from(input.fragment())) + .unwrap(); } - Err(_) => ( unreachable!() ), + Err(_) => (unreachable!()), Ok(res) => { if opt.debug { println!("{:#?}", res); diff --git a/src/parser.rs b/src/parser.rs index 9863628..b29ee38 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,14 +1,14 @@ +pub mod error; +mod literals; pub mod module; pub mod proc; -mod literals; -pub mod error; use nom::{ branch::alt, bytes::complete::tag, character::complete::{alpha1, alphanumeric1, char, multispace0, u64 as decimal}, combinator::{map, opt, recognize}, - error::{ParseError, ErrorKind}, + error::{ErrorKind, ParseError}, multi::{many0, separated_list0}, sequence::{delimited, pair, preceded, separated_pair, terminated, tuple}, }; @@ -22,8 +22,8 @@ pub type IErr = GreedyError; // custom IResult type for VerboseError pub type IResult> = nom::IResult; -use literals::hexadecimal; pub use crate::parser::module::{module, Module, ModuleItem, PortDirection}; +use literals::hexadecimal; fn ws0<'a, F: 'a, O, E: ParseError>>( inner: F, @@ -46,14 +46,12 @@ fn typename(input: Span) -> IResult { map( tuple(( identifier, - opt(delimited(char('<'), ws0(expression), char('>'))) + opt(delimited(char('<'), ws0(expression), char('>'))), )), - |(ident, _)| { - TypeName { - name: ident, - generics: () - } - } + |(ident, _)| TypeName { + name: ident, + generics: (), + }, )(input) } diff --git a/src/parser/error.rs b/src/parser/error.rs index 3360c2e..57c669d 100644 --- a/src/parser/error.rs +++ b/src/parser/error.rs @@ -1,36 +1,29 @@ use std::fmt::Debug; use std::ops::Deref; -use super::{Span, IErr}; +use super::{IErr, Span}; +use ariadne::{Label, Report, ReportKind}; use nom::error::ErrorKind; -use nom_greedyerror::{Position, GreedyErrorKind}; -use ariadne::{Report, ReportKind, Label}; +use nom_greedyerror::{GreedyErrorKind, Position}; fn span_to_range(input: Span) -> std::ops::Range { input.position()..(input.position() + input.len()) } -pub fn convert_error( - input: Span, - e: IErr, -) -> Report { +pub fn convert_error(input: Span, e: IErr) -> Report { let mut labels = Vec::new(); for err in e.errors { let label = match err.1 { GreedyErrorKind::Context(ctx) => { - Label::new(span_to_range(err.0)) - .with_message(format!("in {ctx}")) - }, - GreedyErrorKind::Char(c) => { - Label::new(err.0.position()..err.0.position()) - .with_message(format!("expected {c:?}")) - }, + Label::new(span_to_range(err.0)).with_message(format!("in {ctx}")) + } + GreedyErrorKind::Char(c) => Label::new(err.0.position()..err.0.position()) + .with_message(format!("expected {c:?}")), GreedyErrorKind::Nom(_) => todo!(), }; labels.push(label); } - let mut rep = Report::build(ReportKind::Error, (), 0) - .with_message("Parse Error"); + let mut rep = Report::build(ReportKind::Error, (), 0).with_message("Parse Error"); for lbl in labels { rep = rep.with_label(lbl) } diff --git a/src/parser/literals.rs b/src/parser/literals.rs index 403d1fd..763b3b2 100644 --- a/src/parser/literals.rs +++ b/src/parser/literals.rs @@ -17,7 +17,8 @@ pub fn hexadecimal(input: Span) -> IResult { ))), ), |out: Span| { - u64::from_str_radix(&str::replace(out.fragment(), "_", ""), 16).expect("error parsing literal") + u64::from_str_radix(&str::replace(out.fragment(), "_", ""), 16) + .expect("error parsing literal") }, )(input) } diff --git a/src/parser/module.rs b/src/parser/module.rs index 5648602..bae6009 100644 --- a/src/parser/module.rs +++ b/src/parser/module.rs @@ -5,13 +5,13 @@ use nom::{ combinator::{consumed, map}, error::context, multi::{many0, separated_list0}, - sequence::{delimited, terminated, tuple, preceded}, + sequence::{delimited, preceded, terminated, tuple}, }; use crate::parser::{ assign_statement, declaration, identifier, proc::{proc_block, ProcBlock}, - ws0, Assign, IResult, NetDecl, Span, typename + typename, ws0, Assign, IResult, NetDecl, Span, }; #[derive(Debug)] @@ -41,16 +41,11 @@ pub enum ModuleItem<'a> { } fn port_decl(i: Span) -> IResult { - map( - consumed( - declaration, - ), - |(pos, net)| PortDecl { - pos, - direction: PortDirection::Input, - net, - }, - )(i) + map(consumed(declaration), |(pos, net)| PortDecl { + pos, + direction: PortDirection::Input, + net, + })(i) } fn inputs_list(input: Span) -> IResult> { @@ -85,7 +80,11 @@ pub fn module(input: Span) -> IResult { ws0(identifier), ws0(delimited(char('('), ws0(inputs_list), char(')'))), ws0(preceded(tag("->"), ws0(typename))), - ws0(delimited(char('{'), ws0(many0(ws0(module_item))), char('}'))), + ws0(delimited( + char('{'), + ws0(many0(ws0(module_item))), + char('}'), + )), )), |(_, name, inputs, ret, items)| Module { name,