Skip to content

Commit

Permalink
add .deep_clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Oct 3, 2024
1 parent a3a94b4 commit d4e35a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions parser/src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl Constraint {
}
}

pub fn deep_clone(&self) -> Self {
let mut copy = self.clone();
copy.parser = self.parser.deep_clone();
copy
}

fn save_progress_and_result(&mut self, res: StepResult) {
self.last_res = res;
if self.log_json_progress {
Expand Down
7 changes: 7 additions & 0 deletions parser/src/earley/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1855,4 +1855,11 @@ impl Parser {
let mut shared = self.shared.lock().unwrap();
self.state.model_variables(&mut shared)
}

pub fn deep_clone(&self) -> Self {
let mut copy = self.clone();
let shared = self.shared.lock().unwrap();
copy.shared = Arc::new(Mutex::new(shared.clone()));
copy
}
}
7 changes: 7 additions & 0 deletions parser/src/tokenparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ impl TokenParser {
})
}

// regular .clone() uses a shared lexer state
pub fn deep_clone(&self) -> Self {
let mut copy = self.clone();
copy.parser = self.parser.deep_clone();
copy
}

pub fn stop_reason(&self) -> StopReason {
self.stop_reason
}
Expand Down

0 comments on commit d4e35a8

Please sign in to comment.