From fa25bad3913fb942f5bff5cae5af7b3fa489d194 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 4 Aug 2022 11:36:26 -0400 Subject: [PATCH] don't use #function in errors --- Cargo.toml | 1 - src/vcd/parse/metadata.rs | 31 ++++++++++++++++--------------- src/vcd/parse/scopes.rs | 30 +++++++++--------------------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1c9d90..0f04e45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,4 @@ edition = "2021" num = "0.4" clap = { version = "3.1.8", features = ["derive"] } chrono = "0.4" -function_name = "0.3.0" itertools = "0.10.3" \ No newline at end of file diff --git a/src/vcd/parse/metadata.rs b/src/vcd/parse/metadata.rs index ef6ac5a..08cfd22 100644 --- a/src/vcd/parse/metadata.rs +++ b/src/vcd/parse/metadata.rs @@ -1,10 +1,8 @@ use chrono::prelude::*; use itertools::Itertools; -use function_name::named; use super::*; -#[named] pub(super) fn parse_date( word_and_ctx1 : (&str, &Cursor), word_and_ctx2 : (&str, &Cursor), @@ -19,7 +17,8 @@ pub(super) fn parse_date( let days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; if !days.contains(&word) { - let msg = format!("reached end of file without parser leaving {}\n", function_name!()); + let msg = format!("Error near {}:{}. Reached end of file without \ + terminating parser", file!(), line!()); let msg2 = format!("{word} is not a valid weekday : expected one of {days:?}\n"); let msg3 = format!("failure location: {cursor:?}"); return Err(format!("{}{}{}", msg, msg2, msg3)) @@ -39,7 +38,8 @@ pub(super) fn parse_date( ]; if !months.contains(&word) { - let msg = format!("reached end of file without parser leaving {}\n", function_name!()); + let msg = format!("Error near {}:{}. Reached end of file without \ + terminating parser", file!(), line!()); let msg2 = format!("{word} is not a valid month : expected one of {months:?}\n"); let msg3 = format!("failure location: {cursor:?}"); return Err(format!("{}{}{}", msg, msg2, msg3)) @@ -58,7 +58,8 @@ pub(super) fn parse_date( }; if date > 31 { - let msg = format!("reached end of file without parser leaving {}\n", function_name!()); + let msg = format!("Error near {}:{}. Reached end of file without \ + terminating parser", file!(), line!()); let msg2 = format!("{word} is not a valid date : must be between 0 and 31\n"); let msg3 = format!("failure location: {cursor:?}"); return Err(format!("{}{}{}", msg, msg2, msg3)) @@ -79,7 +80,7 @@ pub(super) fn parse_date( .map_err(|_| "failed to parse".to_string())?; if hh > 23 { - let msg = format!("reached end of file without parser leaving {}\n", function_name!()); + let msg = format!("Error near {}:{}.", file!(), line!()); let msg2 = format!("{hh} is not a valid hour : must be between 0 and 23\n"); let msg3 = format!("failure location: {cursor:?}"); return Err(format!("{}{}{}", msg, msg2, msg3)) @@ -94,7 +95,7 @@ pub(super) fn parse_date( .map_err(|_| "failed to parse".to_string())?; if mm > 60 { - let msg = format!("reached end of file without parser leaving {}\n", function_name!()); + let msg = format!("Error near {}:{}.", file!(), line!()); let msg2 = format!("{mm} is not a valid minute : must be between 0 and 60\n"); let msg3 = format!("failure location: {cursor:?}"); return Err(format!("{}{}{}", msg, msg2, msg3)) @@ -109,7 +110,7 @@ pub(super) fn parse_date( .map_err(|_| "failed to parse".to_string())?; if ss > 60 { - let msg = format!("reached end of file without parser leaving {}\n", function_name!()); + let msg = format!("Error near {}:{}.", file!(), line!()); let msg2 = format!("{ss} is not a valid second : must be between 0 and 60\n"); let msg3 = format!("failure location: {cursor:?}"); return Err(format!("{}{}{}", msg, msg2, msg3)) @@ -135,7 +136,6 @@ pub(super) fn parse_date( } -#[named] pub(super) fn parse_version(word_reader : &mut WordReader) -> Result { let mut version = String::new(); @@ -144,7 +144,9 @@ pub(super) fn parse_version(word_reader : &mut WordReader) -> Result Result Result<(Option, Timescale), String> { - let err_msg = format!("failed in {}", function_name!()); + let err_msg = format!("Error near {}:{}. No more words left in vcd file.", + file!(), line!()); // we might see `scalarunit $end` or `scalar unit $end` @@ -214,9 +216,9 @@ pub(super) fn parse_timescale(word_reader : &mut WordReader) -> Result<(Option Result { - let err_msg = format!("reached end of file without parser leaving {}", function_name!()); + let err_msg = format!("Error near {}:{}. No more words left in vcd file.", + file!(), line!()); let mut metadata = Metadata { date : None, @@ -234,7 +236,6 @@ pub(super) fn parse_metadata(word_reader : &mut WordReader) -> Result { match residual { "date" => { - let err_msg = format!("reached end of file without parser leaving {}", function_name!()); // a date is typically composed of the 5 following words which can // occur in any order: // {Day, Month, Date(number in month), hh:mm:ss, year}. diff --git a/src/vcd/parse/scopes.rs b/src/vcd/parse/scopes.rs index 3a65f6c..4e43a36 100644 --- a/src/vcd/parse/scopes.rs +++ b/src/vcd/parse/scopes.rs @@ -1,17 +1,14 @@ //! part of the vcd parser that handles parsing the signal tree and //! building the resulting signal tree -use function_name::named; - use super::*; -#[named] pub(super) fn parse_var<'a>( word_reader : &mut WordReader, parent_scope_idx : ScopeIdx, vcd : &'a mut VCD, signal_map : &mut HashMap ) -> Result<(), String> { - let err = format!("reached end of file without parser leaving {}", function_name!()); + let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!()); let (word, cursor) = word_reader.next_word().ok_or(&err)?; let expected_types = ["integer", "parameter", "real", "reg", "string", "wire", "tri1", "time"]; @@ -53,7 +50,6 @@ pub(super) fn parse_var<'a>( // ^ - signal_alias let (word, _) = word_reader.next_word().ok_or(&err)?; let signal_alias = word.to_string(); - // dbg!(&signal_alias); // $var parameter 3 a IDLE $end // ^^^^ - full_signal_name(can extend until $end) @@ -153,10 +149,8 @@ fn parse_orphaned_vars<'a>( // we shouldn't reach the end of the file here... if next_word.is_none() { - let (f, l )= (file!(), line!()); - let msg = format!("Error near {f}:{l}.\ - Reached end of file without terminating parser"); - Err(msg)?; + let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!()); + Err(err)?; }; let (word, cursor) = next_word.unwrap(); @@ -178,7 +172,6 @@ fn parse_orphaned_vars<'a>( Ok(()) } -#[named] pub(super) fn parse_signal_tree<'a>( word_reader : &mut WordReader, parent_scope_idx : Option, @@ -188,7 +181,7 @@ pub(super) fn parse_signal_tree<'a>( // $scope module reg_mag_i $end // ^^^^^^ - module keyword - let err = format!("reached end of file without parser leaving {}", function_name!()); + let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!()); let (keyword, cursor) = word_reader.next_word().ok_or(&err)?; let expected = ["module", "begin", "task", "function"]; @@ -233,7 +226,6 @@ pub(super) fn parse_signal_tree<'a>( // ^^^^ - end keyword ident(word_reader, "$end")?; - let err = format!("reached end of file without parser leaving {}", function_name!()); loop { let (word, cursor) = word_reader.next_word().ok_or(&err)?; let ParseResult{matched, residual} = tag(word, "$"); @@ -274,16 +266,14 @@ pub(super) fn parse_signal_tree<'a>( Ok(()) } -#[named] pub(super) fn parse_scopes<'a>( word_reader : &mut WordReader, vcd : &'a mut VCD, signal_map : &mut HashMap ) -> Result<(), String> { // get the current word - let (f, l ) = (file!(), line!()); - let msg = format!("Error near {f}:{l}. Current word empty!"); - let (word, _) = word_reader.curr_word().ok_or(msg)?; + let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!()); + let (word, _) = word_reader.curr_word().ok_or(&err)?; // we may have orphaned vars that occur before the first scope if word == "$var" { @@ -291,9 +281,7 @@ pub(super) fn parse_scopes<'a>( } // get the current word - let (f, l ) = (file!(), line!()); - let msg = format!("Error near {f}:{l}. Current word empty!"); - let (word, cursor) = word_reader.curr_word().ok_or(msg)?; + let (word, cursor) = word_reader.curr_word().ok_or(&err)?; // the current word should be "scope", as `parse_orphaned_vars`(if it // was called), should have terminated upon encountering "$scope". @@ -302,14 +290,14 @@ pub(super) fn parse_scopes<'a>( if word != "$scope" { let (f, l )= (file!(), line!()); let msg = format!("Error near {f}:{l}.\ - Expected $scope or $var, found {word} at {cursor:?}"); + Expected $scope or $var, found {word} at {cursor:?}"); return Err(msg) } // now for the interesting part parse_signal_tree(word_reader, None, vcd, signal_map)?; - let err = format!("reached end of file without parser leaving {}", function_name!()); + // let err = format!("reached end of file without parser leaving {}", function_name!()); let expected_keywords = ["$scope", "$enddefinitions"]; // there could be multiple signal trees, and unfortunately, we