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

Method parser

alpm-types/src/system.rs:108–132  ·  view source on GitHub ↗

Recognizes a [`SystemArchitecture`] in an input string. Consumes all input and returns an error if the string doesn't match any architecture.

(input: &mut &str)

Source from the content-addressed store, hash-verified

106
107impl AlpmParser for SystemArchitecture {
108 /// Recognizes a [`SystemArchitecture`] in an input string.
109 ///
110 /// # Errors
111 ///
112 /// Returns an error if `input` does not begin with a valid `SystemArchitecture`.
113 fn parser(input: &mut &str) -> ModalResult<SystemArchitecture> {
114 // Make sure we don't have an `any`.
115 cut_err(not((Caseless("any"), eof)))
116 .context(StrContext::Label(
117 "system architecture. 'any' has a special meaning and is not allowed here.",
118 ))
119 .parse_next(input)?;
120
121 let alphanum = |c: char| c.is_ascii_alphanumeric();
122 let special_chars = ['_'];
123
124 // We consume as many valid characters as we can until we hit an unknown char or `eof`.
125 // E.g.
126 // `asdfasdf_x86_64_omega:test` -> `:test`
127 let architecture: String = cut_err(repeat(1.., one_of((alphanum, special_chars))))
128 .context(StrContext::Label("character in system architecture"))
129 .context(StrContext::Expected(StrContextValue::Description(
130 "a string containing only ASCII alphanumeric characters and underscores.",
131 )))
132 .parse_next(input)?;
133
134 // We now take that valid architecture and check it against all known static variants in our
135 // SystemArchitecture enum.

Callers

nothing calls this directly

Calls 1

valueMethod · 0.45

Tested by

no test coverage detected