slint-ui / document-features

Extract documentation for the feature flags from comments in Cargo.toml
Apache License 2.0
174 stars 13 forks source link

`error: Parse error while parsing line: [` #16

Closed Mathieu-Lala closed 1 year ago

Mathieu-Lala commented 1 year ago

Hi :wave:

I tried to add document-features to my project https://github.com/viridIT/vSMTP/compare/develop...doc/feature but I have this error : I believe this is a bug in the parser :bug:

error: Parse error while parsing line: [
  --> src/vsmtp/vsmtp-core/src/lib.rs:21:10
   |
21 | #![doc = document_features::document_features!()]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `document_features::document_features` (in Nightly builds, run with -Z macro-backtrace for more info)

error: Compilation failed, aborting rustdoc

error: could not document `vsmtp`

Caused by:
  process didn't exit successfully: `rustdoc [...]
ogoffart commented 1 year ago

The toml parser used in the crate is a bit basic and it looks like your Cargo.toml is quite complicated with its meta-data split in many lines.

I have a suspicion that the problem happens trying to parse array in array

Mathieu-Lala commented 1 year ago

Do you think this could fix it ?

https://github.com/slint-ui/document-features/blob/master/lib.rs#L308

current_table = match table.split_once("]").map(|(t, _)| t.trim()) {
  Some(line) => line,
  None => continue, // ignore the sequence "\n[(.*)\n"
}
ogoffart commented 1 year ago

I think we should try to skip all the lines until the end of the array by using get_balanced.

In fact, we should try to call get_balanced even when in other sections, contrary to what this comment say https://github.com/slint-ui/document-features/blob/ba20128b81382fdb40cfbf7aff2c6408a066c236/lib.rs#L322

Mathieu-Lala commented 1 year ago

Thanks for the fix! It worked fine with my crate. Will you publish to crates.io the new version ?

ogoffart commented 1 year ago

Your wishes have come true :-) 0.2.7 was published