don't use #function in errors
This commit is contained in:
parent
21f0682500
commit
fa25bad391
|
@ -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"
|
|
@ -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<Version, String> {
|
||||
let mut version = String::new();
|
||||
|
||||
|
@ -144,7 +144,9 @@ pub(super) fn parse_version(word_reader : &mut WordReader) -> Result<Version, St
|
|||
|
||||
// if there isn't another word left in the file, then we exit
|
||||
if word.is_none() {
|
||||
return Err(format!("reached end of file without parser leaving {}", function_name!()))
|
||||
let msg = format!("Error near {}:{}. Reached end of file without \
|
||||
terminating parser", file!(), line!());
|
||||
return Err(msg)
|
||||
}
|
||||
|
||||
let (word, _) = word.unwrap();
|
||||
|
@ -162,9 +164,9 @@ pub(super) fn parse_version(word_reader : &mut WordReader) -> Result<Version, St
|
|||
}
|
||||
}
|
||||
|
||||
#[named]
|
||||
pub(super) fn parse_timescale(word_reader : &mut WordReader) -> Result<(Option<u32>, 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<u
|
|||
|
||||
}
|
||||
|
||||
#[named]
|
||||
pub(super) fn parse_metadata(word_reader : &mut WordReader) -> Result<Metadata, String> {
|
||||
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<Metadata,
|
|||
"$" => {
|
||||
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}.
|
||||
|
|
|
@ -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<String, SignalIdx>
|
||||
) -> 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<ScopeIdx>,
|
||||
|
@ -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<String, SignalIdx>
|
||||
) -> 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".
|
||||
|
@ -309,7 +297,7 @@ pub(super) fn parse_scopes<'a>(
|
|||
// 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
|
||||
|
|
Loading…
Reference in a new issue