Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit fa25bad

Browse files
don't use #function in errors
1 parent 21f0682 commit fa25bad

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ edition = "2021"
99
num = "0.4"
1010
clap = { version = "3.1.8", features = ["derive"] }
1111
chrono = "0.4"
12-
function_name = "0.3.0"
1312
itertools = "0.10.3"

src/vcd/parse/metadata.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use chrono::prelude::*;
22
use itertools::Itertools;
3-
use function_name::named;
43

54
use super::*;
65

7-
#[named]
86
pub(super) fn parse_date(
97
word_and_ctx1 : (&str, &Cursor),
108
word_and_ctx2 : (&str, &Cursor),
@@ -19,7 +17,8 @@ pub(super) fn parse_date(
1917

2018
let days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
2119
if !days.contains(&word) {
22-
let msg = format!("reached end of file without parser leaving {}\n", function_name!());
20+
let msg = format!("Error near {}:{}. Reached end of file without \
21+
terminating parser", file!(), line!());
2322
let msg2 = format!("{word} is not a valid weekday : expected one of {days:?}\n");
2423
let msg3 = format!("failure location: {cursor:?}");
2524
return Err(format!("{}{}{}", msg, msg2, msg3))
@@ -39,7 +38,8 @@ pub(super) fn parse_date(
3938
];
4039

4140
if !months.contains(&word) {
42-
let msg = format!("reached end of file without parser leaving {}\n", function_name!());
41+
let msg = format!("Error near {}:{}. Reached end of file without \
42+
terminating parser", file!(), line!());
4343
let msg2 = format!("{word} is not a valid month : expected one of {months:?}\n");
4444
let msg3 = format!("failure location: {cursor:?}");
4545
return Err(format!("{}{}{}", msg, msg2, msg3))
@@ -58,7 +58,8 @@ pub(super) fn parse_date(
5858
};
5959

6060
if date > 31 {
61-
let msg = format!("reached end of file without parser leaving {}\n", function_name!());
61+
let msg = format!("Error near {}:{}. Reached end of file without \
62+
terminating parser", file!(), line!());
6263
let msg2 = format!("{word} is not a valid date : must be between 0 and 31\n");
6364
let msg3 = format!("failure location: {cursor:?}");
6465
return Err(format!("{}{}{}", msg, msg2, msg3))
@@ -79,7 +80,7 @@ pub(super) fn parse_date(
7980
.map_err(|_| "failed to parse".to_string())?;
8081

8182
if hh > 23 {
82-
let msg = format!("reached end of file without parser leaving {}\n", function_name!());
83+
let msg = format!("Error near {}:{}.", file!(), line!());
8384
let msg2 = format!("{hh} is not a valid hour : must be between 0 and 23\n");
8485
let msg3 = format!("failure location: {cursor:?}");
8586
return Err(format!("{}{}{}", msg, msg2, msg3))
@@ -94,7 +95,7 @@ pub(super) fn parse_date(
9495
.map_err(|_| "failed to parse".to_string())?;
9596

9697
if mm > 60 {
97-
let msg = format!("reached end of file without parser leaving {}\n", function_name!());
98+
let msg = format!("Error near {}:{}.", file!(), line!());
9899
let msg2 = format!("{mm} is not a valid minute : must be between 0 and 60\n");
99100
let msg3 = format!("failure location: {cursor:?}");
100101
return Err(format!("{}{}{}", msg, msg2, msg3))
@@ -109,7 +110,7 @@ pub(super) fn parse_date(
109110
.map_err(|_| "failed to parse".to_string())?;
110111

111112
if ss > 60 {
112-
let msg = format!("reached end of file without parser leaving {}\n", function_name!());
113+
let msg = format!("Error near {}:{}.", file!(), line!());
113114
let msg2 = format!("{ss} is not a valid second : must be between 0 and 60\n");
114115
let msg3 = format!("failure location: {cursor:?}");
115116
return Err(format!("{}{}{}", msg, msg2, msg3))
@@ -135,7 +136,6 @@ pub(super) fn parse_date(
135136

136137
}
137138

138-
#[named]
139139
pub(super) fn parse_version(word_reader : &mut WordReader) -> Result<Version, String> {
140140
let mut version = String::new();
141141

@@ -144,7 +144,9 @@ pub(super) fn parse_version(word_reader : &mut WordReader) -> Result<Version, St
144144

145145
// if there isn't another word left in the file, then we exit
146146
if word.is_none() {
147-
return Err(format!("reached end of file without parser leaving {}", function_name!()))
147+
let msg = format!("Error near {}:{}. Reached end of file without \
148+
terminating parser", file!(), line!());
149+
return Err(msg)
148150
}
149151

150152
let (word, _) = word.unwrap();
@@ -162,9 +164,9 @@ pub(super) fn parse_version(word_reader : &mut WordReader) -> Result<Version, St
162164
}
163165
}
164166

165-
#[named]
166167
pub(super) fn parse_timescale(word_reader : &mut WordReader) -> Result<(Option<u32>, Timescale), String> {
167-
let err_msg = format!("failed in {}", function_name!());
168+
let err_msg = format!("Error near {}:{}. No more words left in vcd file.",
169+
file!(), line!());
168170

169171
// we might see `scalarunit $end` or `scalar unit $end`
170172

@@ -214,9 +216,9 @@ pub(super) fn parse_timescale(word_reader : &mut WordReader) -> Result<(Option<u
214216

215217
}
216218

217-
#[named]
218219
pub(super) fn parse_metadata(word_reader : &mut WordReader) -> Result<Metadata, String> {
219-
let err_msg = format!("reached end of file without parser leaving {}", function_name!());
220+
let err_msg = format!("Error near {}:{}. No more words left in vcd file.",
221+
file!(), line!());
220222

221223
let mut metadata = Metadata {
222224
date : None,
@@ -234,7 +236,6 @@ pub(super) fn parse_metadata(word_reader : &mut WordReader) -> Result<Metadata,
234236
"$" => {
235237
match residual {
236238
"date" => {
237-
let err_msg = format!("reached end of file without parser leaving {}", function_name!());
238239
// a date is typically composed of the 5 following words which can
239240
// occur in any order:
240241
// {Day, Month, Date(number in month), hh:mm:ss, year}.

src/vcd/parse/scopes.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
//! part of the vcd parser that handles parsing the signal tree and
22
//! building the resulting signal tree
3-
use function_name::named;
4-
53
use super::*;
64

7-
#[named]
85
pub(super) fn parse_var<'a>(
96
word_reader : &mut WordReader,
107
parent_scope_idx : ScopeIdx,
118
vcd : &'a mut VCD,
129
signal_map : &mut HashMap<String, SignalIdx>
1310
) -> Result<(), String> {
14-
let err = format!("reached end of file without parser leaving {}", function_name!());
11+
let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!());
1512
let (word, cursor) = word_reader.next_word().ok_or(&err)?;
1613
let expected_types = ["integer", "parameter", "real", "reg", "string", "wire", "tri1", "time"];
1714

@@ -53,7 +50,6 @@ pub(super) fn parse_var<'a>(
5350
// ^ - signal_alias
5451
let (word, _) = word_reader.next_word().ok_or(&err)?;
5552
let signal_alias = word.to_string();
56-
// dbg!(&signal_alias);
5753

5854
// $var parameter 3 a IDLE $end
5955
// ^^^^ - full_signal_name(can extend until $end)
@@ -153,10 +149,8 @@ fn parse_orphaned_vars<'a>(
153149

154150
// we shouldn't reach the end of the file here...
155151
if next_word.is_none() {
156-
let (f, l )= (file!(), line!());
157-
let msg = format!("Error near {f}:{l}.\
158-
Reached end of file without terminating parser");
159-
Err(msg)?;
152+
let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!());
153+
Err(err)?;
160154
};
161155

162156
let (word, cursor) = next_word.unwrap();
@@ -178,7 +172,6 @@ fn parse_orphaned_vars<'a>(
178172
Ok(())
179173
}
180174

181-
#[named]
182175
pub(super) fn parse_signal_tree<'a>(
183176
word_reader : &mut WordReader,
184177
parent_scope_idx : Option<ScopeIdx>,
@@ -188,7 +181,7 @@ pub(super) fn parse_signal_tree<'a>(
188181

189182
// $scope module reg_mag_i $end
190183
// ^^^^^^ - module keyword
191-
let err = format!("reached end of file without parser leaving {}", function_name!());
184+
let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!());
192185
let (keyword, cursor) = word_reader.next_word().ok_or(&err)?;
193186

194187
let expected = ["module", "begin", "task", "function"];
@@ -233,7 +226,6 @@ pub(super) fn parse_signal_tree<'a>(
233226
// ^^^^ - end keyword
234227
ident(word_reader, "$end")?;
235228

236-
let err = format!("reached end of file without parser leaving {}", function_name!());
237229
loop {
238230
let (word, cursor) = word_reader.next_word().ok_or(&err)?;
239231
let ParseResult{matched, residual} = tag(word, "$");
@@ -274,26 +266,22 @@ pub(super) fn parse_signal_tree<'a>(
274266
Ok(())
275267
}
276268

277-
#[named]
278269
pub(super) fn parse_scopes<'a>(
279270
word_reader : &mut WordReader,
280271
vcd : &'a mut VCD,
281272
signal_map : &mut HashMap<String, SignalIdx>
282273
) -> Result<(), String> {
283274
// get the current word
284-
let (f, l ) = (file!(), line!());
285-
let msg = format!("Error near {f}:{l}. Current word empty!");
286-
let (word, _) = word_reader.curr_word().ok_or(msg)?;
275+
let err = format!("Error near {}:{}. No more words left in vcd file.", file!(), line!());
276+
let (word, _) = word_reader.curr_word().ok_or(&err)?;
287277

288278
// we may have orphaned vars that occur before the first scope
289279
if word == "$var" {
290280
parse_orphaned_vars(word_reader, vcd, signal_map)?;
291281
}
292282

293283
// get the current word
294-
let (f, l ) = (file!(), line!());
295-
let msg = format!("Error near {f}:{l}. Current word empty!");
296-
let (word, cursor) = word_reader.curr_word().ok_or(msg)?;
284+
let (word, cursor) = word_reader.curr_word().ok_or(&err)?;
297285

298286
// the current word should be "scope", as `parse_orphaned_vars`(if it
299287
// was called), should have terminated upon encountering "$scope".
@@ -302,14 +290,14 @@ pub(super) fn parse_scopes<'a>(
302290
if word != "$scope" {
303291
let (f, l )= (file!(), line!());
304292
let msg = format!("Error near {f}:{l}.\
305-
Expected $scope or $var, found {word} at {cursor:?}");
293+
Expected $scope or $var, found {word} at {cursor:?}");
306294
return Err(msg)
307295
}
308296

309297
// now for the interesting part
310298
parse_signal_tree(word_reader, None, vcd, signal_map)?;
311299

312-
let err = format!("reached end of file without parser leaving {}", function_name!());
300+
// let err = format!("reached end of file without parser leaving {}", function_name!());
313301
let expected_keywords = ["$scope", "$enddefinitions"];
314302

315303
// there could be multiple signal trees, and unfortunately, we

0 commit comments

Comments
 (0)