git.delta.rocks / jrsonnet / refs/commits / 708403715eb7

difftreelog

Merge pull request #58 from CertainLach/fix/number-parsing

Yaroslav Bolyukin2021-08-14parents: #5e5ab6b #fc291eb.patch.diff
in: master
Fix number parsing

3 files changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -131,8 +131,8 @@
 
 fn main_real(state: &EvaluationState, opts: Opts) -> Result<(), Error> {
 	opts.gc.configure_global();
-	opts.general.configure(&state)?;
-	opts.manifest.configure(&state)?;
+	opts.general.configure(state)?;
+	opts.manifest.configure(state)?;
 
 	let val = if opts.input.exec {
 		state.evaluate_snippet_raw(
@@ -158,7 +158,7 @@
 		}
 		for (file, data) in state.manifest_multi(val)?.iter() {
 			let mut path = multi.clone();
-			path.push(&file as &str);
+			path.push(file as &str);
 			if opts.output.create_output_dirs {
 				let mut dir = path.clone();
 				dir.pop();
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
189#[macro_export]189#[macro_export]
190macro_rules! throw {190macro_rules! throw {
191 ($e: expr) => {191 ($e: expr) => {
192 return Err($e.into());192 return Err($e.into())
193 };193 };
194}194}
195195
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -44,9 +44,9 @@
 		rule digit() -> char = d:$(['0'..='9']) {d.chars().next().unwrap()}
 		rule end_of_ident() = !['0'..='9' | '_' | 'a'..='z' | 'A'..='Z']
 		/// Sequence of digits
-		rule uint() -> u64 = a:$(digit()+) { a.parse().unwrap() }
+		rule uint_str() -> &'input str = a:$(digit()+) { a }
 		/// Number in scientific notation format
-		rule number() -> f64 = quiet!{a:$(uint() ("." uint())? (['e'|'E'] (s:['+'|'-'])? uint())?) { a.parse().unwrap() }} / expected!("<number>")
+		rule number() -> f64 = quiet!{a:$(uint_str() ("." uint_str())? (['e'|'E'] (s:['+'|'-'])? uint_str())?) {? a.parse().map_err(|_| "<number>") }} / expected!("<number>")
 
 		/// Reserved word followed by any non-alphanumberic
 		rule reserved() = ("assert" / "else" / "error" / "false" / "for" / "function" / "if" / "import" / "importstr" / "in" / "local" / "null" / "tailstrict" / "then" / "self" / "super" / "true") end_of_ident()