Coverage Report

Created: 2026-03-14 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/pest_consume-1.1.3/src/parser.rs
Line
Count
Source
1
use crate::{Error, Nodes};
2
use pest::Parser as PestParser;
3
use pest::RuleType;
4
5
/// A trait that provides methods to parse strings.
6
/// Do not implement manually; instead use the [`parser`] macro provided by this crate.
7
///
8
/// [`parser`]: macro@crate::parser
9
pub trait Parser {
10
    type Rule: RuleType;
11
    #[doc(hidden)]
12
    type AliasedRule: RuleType;
13
    type Parser: PestParser<Self::Rule>;
14
15
    #[doc(hidden)]
16
    fn rule_alias(rule: Self::Rule) -> Self::AliasedRule;
17
    #[doc(hidden)]
18
    fn allows_shortcut(rule: Self::Rule) -> bool;
19
20
    /// Parses a `&str` starting from `rule`
21
    fn parse<'i>(
22
        rule: Self::Rule,
23
        input_str: &'i str,
24
    ) -> Result<Nodes<'i, Self::Rule, ()>, Error<Self::Rule>> {
25
        Self::parse_with_userdata(rule, input_str, ())
26
    }
27
28
    /// Parses a `&str` starting from `rule`, carrying `user_data` through the parser methods.
29
0
    fn parse_with_userdata<'i, D>(
30
0
        rule: Self::Rule,
31
0
        input_str: &'i str,
32
0
        user_data: D,
33
0
    ) -> Result<Nodes<'i, Self::Rule, D>, Error<Self::Rule>> {
34
0
        let pairs = Self::Parser::parse(rule, input_str)?;
35
0
        Ok(Nodes::new(input_str, pairs, user_data))
36
0
    }
37
}