From 1f93984dbe5e8a670ac2ff112e8a7a2b6667b16f Mon Sep 17 00:00:00 2001 From: b1ek Date: Sat, 16 Nov 2024 21:20:22 +1000 Subject: [PATCH 1/3] fix serde not compiling for struct with lifetime --- src/compiling/lexing/lexer.rs | 4 ++-- src/compiling/lexing/reader.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiling/lexing/lexer.rs b/src/compiling/lexing/lexer.rs index 8836ef9..6a9dbc8 100644 --- a/src/compiling/lexing/lexer.rs +++ b/src/compiling/lexing/lexer.rs @@ -33,13 +33,13 @@ pub struct Lexer { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -struct LexState<'a> { +struct LexState { word: String, is_indenting: bool, is_escaped: bool, token_start_index: usize, position: (usize, usize), - reader: Reader<'a>, + reader: Reader, lexem: Vec, region_handler: RegionHandler, compound_handler: CompoundHandler, diff --git a/src/compiling/lexing/reader.rs b/src/compiling/lexing/reader.rs index 438fae9..63085f8 100644 --- a/src/compiling/lexing/reader.rs +++ b/src/compiling/lexing/reader.rs @@ -10,18 +10,18 @@ pub enum ReadMode { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct Reader<'a> { - pub code: &'a String, +pub struct Reader { + pub code: String, pub row: usize, pub col: usize, pub index: usize, pub new_line: bool } -impl<'a> Reader<'a> { - pub fn new(code: &'a String) -> Self { +impl Reader { + pub fn new(code: &String) -> Self { Reader { - code, + code: code.clone(), row: BEGINNING.0, col: BEGINNING.1, index: 0, @@ -116,7 +116,7 @@ impl<'a> Reader<'a> { } } -impl<'a> Iterator for Reader<'a> { +impl Iterator for Reader { type Item = char; fn next(&mut self) -> Option { From 52329532d5fd5cab5d7aa8b8ea447eaf7f97e709 Mon Sep 17 00:00:00 2001 From: b1ek Date: Sun, 17 Nov 2024 13:32:13 +1000 Subject: [PATCH 2/3] remove serde from them lexer reader compiler classes --- src/compiling/compiler.rs | 1 - src/compiling/lexing/lexer.rs | 6 +----- src/compiling/lexing/reader.rs | 5 ----- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/compiling/compiler.rs b/src/compiling/compiler.rs index 806d9dd..4fd2592 100644 --- a/src/compiling/compiler.rs +++ b/src/compiling/compiler.rs @@ -67,7 +67,6 @@ pub enum ScopingMode { /// # } /// ``` #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Compiler { /// Name of your language pub name: String, diff --git a/src/compiling/lexing/lexer.rs b/src/compiling/lexing/lexer.rs index 6a9dbc8..3565c17 100644 --- a/src/compiling/lexing/lexer.rs +++ b/src/compiling/lexing/lexer.rs @@ -14,12 +14,8 @@ use super::{ LexerError, LexerErrorType, }; -#[cfg(feature = "serde")] -use serde::{Serialize, Deserialize}; - /// Lexer #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Lexer { rules: Rules, /// Path to the lexed file @@ -32,7 +28,7 @@ pub struct Lexer { pub scoping_mode: ScopingMode, } -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] struct LexState { word: String, is_indenting: bool, diff --git a/src/compiling/lexing/reader.rs b/src/compiling/lexing/reader.rs index 63085f8..ae7c20b 100644 --- a/src/compiling/lexing/reader.rs +++ b/src/compiling/lexing/reader.rs @@ -1,15 +1,10 @@ -#[cfg(feature = "serde")] -use serde::{Serialize, Deserialize}; - const BEGINNING: (usize, usize) = (0, 1); -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ReadMode { History, Future } -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Reader { pub code: String, pub row: usize, From 3c1d2ea8b961ce5de290be54e7144f7233c856e4 Mon Sep 17 00:00:00 2001 From: blek! Date: Wed, 20 Nov 2024 20:58:52 +1000 Subject: [PATCH 3/3] Update src/compiling/lexing/lexer.rs Co-authored-by: Phoenix Himself --- src/compiling/lexing/lexer.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiling/lexing/lexer.rs b/src/compiling/lexing/lexer.rs index 3565c17..8425e33 100644 --- a/src/compiling/lexing/lexer.rs +++ b/src/compiling/lexing/lexer.rs @@ -28,7 +28,6 @@ pub struct Lexer { pub scoping_mode: ScopingMode, } -// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] struct LexState { word: String, is_indenting: bool,