1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// pest. The Elegant Parser
// Copyright (C) 2017  Dragoș Tiselice
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::rc::Rc;

use super::error::Error;
use super::inputs::{Input, StringInput};
use super::iterators::Pairs;
use super::RuleType;

/// A `trait` that defines a `Parser`.
pub trait Parser<R: RuleType> {
    /// Parses `input` starting from `rule`.
    fn parse<I: Input>(rule: R, input: Rc<I>) -> Result<Pairs<R, I>, Error<R, I>>;
    /// Parses an `input` &str starting from `rule`.
    fn parse_str(rule: R, input: &str) -> Result<Pairs<R, StringInput>, Error<R, StringInput>> {
        Self::parse(rule, Rc::new(StringInput::new(input.to_owned())))
    }
}