Parses a single `%SECTION%` block and returns a [`Section`] variant. # Errors Returns an error if: - the section name is invalid or not recognized, - the section body contains malformed values, - or the section does not terminate properly.
(input: &mut &str)
| 258 | /// - the section body contains malformed values, |
| 259 | /// - or the section does not terminate properly. |
| 260 | fn section(input: &mut &str) -> ModalResult<Section> { |
| 261 | // Parse and validate the header keyword first. |
| 262 | let section_keyword = cut_err(SectionKeyword::parser) |
| 263 | .context(StrContext::Label("section name")) |
| 264 | .context(StrContext::Expected(StrContextValue::Description( |
| 265 | "a section name that is enclosed in `%` characters", |
| 266 | ))) |
| 267 | .context_with(iter_str_context!([SectionKeyword::VARIANTS])) |
| 268 | .parse_next(input)?; |
| 269 | |
| 270 | // Delegate to the corresponding value or values parser. |
| 271 | let section = match section_keyword { |
| 272 | SectionKeyword::Name => Section::Name(value(input)?), |
| 273 | SectionKeyword::Version => Section::Version(value(input)?), |
| 274 | SectionKeyword::Base => Section::Base(value(input)?), |
| 275 | SectionKeyword::Desc => Section::Desc(value(input)?), |
| 276 | SectionKeyword::Url => Section::Url(opt_value(input)?), |
| 277 | SectionKeyword::Arch => Section::Arch(value(input)?), |
| 278 | SectionKeyword::BuildDate => Section::BuildDate(value(input)?), |
| 279 | SectionKeyword::InstallDate => Section::InstallDate(value(input)?), |
| 280 | SectionKeyword::Packager => Section::Packager(value(input)?), |
| 281 | SectionKeyword::Size => Section::Size(value(input)?), |
| 282 | SectionKeyword::Groups => Section::Groups(values(input)?), |
| 283 | SectionKeyword::Reason => Section::Reason(value(input)?), |
| 284 | SectionKeyword::License => Section::License(values(input)?), |
| 285 | SectionKeyword::Validation => Section::Validation(values(input)?), |
| 286 | SectionKeyword::Replaces => Section::Replaces(values(input)?), |
| 287 | SectionKeyword::Depends => Section::Depends(values(input)?), |
| 288 | SectionKeyword::OptDepends => Section::OptDepends(values(input)?), |
| 289 | SectionKeyword::Conflicts => Section::Conflicts(values(input)?), |
| 290 | SectionKeyword::Provides => Section::Provides(values(input)?), |
| 291 | SectionKeyword::XData => { |
| 292 | let entries: Vec<ExtraDataEntry> = values(input)?; |
| 293 | let xdata = entries |
| 294 | .try_into() |
| 295 | .map_err(|e| ErrMode::Cut(ContextError::from_external_error(input, e)))?; |
| 296 | Section::XData(xdata) |
| 297 | } |
| 298 | }; |
| 299 | |
| 300 | Ok(section) |
| 301 | } |
| 302 | |
| 303 | /// Parses all `%SECTION%` blocks from the given input into a list of [`Section`]s. |
| 304 | /// |