Derive Debug and Clone for tokens and parser state

This commit is contained in:
Juno Takano 2026-01-02 14:30:36 -03:00
commit 8d204503a8
12 changed files with 18 additions and 13 deletions

View file

@ -134,17 +134,19 @@ fn lex(text: &str, map: LexMap, config: &Config) -> Vec<Token> {
tokens
}
#[derive(Clone, Debug)]
pub struct State {
context: Context,
dom_ids: HashMap<String, Vec<String>>,
buffers: Buffers,
}
#[derive(Clone, Debug)]
struct Buffers {
anchor: AnchorBuffer,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
struct AnchorBuffer {
candidate: Anchor,
text: String,
@ -169,7 +171,7 @@ impl State {
dom_ids: HashMap::new(),
buffers: Buffers {
anchor: AnchorBuffer {
candidate: Anchor::empty(),
candidate: Anchor::default(),
text: String::new(),
destination: String::new(),
},

View file

@ -5,11 +5,13 @@ use crate::syntax::content::parser::{
pub mod anchor;
#[derive(Clone, Debug)]
pub struct Context {
pub block: Block,
pub inline: Inline,
}
#[derive(Clone, Debug)]
pub enum Block {
Paragraph,
Header(u8),
@ -17,6 +19,7 @@ pub enum Block {
None,
}
#[derive(Clone, Debug)]
pub enum Inline {
Anchor,
Code,

View file

@ -10,7 +10,7 @@ pub mod preformat;
pub mod code;
pub mod oblique;
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum Token {
Anchor(anchor::Anchor),
Code(code::Code),

View file

@ -1,6 +1,6 @@
use crate::syntax::content::{Parseable, parser::lexeme::Lexeme};
#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct Anchor {
pub text: String,
pub destination: Option<String>,

View file

@ -2,7 +2,7 @@ use crate::{
syntax::content::{Parseable, Lexeme},
};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Code {
open: bool,
}

View file

@ -10,7 +10,7 @@ use crate::{
use std::fmt::Display;
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Header {
open: Option<bool>,
level: Level,
@ -112,7 +112,7 @@ impl Parseable for Header {
}
}
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Level {
One,
Two,

View file

@ -2,7 +2,7 @@ use crate::{
syntax::content::{Parseable, parser::lexeme::Lexeme},
};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct LineBreak {}
impl Parseable for LineBreak {

View file

@ -1,6 +1,6 @@
use crate::syntax::content::{Parseable, parser::lexeme::Lexeme};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Literal {
text: String,
}

View file

@ -2,7 +2,7 @@ use crate::{
syntax::content::{Parseable, Lexeme},
};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Oblique {
open: bool,
}

View file

@ -1,6 +1,6 @@
use crate::syntax::content::{Parseable, parser::lexeme::Lexeme};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Paragraph {
open: Option<bool>,
}

View file

@ -2,7 +2,7 @@ use crate::{
syntax::content::{Parseable, Lexeme},
};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct PreFormat {
open: Option<bool>,
}

View file

@ -1,6 +1,6 @@
use crate::syntax::content::{Parseable, parser::lexeme::Lexeme};
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Span {
open: Option<bool>,
}