git.delta.rocks / jrsonnet / refs/commits / 2d81df4933d9

difftreelog

feat enhance messages of intensified numeric parsers

Petr Portnov2022-11-23parent: #398f421.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
82 if first_char == '-' {82 if first_char == '-' {
83 let remaining = chars.as_str();83 let remaining = chars.as_str();
84 if remaining.is_empty() {84 if remaining.is_empty() {
85 throw!("Not an integer: \"{}\"", raw);85 throw!("Integer only consists of a minus");
86 }86 }
87 parse_nat::<10>(remaining).map(|value| -value)87 parse_nat::<10>(remaining).map(|value| -value)
88 } else {88 } else {
89 parse_nat::<10>(raw.as_str())89 parse_nat::<10>(raw.as_str())
90 }90 }
91 } else {91 } else {
92 throw!("Not an integer: \"{}\"", raw);92 throw!("Empty decimal integer \"{}\"", raw);
93 }93 }
94}94}
9595
96#[builtin]96#[builtin]
97pub fn builtin_parse_octal(raw: IStr) -> Result<f64> {97pub fn builtin_parse_octal(raw: IStr) -> Result<f64> {
98 if raw.is_empty() {98 if raw.is_empty() {
99 throw!("Not an octal number: \"\"");99 throw!("Empty octal integer");
100 }100 }
101101
102 parse_nat::<8>(raw.as_str())102 parse_nat::<8>(raw.as_str())
105#[builtin]105#[builtin]
106pub fn builtin_parse_hex(raw: IStr) -> Result<f64> {106pub fn builtin_parse_hex(raw: IStr) -> Result<f64> {
107 if raw.is_empty() {107 if raw.is_empty() {
108 throw!("Not hexadecimal: \"\"");108 throw!("Empty hexadecimal integer");
109 }109 }
110110
111 parse_nat::<16>(raw.as_str())111 parse_nat::<16>(raw.as_str())
145 if digit < BASE {145 if digit < BASE {
146 Ok(base * aggregate + digit as f64)146 Ok(base * aggregate + digit as f64)
147 } else {147 } else {
148 throw!("{raw} is not a base {BASE} integer",);148 throw!("\"{raw}\" is not a base {BASE} integer",);
149 }149 }
150 })150 })
151}151}