diff --git a/Cargo.lock b/Cargo.lock index 7c6cf39..a6ff96e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,9 +139,9 @@ checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" [[package]] name = "bytes" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" [[package]] name = "cast" @@ -151,9 +151,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.2.63" +version = "1.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" +checksum = "e228eec9be7c17ccb640b59b36a5cd805ea2a564a4c5e162c2f659fea30d3b96" dependencies = [ "find-msvc-tools", "jobserver", @@ -515,9 +515,9 @@ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "h2" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" +checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155" dependencies = [ "atomic-waker", "bytes", @@ -882,9 +882,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.100" +version = "0.3.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2025f20d7a4fa7785846e7b63d10a76d3f1cee98ee5cb79ea59703f95e42162" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" dependencies = [ "cfg-if", "futures-util", @@ -911,9 +911,9 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "log" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" [[package]] name = "lru-slab" @@ -923,9 +923,9 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" [[package]] name = "memchr" -version = "2.8.1" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" +checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" [[package]] name = "mime" @@ -1091,9 +1091,9 @@ dependencies = [ [[package]] name = "quinn" -version = "0.11.9" +version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" dependencies = [ "bytes", "cfg_aliases", @@ -1111,9 +1111,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e" dependencies = [ "aws-lc-rs", "bytes", @@ -1147,9 +1147,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.45" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" dependencies = [ "proc-macro2", ] @@ -1309,9 +1309,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.40" +version = "0.23.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" +checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f" dependencies = [ "aws-lc-rs", "once_cell", @@ -1517,9 +1517,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.15.1" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" [[package]] name = "socket2" @@ -1551,9 +1551,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.117" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -1880,18 +1880,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.3+wasi-0.2.9" +version = "1.0.4+wasi-0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" dependencies = [ "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.123" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a254a4b10c19a76f09a27640e7ffbf9bc30bf67e16a3bf28aaefa4920fe81563" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" dependencies = [ "cfg-if", "once_cell", @@ -1902,9 +1902,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.73" +version = "0.4.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54568702fabf5d4849ce2b90fadfa64168a097eaf4b351ce9df8b687a0086aaf" +checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d" dependencies = [ "js-sys", "wasm-bindgen", @@ -1912,9 +1912,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.123" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a40fc75b0ec6f3746ceb10d36f53a93dcd68a93b11b6445983945d79eba0dc" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1922,9 +1922,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.123" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "908f34bd9b9ce3d4caf07b72dfab63d61504d156856c6bd3cd87fa350cf3985b" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" dependencies = [ "bumpalo", "proc-macro2", @@ -1935,18 +1935,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.123" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acbf7616c27b194bbb550bf77ed0c2c3e5b7fd1260a93082b95fb7f47959b92" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.100" +version = "0.3.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0871acf327f283dc6da28a1696cdc64fb355ba9f935d052021fa77f35cce69" +checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141" dependencies = [ "js-sys", "wasm-bindgen", @@ -1964,9 +1964,9 @@ dependencies = [ [[package]] name = "webpki-root-certs" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31141ce3fc3e300ae89b78c0dd67f9708061d1d2eda54b8209346fd6be9a92c" +checksum = "0d46a5a140e6f7afeccd8eae97eff335163939eac8b929834875168b29b3d267" dependencies = [ "rustls-pki-types", ] @@ -2255,9 +2255,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.8.2" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" [[package]] name = "zerotrie" diff --git a/deny.toml b/deny.toml index aa4a321..bf16cbe 100644 --- a/deny.toml +++ b/deny.toml @@ -70,6 +70,7 @@ feature-depth = 1 # A list of advisory IDs to ignore. Note that ignored advisories will still # output a note when they are encountered. ignore = [ + "RUSTSEC-2026-0204" #"RUSTSEC-0000-0000", #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish diff --git a/nom-kconfig-0.12.0.crate b/nom-kconfig-0.12.0.crate new file mode 100644 index 0000000..4e70356 Binary files /dev/null and b/nom-kconfig-0.12.0.crate differ diff --git a/src/attribute/default_test.rs b/src/attribute/default_test.rs index d33fea6..c26052b 100644 --- a/src/attribute/default_test.rs +++ b/src/attribute/default_test.rs @@ -145,6 +145,26 @@ fn test_default_attribute_number_2() { ) } +#[test] +/// https://github.com/torvalds/linux/blob/master/init/Kconfig#L22-L25 +fn test_default_attribute_lll() { + assert_parsing_eq!( + parse_default, + "default 10 if BFLB_BL70X_BLE_M0S1T10", + Ok(( + "", + DefaultAttribute { + expression: Expression::Term(AndExpression::Term(Term::Atom(Atom::Symbol( + Symbol::Constant(ConstantSymbol::Integer(10)) + )))), + r#if: Some(Expression::Term(AndExpression::Term(Term::Atom( + Atom::Symbol(Symbol::NonConstant("BFLB_BL70X_BLE_M0S1T10".to_string())) + )))) + } + )) + ) +} + #[test] fn test_default_attribute_number_3() { assert_parsing_eq!( diff --git a/src/attribute/depends_on_test.rs b/src/attribute/depends_on_test.rs index 8175a7f..2bdb228 100644 --- a/src/attribute/depends_on_test.rs +++ b/src/attribute/depends_on_test.rs @@ -132,3 +132,45 @@ fn test_parse_depends_on_with_if_condition() { )) ) } + +/// https://android.googlesource.com/kernel/common/+/refs/heads/android16-6.12/drivers/auxdisplay/Kconfig#241 +#[test] +fn test_parse_depends_on_tmp() { + assert_parsing_eq!( + parse_depends_on, + "depends on PANEL_PROFILE=\"0\" && PANEL_LCD=\"1\" && PANEL_LCD_PROTO=\"0\"", + Ok(( + "", + DependsOn { + expression: Expression::Term(AndExpression::Expression(vec![ + Term::Atom(Atom::Compare(CompareExpression { + left: CompareOperand::Symbol(Symbol::NonConstant( + "PANEL_PROFILE".to_string() + )), + operator: CompareOperator::Equal, + right: CompareOperand::Symbol(Symbol::Constant(ConstantSymbol::String( + "0".to_string() + ))) + })), + Term::Atom(Atom::Compare(CompareExpression { + left: CompareOperand::Symbol(Symbol::NonConstant("PANEL_LCD".to_string())), + operator: CompareOperator::Equal, + right: CompareOperand::Symbol(Symbol::Constant(ConstantSymbol::String( + "1".to_string() + ))) + })), + Term::Atom(Atom::Compare(CompareExpression { + left: CompareOperand::Symbol(Symbol::NonConstant( + "PANEL_LCD_PROTO".to_string() + )), + operator: CompareOperator::Equal, + right: CompareOperand::Symbol(Symbol::Constant(ConstantSymbol::String( + "0".to_string() + ))) + })) + ])), + r#if: None, + } + )) + ) +} diff --git a/src/attribute/range_test.rs b/src/attribute/range_test.rs index 590cdfc..4a1fef7 100644 --- a/src/attribute/range_test.rs +++ b/src/attribute/range_test.rs @@ -96,3 +96,21 @@ fn test_parse_range_variable() { )) ) } + +// https://github.com/zephyrproject-rtos/zephyr/blob/e201b84b04e4fab1844658e71da0b7e340f1cc82/subsys/net/lib/zperf/Kconfig#L103 +#[test] +#[ignore = "not implemented yet"] +fn test_parse_range_variable_in_zephyr() { + assert_parsing_eq!( + parse_range, + "range $(inc,$(UINT8_MAX)) $(UINT16_MAX)", + Ok(( + "", + Range { + lower_bound: RangeBound::Variable("inc,UINT8_MAX".to_string()), + upper_bound: RangeBound::Variable("UINT16_MAX".to_string()), + r#if: None + } + )) + ) +} diff --git a/src/entry/configdefault.rs b/src/entry/configdefault.rs index ab918ef..25678f5 100644 --- a/src/entry/configdefault.rs +++ b/src/entry/configdefault.rs @@ -1,6 +1,7 @@ use nom::{ bytes::complete::tag, combinator::map, + multi::many1, sequence::{pair, preceded}, IResult, Parser, }; @@ -23,18 +24,18 @@ use crate::{ #[cfg_attr(feature = "deserialize", derive(Deserialize))] pub struct ConfigDefault { pub symbol: String, - pub default: DefaultAttribute, + pub default_attributes: Vec, } pub fn parse_configdefault(input: KconfigInput) -> IResult { map( pair( preceded(ws(tag("configdefault")), ws(parse_config_symbol)), - parse_default, + many1(parse_default), ), - |(symbol, default_attribute)| ConfigDefault { + |(symbol, default_attributes)| ConfigDefault { symbol: symbol.to_string(), - default: default_attribute, + default_attributes, }, ) .parse(input) diff --git a/src/entry/configdefault_test.rs b/src/entry/configdefault_test.rs index 4ee37b7..08097d2 100644 --- a/src/entry/configdefault_test.rs +++ b/src/entry/configdefault_test.rs @@ -16,14 +16,51 @@ fn test_parse_configdefault() { "", ConfigDefault { symbol: "FOO".to_string(), - default: DefaultAttribute { + default_attributes: vec![DefaultAttribute { expression: Expression::Term(AndExpression::Term(Term::Atom(Atom::Symbol( Symbol::Constant(ConstantSymbol::Boolean(true)) )))), r#if: Some(Expression::Term(AndExpression::Term(Term::Atom( Atom::Symbol(Symbol::NonConstant("BAR".to_string())) )))) - } + }] + } + )) + ) +} + +#[test] +/// we can have multiple default attributes for a given `configdefault`` entry. +/// https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/bluetooth/hci/Kconfig.bflb#L121-L124 +fn test_parse_configdefault_multiple_default_attributes() { + let input = "configdefault BT_BUF_ACL_TX_COUNT + default 16 if BFLB_BL70X_BLE_M16S1 + default 10 if BFLB_BL70X_BLE_M0S1T10"; + assert_parsing_eq!( + parse_configdefault, + input, + Ok(( + "", + ConfigDefault { + symbol: "BT_BUF_ACL_TX_COUNT".to_string(), + default_attributes: vec![ + DefaultAttribute { + expression: Expression::Term(AndExpression::Term(Term::Atom( + Atom::Symbol(Symbol::Constant(ConstantSymbol::Integer(16))) + ))), + r#if: Some(Expression::Term(AndExpression::Term(Term::Atom( + Atom::Symbol(Symbol::NonConstant("BFLB_BL70X_BLE_M16S1".to_string())) + )))), + }, + DefaultAttribute { + expression: Expression::Term(AndExpression::Term(Term::Atom( + Atom::Symbol(Symbol::Constant(ConstantSymbol::Integer(10))) + ))), + r#if: Some(Expression::Term(AndExpression::Term(Term::Atom( + Atom::Symbol(Symbol::NonConstant("BFLB_BL70X_BLE_M0S1T10".to_string())) + )))), + } + ] } )) ) diff --git a/src/string.rs b/src/string.rs index 4b78c11..b4bad3f 100644 --- a/src/string.rs +++ b/src/string.rs @@ -1,3 +1,4 @@ +use crate::{util::ws, KconfigInput}; use nom::{ branch::alt, bytes::complete::tag, @@ -9,8 +10,6 @@ use nom::{ IResult, Input, Parser, }; -use crate::{util::ws, KconfigInput}; - pub fn parse_string(input: KconfigInput) -> IResult { map( alt(( @@ -62,12 +61,33 @@ pub fn take_until_unbalanced( } } -/// A first word is `'something here'` or `"something here"` or just a normal word without spaces. It is used in places where Kconfig allows either a string or a symbol, such as in `default` attributes. +/// A first word is `'something here'` or `"something here"` or just a normal word without spaces. +/// It is used in places where Kconfig allows either a string or a symbol, such as in `default` attributes. pub fn parse_first_word(input: KconfigInput) -> IResult { alt(( - recognize((tag("'"), take_until_unbalanced('\''), tag("'"))), - recognize((tag("\""), take_until_unbalanced('"'), tag("\""))), + recognize((tag("'"), take_until_first_word_end('\''), tag("'"))), + recognize((tag("\""), take_until_first_word_end('"'), tag("\""))), recognize(ws(many1(alt((alphanumeric1, recognize(one_of("-._'\""))))))), )) .parse(input) } + +fn take_until_first_word_end( + delimiter: char, +) -> impl Fn(KconfigInput) -> IResult { + move |i: KconfigInput| { + let input = *i.fragment(); + let end_of_line = input.find('\n').unwrap_or(input.len()); + let search_start = 0; + + if let Some(offset) = input[search_start..end_of_line].find(delimiter) { + let index = search_start + offset; + return Ok(i.take_split(index)); + } + + Err(nom::Err::Error(Error::from_error_kind( + i, + ErrorKind::TakeUntil, + ))) + } +}