MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_version_constraint

Function parse_version_constraint

src/testdrive/src/parser.rs:199–324  ·  view source on GitHub ↗
(
    line_reader: &mut LineReader,
)

Source from the content-addressed store, hash-verified

197}
198
199fn parse_version_constraint(
200 line_reader: &mut LineReader,
201) -> Result<Option<VersionConstraint>, PosError> {
202 let (pos, line) = line_reader.next().unwrap();
203 if line[1..2].to_string() != "[" {
204 line_reader.push(&line);
205 return Ok(None);
206 }
207 let closed_brace_pos = match line.find(']') {
208 Some(x) => x,
209 None => {
210 return Err(PosError {
211 source: anyhow!("version-constraint: found no closing brace"),
212 pos: Some(pos),
213 });
214 }
215 };
216 let mut begin_version_kw = 2;
217 const MIN_VERSION: i32 = 0;
218 let mut min_version = MIN_VERSION;
219 if line.as_bytes()[2].is_ascii_digit() {
220 let Some(op_pos) = line.find('<') else {
221 return Err(PosError {
222 source: anyhow!("version-constraint: initial number but no '<' following"),
223 pos: Some(pos),
224 });
225 };
226 let min_version_str = line[2..op_pos].to_string();
227 match min_version_str.parse::<i32>() {
228 Ok(mv) => min_version = mv,
229 Err(_) => {
230 return Err(PosError {
231 source: anyhow!(
232 "version-constraint: invalid version number {}",
233 min_version_str
234 ),
235 pos: Some(pos),
236 });
237 }
238 };
239
240 if line.as_bytes()[op_pos + 1] == b'=' {
241 begin_version_kw = op_pos + 2;
242 } else {
243 begin_version_kw = op_pos + 1;
244 min_version += 1;
245 }
246 };
247
248 let version_start = begin_version_kw + "version".len();
249 if line[begin_version_kw..version_start].to_string() != "version" {
250 return Err(PosError {
251 source: anyhow!(
252 "version-constraint: invalid property {} (found '{}', expected 'version' {begin_version_kw})",
253 &line[2..closed_brace_pos],
254 &line[begin_version_kw..version_start]
255 ),
256 pos: Some(pos),

Callers 1

parseFunction · 0.85

Calls 7

unwrapMethod · 0.80
nextMethod · 0.45
to_stringMethod · 0.45
pushMethod · 0.45
findMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected