diff --git a/Cargo.toml b/Cargo.toml index 51aa8b7..873584b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ opt-level = 0 debug = true [dependencies] -derivative = "2.2.0" serde = { version = "1.0", features = ["derive"] } #[target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/src/document.rs b/src/document.rs index 1ebd662..fd1524b 100644 --- a/src/document.rs +++ b/src/document.rs @@ -12,7 +12,7 @@ use crate::parser::{Parser, StyleBlock}; // Interface to WASM to be used in JS #[wasm_bindgen] pub fn parse_rtf(rtf: String) -> RtfDocument { - return RtfDocument::try_from(rtf).unwrap() + return RtfDocument::try_from(rtf).unwrap(); } #[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)] diff --git a/src/lexer.rs b/src/lexer.rs index 208142c..4032b69 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -311,4 +311,4 @@ if (a == b) \{\ [OpeningBracket, PlainText("je suis une b"), ControlSymbol((Unicode, Value(234))), PlainText("te"), ClosingBracket,] ); } -} \ No newline at end of file +} diff --git a/src/paragraph.rs b/src/paragraph.rs index 28fbe50..50a4383 100644 --- a/src/paragraph.rs +++ b/src/paragraph.rs @@ -1,5 +1,4 @@ /// Define the paragraph related structs and enums - use serde::{Deserialize, Serialize}; use tsify::Tsify; use wasm_bindgen::prelude::wasm_bindgen; diff --git a/src/parser.rs b/src/parser.rs index 2eb10ee..577f5d5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use std::{fmt, mem}; -use derivative::Derivative; use serde::{Deserialize, Serialize}; use wasm_bindgen::prelude::wasm_bindgen; @@ -28,13 +27,11 @@ pub struct StyleBlock { pub text: String, } -#[derive(Derivative, Debug, Clone, PartialEq, Hash, Deserialize, Serialize)] -#[derivative(Default)] +#[derive(Debug, Clone, PartialEq, Hash, Deserialize, Serialize)] #[wasm_bindgen] pub struct Painter { pub color_ref: ColorRef, pub font_ref: FontRef, - #[derivative(Default(value = "12"))] pub font_size: u16, pub bold: bool, pub italic: bool, @@ -45,6 +42,23 @@ pub struct Painter { pub strike: bool, } +impl Default for Painter { + fn default() -> Self { + Self { + color_ref: Default::default(), + font_ref: Default::default(), + font_size: 12, + bold: Default::default(), + italic: Default::default(), + underline: Default::default(), + superscript: Default::default(), + subscript: Default::default(), + smallcaps: Default::default(), + strike: Default::default(), + } + } +} + #[derive(Debug, Clone)] pub enum ParserError { InvalidToken(String), @@ -78,15 +92,23 @@ impl fmt::Display for ParserError { } // This state keeps track of each value that depends on the scope nesting -#[derive(Derivative, Debug, Clone, PartialEq, Hash)] -#[derivative(Default)] +#[derive(Debug, Clone, PartialEq, Hash)] struct ParserState { pub painter: Painter, pub paragraph: Paragraph, - #[derivative(Default(value = "1"))] pub unicode_ignore_count: i32, } +impl Default for ParserState { + fn default() -> Self { + Self { + painter: Default::default(), + paragraph: Default::default(), + unicode_ignore_count: 1, + } + } +} + pub struct Parser<'a> { tokens: Vec>, parsed_item: Vec, @@ -129,7 +151,7 @@ impl<'a> Parser<'a> { pub fn parse(&mut self) -> Result { self.check_document_validity()?; let mut document = RtfDocument::default(); // Init empty document - // Traverse the document and consume the header groups (FontTable, StyleSheet, etc ...) + // Traverse the document and consume the header groups (FontTable, StyleSheet, etc ...) document.header = self.parse_header()?; // Init the state of the docuement. the stack is used to keep track of the different scope changes. let mut state_stack: Vec = vec![ParserState::default()]; @@ -748,4 +770,4 @@ pub mod tests { assert_eq!(doc1.body, doc2.body); assert_eq!(doc3.body, doc2.body); } -} \ No newline at end of file +} diff --git a/src/tokens.rs b/src/tokens.rs index 3d673df..0307c15 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -245,4 +245,4 @@ mod tests { let input = r"\rtf-1"; assert_eq!(ControlWord::from(input).unwrap(), (ControlWord::Rtf, Property::Value(-1))) } -} \ No newline at end of file +}