diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3bc0d541da69e170f19c2bebe2066fbe984db98b --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_cargo_crate("lib") { + crate_name = "cexpr" + crate_type = "rlib" + crate_root = "src/lib.rs" + + sources = ["src/lib.rs"] + edition = "2018" + cargo_pkg_version = "0.5.0" + cargo_pkg_authors = "Jethro Beekman " + cargo_pkg_name = "cexpr" + cargo_pkg_description = "A C expression parser and evaluator" + deps = ["//third_party/rust/crates/nom:lib"] +} diff --git a/src/expr.rs b/src/expr.rs index 5dce3c78cfa131fd2403280770f4326630651740..7f7e458bd4639b2f1ff27673639996709e015754 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -308,7 +308,7 @@ impl<'a> PRef<'a> { pair(complete(one_of_punctuation(&["*", "/", "%"][..])), |i| { self.unary(i) }), - acc, + move || acc.clone(), |mut acc, (op, val): (&[u8], EvalResult)| { match op[0] as char { '*' => acc *= &val, @@ -327,7 +327,7 @@ impl<'a> PRef<'a> { pair(complete(one_of_punctuation(&["+", "-"][..])), |i| { self.mul_div_rem(i) }), - acc, + move || acc.clone(), |mut acc, (op, val): (&[u8], EvalResult)| { match op[0] as char { '+' => acc += &val, @@ -345,7 +345,7 @@ impl<'a> PRef<'a> { pair(complete(one_of_punctuation(&["<<", ">>"][..])), |i| { self.add_sub(i) }), - acc, + move || acc.clone(), |mut acc, (op, val): (&[u8], EvalResult)| { match op { b"<<" => acc <<= &val, @@ -361,7 +361,7 @@ impl<'a> PRef<'a> { let (input, acc) = self.shl_shr(input)?; numeric(fold_many0( preceded(complete(p("&")), |i| self.shl_shr(i)), - acc, + move || acc.clone(), |mut acc, val: EvalResult| { acc &= &val; acc @@ -373,7 +373,7 @@ impl<'a> PRef<'a> { let (input, acc) = self.and(input)?; numeric(fold_many0( preceded(complete(p("^")), |i| self.and(i)), - acc, + move || acc.clone(), |mut acc, val: EvalResult| { acc ^= &val; acc @@ -385,7 +385,7 @@ impl<'a> PRef<'a> { let (input, acc) = self.xor(input)?; numeric(fold_many0( preceded(complete(p("|")), |i| self.xor(i)), - acc, + move || acc.clone(), |mut acc, val: EvalResult| { acc |= &val; acc diff --git a/src/literal.rs b/src/literal.rs index b74699f87f92fa5310b05a99c2660f96df709c8a..68e85c7dadbd0d9e4a13dd2bc168a98941b73dae 100644 --- a/src/literal.rs +++ b/src/literal.rs @@ -224,7 +224,7 @@ fn c_string(i: &[u8]) -> nom::IResult<&[u8], Vec> { map(escaped_char, |c: CChar| c.into()), map(is_not([b'\\', b'"']), |c: &[u8]| c.into()), )), - Vec::new(), + Vec::new, |mut v: Vec, res: Vec| { v.extend_from_slice(&res); v