lewp_css/parsers/
parse.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5    super::{
6        separators::{Separated, Separator},
7        ParserContext,
8    },
9    crate::CustomParseError,
10    cssparser::{ParseError, Parser, UnicodeRange},
11};
12
13pub(crate) trait Parse: Sized {
14    /// Parse a value of this type.
15    ///
16    /// Returns an error on failure.
17    fn parse<'i, 't>(
18        context: &ParserContext,
19        input: &mut Parser<'i, 't>,
20    ) -> Result<Self, ParseError<'i, CustomParseError<'i>>>;
21}
22
23impl<T> Parse for Vec<T>
24where
25    T: Parse + Separated,
26    <T as Separated>::Delimiter: Separator,
27{
28    fn parse<'i, 't>(
29        context: &ParserContext,
30        input: &mut Parser<'i, 't>,
31    ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
32        <T as Separated>::Delimiter::parse(input, |i| T::parse(context, i))
33    }
34}
35
36impl Parse for ::cssparser::UnicodeRange {
37    fn parse<'i, 't>(
38        _context: &ParserContext,
39        input: &mut Parser<'i, 't>,
40    ) -> Result<Self, ParseError<'i, CustomParseError<'i>>> {
41        UnicodeRange::parse(input).map_err(|e| e.into())
42    }
43}