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