| 1 | use std::fmt;
|
| 2 |
|
| 3 | #[derive(Debug, Clone, PartialEq, Eq)]
|
| 4 | pub struct ParseError {
|
| 5 | pub line: usize,
|
| 6 | pub column: usize,
|
| 7 | pub message: String,
|
| 8 | }
|
| 9 |
|
| 10 | impl fmt::Display for ParseError {
|
| 11 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
| 12 | write!(
|
| 13 | f,
|
| 14 | "line {}, column {}: {}",
|
| 15 | self.line, self.column, self.message
|
| 16 | )
|
| 17 | }
|
| 18 | }
|
| 19 |
|
| 20 | impl std::error::Error for ParseError {}
|
| 21 |
|
| 22 | #[derive(Debug, Clone, PartialEq, Eq)]
|
| 23 | pub struct Document {
|
| 24 | pub blocks: Vec<Block>,
|
| 25 | }
|
| 26 |
|
| 27 | #[derive(Debug, Clone, PartialEq, Eq)]
|
| 28 | pub enum Block {
|
| 29 | Paragraph {
|
| 30 | align: Align,
|
| 31 | inlines: Vec<Inline>,
|
| 32 | },
|
| 33 | Heading {
|
| 34 | level: u8,
|
| 35 | inlines: Vec<Inline>,
|
| 36 | },
|
| 37 | Rule,
|
| 38 | Feed(u8),
|
| 39 | Cut,
|
| 40 | Image {
|
| 41 | path: String,
|
| 42 | width: ImageWidth,
|
| 43 | align: Align,
|
| 44 | },
|
| 45 | Barcode {
|
| 46 | symbology: BarcodeSymbology,
|
| 47 | data: String,
|
| 48 | height: u8,
|
| 49 | align: Align,
|
| 50 | show_text: bool,
|
| 51 | },
|
| 52 | Qr {
|
| 53 | data: String,
|
| 54 | size: u8,
|
| 55 | ecc: QrEcc,
|
| 56 | align: Align,
|
| 57 | },
|
| 58 | }
|
| 59 |
|
| 60 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
| 61 | pub enum Align {
|
| 62 | #[default]
|
| 63 | Left,
|
| 64 | Center,
|
| 65 | Right,
|
| 66 | }
|
| 67 |
|
| 68 | #[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
| 69 | pub enum ImageWidth {
|
| 70 | Percent(u8),
|
| 71 | Dots(u16),
|
| 72 | Default,
|
| 73 | }
|
| 74 |
|
| 75 | #[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
| 76 | pub enum BarcodeSymbology {
|
| 77 | Code128,
|
| 78 | Ean13,
|
| 79 | Ean8,
|
| 80 | Code39,
|
| 81 | }
|
| 82 |
|
| 83 | #[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
| 84 | pub enum QrEcc {
|
| 85 | L,
|
| 86 | M,
|
| 87 | Q,
|
| 88 | H,
|
| 89 | }
|
| 90 |
|
| 91 | #[derive(Debug, Clone, PartialEq, Eq)]
|
| 92 | pub enum Inline {
|
| 93 | Text(String),
|
| 94 | Bold(Vec<Inline>),
|
| 95 | Italic(Vec<Inline>),
|
| 96 | Code(String),
|
| 97 | Param(String),
|
| 98 | }
|
| 99 |
|
| 100 | mod parser;
|
| 101 |
|
| 102 | pub use parser::parse;
|