Skip to content

Commit b31c207

Browse files
MarquessVShadow53
andauthored
fix: Parsing programs with integers that overflow a u64 will no longer panic; instead, they will raise an error. (#372)
* fix: Parsing programs with integers that overflow a u64 will no longer panic; instead, they will raise an error. * make MemoryAccess pub to appease clippy * map Co-authored-by: Michael Bryant <[email protected]> * rustfmt --------- Co-authored-by: Michael Bryant <[email protected]>
1 parent 30189fa commit b31c207

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

quil-rs/src/parser/lexer/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ pub enum LexErrorKind {
3333
/// Encountered an unexpected EOF
3434
#[error("unexpected EOF while parsing")]
3535
UnexpectedEOF,
36+
#[error("error parsing an integer: {0}")]
37+
ParseInt(#[from] std::num::ParseIntError),
3638
}

quil-rs/src/parser/lexer/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ fn lex_number(input: LexInput) -> InternalLexResult {
297297
Ok((
298298
input,
299299
match integer_parse_result {
300-
Ok(_) => Token::Integer(float_string.parse::<u64>().unwrap()),
300+
Ok(_) => float_string
301+
.parse::<u64>()
302+
.map(Token::Integer)
303+
.map_err(|e| InternalLexError::from_kind(input, e.into()))
304+
.map_err(nom::Err::Failure)?,
301305
Err(_) => Token::Float(double(float_string)?.1),
302306
},
303307
))

quil-rs/src/program/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub use self::calibration_set::CalibrationSet;
3434
pub use self::error::{disallow_leftover, map_parsed, recover, ParseProgramError, SyntaxError};
3535
pub use self::frame::FrameSet;
3636
pub use self::frame::MatchedFrames;
37-
pub use self::memory::{MemoryAccesses, MemoryRegion};
37+
pub use self::memory::{MemoryAccess, MemoryAccesses, MemoryRegion};
3838

3939
pub mod analysis;
4040
mod calibration;

0 commit comments

Comments
 (0)