diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:43:33 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:43:33 +0000 |
commit | 34682efdb2b56a0db5326f894a165d65c6fe90f9 (patch) | |
tree | 3499aa8558094da40037a517b111c2efd6ea6847 | |
parent | 14d5210b95d9e3686028e10d472f4e9d3b3330aa (diff) | |
parent | 4c814f5cdc1b53fc86bc2de6ec90b7017d25c3d6 (diff) | |
download | cexpr-34682efdb2b56a0db5326f894a165d65c6fe90f9.tar.gz |
Snap for 8730993 from 4c814f5cdc1b53fc86bc2de6ec90b7017d25c3d6 to mainline-tzdata3-releaseaml_tz3_314012070aml_tz3_314012050aml_tz3_314012010aml_tz3_313110000aml_tz3_312511020aml_tz3_312511010aml_tz3_312410020aml_tz3_312410010android12-mainline-tzdata3-releaseaml_tz3_314012010
Change-Id: I896fbd81ced94345d8a61e064eb63a16be1472f1
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 10 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | TEST_MAPPING | 20 | ||||
-rw-r--r-- | cargo2android.json | 4 | ||||
-rw-r--r-- | patches/nom7.patch | 84 | ||||
-rw-r--r-- | src/expr.rs | 69 | ||||
-rw-r--r-- | src/lib.rs | 11 | ||||
-rw-r--r-- | src/literal.rs | 18 |
11 files changed, 69 insertions, 167 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 8481d95..2d990ac 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "6a43efb32cf14b8dc4cd294429d3de259d37e279" + "sha1": "2979eee12f92d1903a53f820664c65735b010e0e" } } @@ -1,5 +1,4 @@ -// This file is generated by cargo2android.py --config cargo2android.json. -// Do not modify this file as changes will be overridden on upgrade. +// This file is generated by cargo2android.py --run --dependencies --device. package { default_applicable_licenses: ["external_rust_crates_cexpr_license"], @@ -41,11 +40,14 @@ rust_library { name: "libcexpr", host_supported: true, crate_name: "cexpr", - cargo_env_compat: true, - cargo_pkg_version: "0.5.0", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ "libnom", ], } + +// dependent_library ["feature_list"] +// memchr-2.3.3 "std,use_std" +// nom-5.1.2 "alloc,std" +// version_check-0.9.2 @@ -13,7 +13,7 @@ [package] edition = "2018" name = "cexpr" -version = "0.5.0" +version = "0.4.0" authors = ["Jethro Beekman <jethro@jbeekman.nl>"] description = "A C expression parser and evaluator" documentation = "https://docs.rs/cexpr/" @@ -21,7 +21,7 @@ keywords = ["C", "expression", "parser"] license = "Apache-2.0/MIT" repository = "https://github.com/jethrogb/rust-cexpr" [dependencies.nom] -version = "7" +version = "5" features = ["std"] default-features = false [dev-dependencies.clang-sys] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index acbe572..d6ab0de 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "cexpr" -version = "0.5.0" +version = "0.4.0" edition = "2018" authors = ["Jethro Beekman <jethro@jbeekman.nl>"] license = "Apache-2.0/MIT" @@ -13,7 +13,7 @@ keywords = ["C","expression","parser"] travis-ci = { repository = "jethrogb/rust-cexpr" } [dependencies] -nom = { version = "6", default-features = false, features = ["std"] } +nom = { version = "5", default-features = false, features = ["std"] } [dev-dependencies] clang-sys = ">= 0.13.0, < 0.29.0" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/cexpr/cexpr-0.5.0.crate" + value: "https://static.crates.io/crates/cexpr/cexpr-0.4.0.crate" } - version: "0.5.0" + version: "0.4.0" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 6 - day: 21 + year: 2020 + month: 3 + day: 31 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index e4ec3b3..6716814 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,24 +1,8 @@ -// Generated by update_crate_tests.py for tests that depend on this crate. +// Generated by cargo2android.py for tests in Android.bp { - "imports": [ - { - "path": "external/rust/crates/libsqlite3-sys" - } - ], "presubmit": [ { - "name": "keystore2_test" - }, - { - "name": "legacykeystore_test" - } - ], - "presubmit-rust": [ - { - "name": "keystore2_test" - }, - { - "name": "legacykeystore_test" + "name": "libsqlite3-sys_device_test_src_lib" } ] } diff --git a/cargo2android.json b/cargo2android.json deleted file mode 100644 index bf78496..0000000 --- a/cargo2android.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "device": true, - "run": true -}
\ No newline at end of file diff --git a/patches/nom7.patch b/patches/nom7.patch deleted file mode 100644 index 5ba703d..0000000 --- a/patches/nom7.patch +++ /dev/null @@ -1,84 +0,0 @@ -diff --git a/Cargo.toml b/Cargo.toml -index 8f6dcc2..a3067d0 100644 ---- a/Cargo.toml -+++ b/Cargo.toml -@@ -21,7 +21,7 @@ keywords = ["C", "expression", "parser"] - license = "Apache-2.0/MIT" - repository = "https://github.com/jethrogb/rust-cexpr" - [dependencies.nom] --version = "6" -+version = "7" - features = ["std"] - default-features = false - [dev-dependencies.clang-sys] -diff --git a/src/expr.rs b/src/expr.rs -index 5dce3c7..7f7e458 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 b74699f..68e85c7 100644 ---- a/src/literal.rs -+++ b/src/literal.rs -@@ -224,7 +224,7 @@ fn c_string(i: &[u8]) -> nom::IResult<&[u8], Vec<u8>> { - map(escaped_char, |c: CChar| c.into()), - map(is_not([b'\\', b'"']), |c: &[u8]| c.into()), - )), -- Vec::new(), -+ Vec::new, - |mut v: Vec<u8>, res: Vec<u8>| { - v.extend_from_slice(&res); - v diff --git a/src/expr.rs b/src/expr.rs index 7f7e458..b1fbfb2 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -31,7 +31,7 @@ use crate::token::{Kind as TokenKind, Token}; use crate::ToCexprResult; use nom::branch::alt; use nom::combinator::{complete, map, map_opt}; -use nom::multi::{fold_many0, many0, separated_list0}; +use nom::multi::{fold_many0, many0, separated_list}; use nom::sequence::{delimited, pair, preceded}; use nom::*; @@ -100,7 +100,7 @@ macro_rules! exact_token ( ($k:ident, $c:expr) => ({ move |input: &[Token]| { if input.is_empty() { - let res: CResult<'_, &[u8]> = Err(crate::nom::Err::Incomplete(Needed::new($c.len()))); + let res: CResult<'_, &[u8]> = Err(crate::nom::Err::Incomplete(Needed::Size($c.len()))); res } else { if input[0].kind==TokenKind::$k && &input[0].raw[..]==$c { @@ -113,16 +113,29 @@ macro_rules! exact_token ( }); ); -fn identifier_token(input: &[Token]) -> CResult<'_, &[u8]> { +macro_rules! typed_token ( + ($k:ident) => ({ + move |input: &[Token]| { + if input.is_empty() { + let res: CResult<'_, &[u8]> = Err(nom::Err::Incomplete(Needed::Size(1))); + res + } else { + if input[0].kind==TokenKind::$k { + Ok((&input[1..], &input[0].raw[..])) + } else { + Err(crate::nom::Err::Error((input, crate::ErrorKind::TypedToken(TokenKind::$k)).into())) + } + } + } + }); +); + +#[allow(dead_code)] +fn any_token(input: &[Token]) -> CResult<'_, &Token> { if input.is_empty() { - let res: CResult<'_, &[u8]> = Err(nom::Err::Incomplete(Needed::new(1))); - res + Err(crate::nom::Err::Incomplete(Needed::Size(1))) } else { - if input[0].kind == TokenKind::Identifier { - Ok((&input[1..], &input[0].raw[..])) - } else { - Err(crate::nom::Err::Error((input, crate::ErrorKind::TypedToken(TokenKind::Identifier)).into())) - } + Ok((&input[1..], &input[0])) } } @@ -138,7 +151,7 @@ fn one_of_punctuation(c: &'static [&'static str]) -> impl Fn(&[Token]) -> CResul .map(|opt| opt.len()) .min() .expect("at least one option"); - Err(crate::nom::Err::Incomplete(Needed::new(min))) + Err(crate::nom::Err::Incomplete(Needed::Size(min))) } else if input[0].kind == TokenKind::Punctuation && c.iter().any(|opt| opt.as_bytes() == &input[0].raw[..]) { @@ -282,9 +295,9 @@ fn unary_op(input: (&[u8], EvalResult)) -> Option<EvalResult> { fn numeric<I: Clone, E: nom::error::ParseError<I>, F>( f: F, -) -> impl FnMut(I) -> nom::IResult<I, EvalResult, E> +) -> impl Fn(I) -> nom::IResult<I, EvalResult, E> where - F: FnMut(I) -> nom::IResult<I, EvalResult, E>, + F: Fn(I) -> nom::IResult<I, EvalResult, E>, { nom::combinator::map_opt(f, EvalResult::as_numeric) } @@ -308,7 +321,7 @@ impl<'a> PRef<'a> { pair(complete(one_of_punctuation(&["*", "/", "%"][..])), |i| { self.unary(i) }), - move || acc.clone(), + acc, |mut acc, (op, val): (&[u8], EvalResult)| { match op[0] as char { '*' => acc *= &val, @@ -327,7 +340,7 @@ impl<'a> PRef<'a> { pair(complete(one_of_punctuation(&["+", "-"][..])), |i| { self.mul_div_rem(i) }), - move || acc.clone(), + acc, |mut acc, (op, val): (&[u8], EvalResult)| { match op[0] as char { '+' => acc += &val, @@ -345,7 +358,7 @@ impl<'a> PRef<'a> { pair(complete(one_of_punctuation(&["<<", ">>"][..])), |i| { self.add_sub(i) }), - move || acc.clone(), + acc, |mut acc, (op, val): (&[u8], EvalResult)| { match op { b"<<" => acc <<= &val, @@ -361,7 +374,7 @@ impl<'a> PRef<'a> { let (input, acc) = self.shl_shr(input)?; numeric(fold_many0( preceded(complete(p("&")), |i| self.shl_shr(i)), - move || acc.clone(), + acc, |mut acc, val: EvalResult| { acc &= &val; acc @@ -373,7 +386,7 @@ impl<'a> PRef<'a> { let (input, acc) = self.and(input)?; numeric(fold_many0( preceded(complete(p("^")), |i| self.and(i)), - move || acc.clone(), + acc, |mut acc, val: EvalResult| { acc ^= &val; acc @@ -385,7 +398,7 @@ impl<'a> PRef<'a> { let (input, acc) = self.xor(input)?; numeric(fold_many0( preceded(complete(p("|")), |i| self.xor(i)), - move || acc.clone(), + acc, |mut acc, val: EvalResult| { acc |= &val; acc @@ -406,7 +419,7 @@ impl<'a> PRef<'a> { impl<'a> PRef<'a> { fn identifier(self, input: &'_ [Token]) -> CResult<'_, EvalResult> { match input.split_first() { - None => Err(Err::Incomplete(Needed::new(1))), + None => Err(Err::Incomplete(Needed::Size(1))), Some(( &Token { kind: TokenKind::Identifier, @@ -430,7 +443,7 @@ impl<'a> PRef<'a> { fn literal(self, input: &'_ [Token]) -> CResult<'_, EvalResult> { match input.split_first() { - None => Err(Err::Incomplete(Needed::new(1))), + None => Err(Err::Incomplete(Needed::Size(1))), Some(( &Token { kind: TokenKind::Literal, @@ -483,7 +496,7 @@ impl<'a> PRef<'a> { } fn macro_definition(self, input: &'_ [Token]) -> CResult<'_, (&'_ [u8], EvalResult)> { - pair(identifier_token, |i| self.expr(i))(input) + pair(typed_token!(Identifier), |i| self.expr(i))(input) } } @@ -506,7 +519,7 @@ impl<'ident> IdentifierParser<'ident> { IdentifierParser { identifiers } } - /// Parse and evaluate an expression of a list of tokens. + /// Parse and evalute an expression of a list of tokens. /// /// Returns an error if the input is not a valid expression or if the token /// stream contains comments, keywords or unknown identifiers. @@ -514,7 +527,7 @@ impl<'ident> IdentifierParser<'ident> { self.as_ref().expr(input) } - /// Parse and evaluate a macro definition from a list of tokens. + /// Parse and evaluate a macro definition from of a list of tokens. /// /// Returns the identifier for the macro and its replacement evaluated as an /// expression. The input should not include `#define`. @@ -539,7 +552,7 @@ impl<'ident> IdentifierParser<'ident> { } } -/// Parse and evaluate an expression of a list of tokens. +/// Parse and evalute an expression of a list of tokens. /// /// Returns an error if the input is not a valid expression or if the token /// stream contains comments, keywords or identifiers. @@ -547,7 +560,7 @@ pub fn expr(input: &[Token]) -> CResult<'_, EvalResult> { IdentifierParser::new(&HashMap::new()).expr(input) } -/// Parse and evaluate a macro definition from a list of tokens. +/// Parse and evaluate a macro definition from of a list of tokens. /// /// Returns the identifier for the macro and its replacement evaluated as an /// expression. The input should not include `#define`. @@ -600,10 +613,10 @@ pub fn macro_definition(input: &[Token]) -> CResult<'_, (&'_ [u8], EvalResult)> /// ``` pub fn fn_macro_declaration(input: &[Token]) -> CResult<'_, (&[u8], Vec<&[u8]>)> { pair( - identifier_token, + typed_token!(Identifier), delimited( p("("), - separated_list0(p(","), identifier_token), + separated_list(p(","), typed_token!(Identifier)), p(")"), ), )(input) @@ -19,7 +19,7 @@ pub mod nom { //! nom's result types, re-exported. - pub use nom::{error::ErrorKind, error::Error, Err, IResult, Needed}; + pub use nom::{error::ErrorKind, Err, IResult, Needed}; } pub mod expr; pub mod literal; @@ -86,15 +86,6 @@ impl<I> From<(I, ErrorKind)> for Error<I> { } } -impl<I> From<::nom::error::Error<I>> for Error<I> { - fn from(e: ::nom::error::Error<I>) -> Self { - Self { - input: e.input, - error: e.code.into(), - } - } -} - impl<I> ::nom::error::ParseError<I> for Error<I> { fn from_error_kind(input: I, kind: nom::ErrorKind) -> Self { Self { diff --git a/src/literal.rs b/src/literal.rs index 68e85c7..39f07be 100644 --- a/src/literal.rs +++ b/src/literal.rs @@ -70,7 +70,7 @@ impl From<u8> for CChar { } // A non-allocating version of this would be nice... -impl std::convert::Into<Vec<u8>> for CChar { +impl Into<Vec<u8>> for CChar { fn into(self) -> Vec<u8> { match self { CChar::Char(c) => { @@ -88,12 +88,12 @@ impl std::convert::Into<Vec<u8>> for CChar { } /// ensures the child parser consumes the whole input -pub fn full<I: Clone, O, F>( +pub fn full<I: Clone, O, E: From<nom::error::ErrorKind>, F>( f: F, -) -> impl Fn(I) -> nom::IResult<I, O> +) -> impl Fn(I) -> nom::IResult<I, O, (I, E)> where I: nom::InputLength, - F: Fn(I) -> nom::IResult<I, O>, + F: Fn(I) -> nom::IResult<I, O, (I, E)>, { move |input| { let res = f(input); @@ -102,7 +102,7 @@ where if i.input_len() == 0 { Ok((i, o)) } else { - Err(nom::Err::Error(nom::error::Error::new(i, nom::error::ErrorKind::Complete))) + Err(nom::Err::Error((i, nom::error::ErrorKind::Complete.into()))) } } r => r, @@ -119,8 +119,8 @@ macro_rules! byte { fn parser(i: &[u8]) -> crate::nom::IResult<&[u8], u8> { match i.split_first() { $(Some((&c @ $p,rest)))|* => Ok((rest,c)), - Some(_) => Err(nom::Err::Error(nom::error::Error::new(i, nom::error::ErrorKind::OneOf))), - None => Err(nom::Err::Incomplete(Needed::new(1))), + Some(_) => Err(nom::Err::Error((i, nom::error::ErrorKind::OneOf))), + None => Err(nom::Err::Incomplete(Needed::Size(1))), } } @@ -224,7 +224,7 @@ fn c_string(i: &[u8]) -> nom::IResult<&[u8], Vec<u8>> { map(escaped_char, |c: CChar| c.into()), map(is_not([b'\\', b'"']), |c: &[u8]| c.into()), )), - Vec::new, + Vec::new(), |mut v: Vec<u8>, res: Vec<u8>| { v.extend_from_slice(&res); v @@ -272,7 +272,7 @@ fn c_int(i: &[u8]) -> nom::IResult<&[u8], i64> { c_int_radix(v, 8) }), map_opt(many1(complete(decimal)), |v| c_int_radix(v, 10)), - |input| Err(crate::nom::Err::Error(nom::error::Error::new(input, crate::nom::ErrorKind::Fix))), + |input| Err(crate::nom::Err::Error((input, crate::nom::ErrorKind::Fix))), )), opt(take_ul), ), |