| 1 |
// SPDX-FileCopyrightText: Peter Pentchev <[email protected]> |
| 2 |
// SPDX-License-Identifier: BSD-2-Clause |
| 3 |
//! A set of parsers for the query expressions supported by feature-check. |
| 4 |
|
| 5 |
use std::collections::HashMap; |
| 6 |
|
| 7 |
use crate::defs::{Mode, ParseError}; |
| 8 |
use crate::version::{ParseError as VParseError, Version}; |
| 9 |
|
| 10 |
pub mod p_nom; |
| 11 |
|
| 12 |
/// Parse a "feature" or "feature op version" expression for later evaluation. |
| 13 |
/// |
| 14 |
/// Returns either [`Mode::Single`] or [`Mode::Simple`]. |
| 15 |
/// |
| 16 |
/// # Errors |
| 17 |
/// |
| 18 |
/// Will return an error if the expression is neither a single feature name nor in |
| 19 |
/// the "var op value" format or if an unrecognized comparison operator is specified. |
| 20 |
#[inline] |
| 21 |
pub fn parse_expr(expr: &str) -> Result<Mode, ParseError> { |
| 22 |
p_nom::parse_expr(expr) |
| 23 |
} |
| 24 |
|
| 25 |
/// Parse a version string. |
| 26 |
/// |
| 27 |
/// # Errors |
| 28 |
/// |
| 29 |
/// Returns an error if the version string is invalid. |
| 30 |
#[inline] |
| 31 |
pub fn parse_version(value: &str) -> Result<Version, VParseError> { |
| 32 |
p_nom::parse_version(value) |
| 33 |
} |
| 34 |
|
| 35 |
/// Parse a line of `feature[=version]` pairs. |
| 36 |
/// |
| 37 |
/// # Errors |
| 38 |
/// |
| 39 |
/// Returns an error if the feature names or version strings are invalid. |
| 40 |
#[inline] |
| 41 |
pub fn parse_features_line(value: &str) -> Result<HashMap<String, Version>, ParseError> { |
| 42 |
p_nom::parse_features_line(value) |
| 43 |
} |