color_parser/color/
mod.rs

1use pex::{
2    helpers::{ascii_whitespace, make_from_str},
3    ParseResult, ParseState, StopBecause,
4};
5
6use crate::RGBA32;
7
8/// `<rgb> = (rgb|rgba) ((<percentage>|<number>)#{3},<alpha-value>?)`
9///
10/// ```bnf
11/// <rgb> = rgb( [<percentage> | none]{3} [ / [<alpha-value> | none] ]? )
12///       | rgb( [<number> | none]{3} [ / [<alpha-value> | none] ]? )
13/// ```
14/// https://www.w3.org/TR/css-color-4/#rgb-functions
15pub fn rgba(input: &str) -> Result<RGBA32, StopBecause> {
16    let state = ParseState::new(input.trim_end()).skip(ascii_whitespace);
17    make_from_str(state, parse_rgba)
18}
19
20fn parse_rgba(input: ParseState) -> ParseResult<RGBA32> {
21    todo!()
22}
23
24fn maybe_alpha(input: ParseState) -> ParseResult<RGBA32> {
25    let (state, _) = input.match_char('/')?;
26    let state = state.skip(ascii_whitespace);
27
28    todo!()
29}
30
31fn split_any(input: ParseState) -> ParseResult<RGBA32> {
32    todo!()
33}
34
35fn split_comma(input: ParseState) -> ParseResult<RGBA32> {
36    todo!()
37}
38
39fn split_slash(input: ParseState) -> ParseResult<RGBA32> {
40    todo!()
41}
42
43fn split_space(input: ParseState) -> ParseResult<RGBA32> {
44    todo!()
45}