From 708403715eb718a419d9db2c532d635693425871 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sat, 14 Aug 2021 17:10:30 +0000 Subject: [PATCH] Merge pull request #58 from CertainLach/fix/number-parsing Fix number parsing --- --- 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(); --- a/crates/jrsonnet-evaluator/src/error.rs +++ b/crates/jrsonnet-evaluator/src/error.rs @@ -189,6 +189,6 @@ #[macro_export] macro_rules! throw { ($e: expr) => { - return Err($e.into()); + return Err($e.into()) }; } --- 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!("") + rule number() -> f64 = quiet!{a:$(uint_str() ("." uint_str())? (['e'|'E'] (s:['+'|'-'])? uint_str())?) {? a.parse().map_err(|_| "") }} / expected!("") /// 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() -- gitstuff