From 3a780cb7a8a30fe03bb9ae1e825277d1bcd5e435 Mon Sep 17 00:00:00 2001 From: Peerat Vichivanives Date: Fri, 11 Oct 2024 11:05:52 -0700 Subject: [PATCH 1/2] Remove deriative --- .DS_Store | Bin 0 -> 6148 bytes Cargo.toml | 1 - src/document.rs | 2 +- src/lexer.rs | 2 +- src/paragraph.rs | 1 - src/parser.rs | 40 +++++++++++++++++++++++++++++++--------- src/tokens.rs | 2 +- 7 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..42857ecb34c81f2e166f75f299e7cb23a1907b96 GIT binary patch literal 6148 zcmeHLze@u#6n?Q)t3~MOcz=OV1n0Ayqf=KA?GIYz%9YxJgTpNjj^dvoh@%!n9CUF| z@UQT%sNYNCUDCUD6qP(kzL57`^4-^5aw!ps+Nf0}st{2Lg|WDbD#zH*C1VS^XB{Yb zjIdL!H=|xZ6X`mf0#1S7r~tpaMcSYa9nsKwf5pe1>FY&7&Q=SrA%f=S$yRFhfS_cr*ud? z>QjjJiOq;6V3dh5IenfboO0q)R`cR=c&*TY*-!+P2GqU+`tl+4%tGH#gq$7Ydoo;o zMyRH%odQk)LxF;7SNQzjnSK8^GF;Os;1u|83W#D*4{CTSeYR$vkIz~U%J|zQ$M~dSLEDK+51Mr@)UY@CCel)4c!y literal 0 HcmV?d00001 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 +} From ac27f1abd5b0966e0e9b3615eeab5f55b8ca48eb Mon Sep 17 00:00:00 2001 From: Peerat Vichivanives Date: Sun, 13 Oct 2024 18:56:16 -0700 Subject: [PATCH 2/2] remove .Ds-store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 42857ecb34c81f2e166f75f299e7cb23a1907b96..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHLze@u#6n?Q)t3~MOcz=OV1n0Ayqf=KA?GIYz%9YxJgTpNjj^dvoh@%!n9CUF| z@UQT%sNYNCUDCUD6qP(kzL57`^4-^5aw!ps+Nf0}st{2Lg|WDbD#zH*C1VS^XB{Yb zjIdL!H=|xZ6X`mf0#1S7r~tpaMcSYa9nsKwf5pe1>FY&7&Q=SrA%f=S$yRFhfS_cr*ud? z>QjjJiOq;6V3dh5IenfboO0q)R`cR=c&*TY*-!+P2GqU+`tl+4%tGH#gq$7Ydoo;o zMyRH%odQk)LxF;7SNQzjnSK8^GF;Os;1u|83W#D*4{CTSeYR$vkIz~U%J|zQ$M~dSLEDK+51Mr@)UY@CCel)4c!y