Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Deriative #15

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@ if (a == b) \{\
[OpeningBracket, PlainText("je suis une b"), ControlSymbol((Unicode, Value(234))), PlainText("te"), ClosingBracket,]
);
}
}
}
1 change: 0 additions & 1 deletion src/paragraph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// Define the paragraph related structs and enums

use serde::{Deserialize, Serialize};
use tsify::Tsify;
use wasm_bindgen::prelude::wasm_bindgen;
Expand Down
40 changes: 31 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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<Token<'a>>,
parsed_item: Vec<bool>,
Expand Down Expand Up @@ -129,7 +151,7 @@ impl<'a> Parser<'a> {
pub fn parse(&mut self) -> Result<RtfDocument, ParserError> {
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<ParserState> = vec![ParserState::default()];
Expand Down Expand Up @@ -748,4 +770,4 @@ pub mod tests {
assert_eq!(doc1.body, doc2.body);
assert_eq!(doc3.body, doc2.body);
}
}
}
2 changes: 1 addition & 1 deletion src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,4 @@ mod tests {
let input = r"\rtf-1";
assert_eq!(ControlWord::from(input).unwrap(), (ControlWord::Rtf, Property::Value(-1)))
}
}
}
Loading