MCPcopy Create free account
hub / github.com/archlinux/alpm / section

Function section

alpm-db/src/desc/parser.rs:260–301  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

258/// - the section body contains malformed values,
259/// - or the section does not terminate properly.
260fn 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///

Callers 1

fmtMethod · 0.70

Calls 8

NameClass · 0.85
PackagerClass · 0.85
valueFunction · 0.70
opt_valueFunction · 0.70
valuesFunction · 0.70
VersionClass · 0.50
UrlClass · 0.50
LicenseEnum · 0.50

Tested by

no test coverage detected