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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use snafu::prelude::*;

/// Syntax errors that can occur when parsing an SVG path
///
/// These errors try to be exhaustive.
#[derive(Debug, PartialEq, Snafu, Clone)]
pub enum SyntaxError {
    /// The first command in a path is not moveto.
    #[snafu(display(
        "Invalid SVG path command '{command}' at index {index}, expected 'M' or 'm'"
    ))]
    ExpectedMovetoCommand {
        /// Command letter found
        command: char,
        /// Index of the command in the path
        index: usize,
    },

    /// Invalid number found in path.
    #[snafu(display("Invalid number '{number}' at index {index}"))]
    InvalidNumber {
        /// Number found
        number: String,
        /// Index of the number in the path
        index: usize,
    },

    /// Invalid character found in path.
    #[snafu(display(
        "Invalid character '{character}' at index {index}, expected {expected}"
    ))]
    InvalidCharacter {
        /// Character found
        character: char,
        /// Index of the character in the path
        index: usize,
        /// Expected character
        expected: String,
    },

    /// Invalid path ending.
    #[snafu(display("Unexpected SVG path end at index {index}, expected {expected}"))]
    UnexpectedEnding {
        /// Index of the end of the path
        index: usize,
        /// Expected token
        expected: String,
    },

    /// Invalid SVG quaractic arc command flag argument.
    #[snafu(display("Invalid SVG path elliptical arc flag at index {index}. Expected 0 or 1 but found '{character}'"))]
    InvalidArcFlag {
        /// Command letter found
        character: char,
        /// Index of the command in the path
        index: usize,
    },

    /// Invalid SVG quaractic arc command radius argument.
    #[snafu(display("Invalid SVG path elliptical arc command '{command}' radius at index {index}. Expected positive number but found '{value}'"))]
    InvalidArcRadius {
        /// Command letter found
        command: char,
        /// Index of the command in the path
        index: usize,
        /// Value found
        value: f64,
    },
}