Skip to content

Commit bc99916

Browse files
authored
Propagate literal parsing errors (#104)
1 parent dce5b08 commit bc99916

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/verilog.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ fn parse_literal_as_bool(node: RefNode, ast: &sv_parser::SyntaxTree) -> Result<b
8080
RefNode::BinaryValue(b) => {
8181
let loc = b.nodes.0;
8282
let val = ast.get_str(&loc).unwrap();
83-
let num = u64::from_str_radix(val, 2).unwrap();
83+
let num = u64::from_str_radix(val, 2)
84+
.map_err(|_e| format!("Could not parse binary value {val} as bool"))?;
8485
match num {
8586
1 => Ok(true),
8687
0 => Ok(false),
@@ -90,7 +91,8 @@ fn parse_literal_as_bool(node: RefNode, ast: &sv_parser::SyntaxTree) -> Result<b
9091
RefNode::HexValue(b) => {
9192
let loc = b.nodes.0;
9293
let val = ast.get_str(&loc).unwrap();
93-
let num = u64::from_str_radix(val, 16).unwrap();
94+
let num = u64::from_str_radix(val, 16)
95+
.map_err(|_e| format!("Could not parse hex value {val} as bool"))?;
9496
match num {
9597
1 => Ok(true),
9698
0 => Ok(false),
@@ -100,7 +102,9 @@ fn parse_literal_as_bool(node: RefNode, ast: &sv_parser::SyntaxTree) -> Result<b
100102
RefNode::UnsignedNumber(b) => {
101103
let loc = b.nodes.0;
102104
let val = ast.get_str(&loc).unwrap();
103-
let num = val.parse::<u64>().unwrap();
105+
let num = val
106+
.parse::<u64>()
107+
.map_err(|_e| format!("Could not parse decimal value {val} as bool"))?;
104108
match num {
105109
1 => Ok(true),
106110
0 => Ok(false),

0 commit comments

Comments
 (0)