Skip to content

Commit

Permalink
Debugger tweaks, added tracing
Browse files Browse the repository at this point in the history
- Fixed debugger argument handling
- Expanded debugger behaviour a bit (like being able to continue a bunch
  of times)
- Added support for tracing the productions of a grammar during parsing,
  in both the debugger and normal modes
  • Loading branch information
rlpowell committed Feb 5, 2025
1 parent a13c05c commit 74c00ed
Show file tree
Hide file tree
Showing 14 changed files with 826 additions and 297 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ mod b {
* Input handling
* Custom errors
* Runs on stable Rust
* Specialized parser debugger
* Optional tracing output

## Projects using pest

Expand Down
1 change: 1 addition & 0 deletions debugger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ readme = "_README.md"
rust-version = "1.61"

[dependencies]
clap = { version = "4.0.32", features = ["derive"] }
pest = { path = "../pest", version = "2.7.15" }
pest_meta = { path = "../meta", version = "2.7.15" }
pest_vm = { path = "../vm", version = "2.7.15" }
Expand Down
27 changes: 25 additions & 2 deletions debugger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use std::{
thread::{self, JoinHandle},
};

use pest::{error::Error, Position};
use pest::{error::Error, Position, TracingConfig, TracingType};
use pest_meta::{
optimizer::OptimizedRule,
parse_and_optimize,
Expand Down Expand Up @@ -133,6 +133,7 @@ pub struct DebuggerContext {
grammar: Option<Vec<OptimizedRule>>,
input: Option<String>,
breakpoints: Arc<Mutex<HashSet<String>>>,
tracing_config: TracingConfig,
}

const POISONED_LOCK_PANIC: &str = "poisoned lock";
Expand Down Expand Up @@ -211,6 +212,26 @@ impl DebuggerContext {
breakpoints.insert(rule);
}

/// Sets tracing on and its type
pub fn tracing(&mut self, ttype: TracingType) {
self.tracing_config.ttype = ttype;
}

/// Sets tracing indent spacing
pub fn tracing_spacing(&mut self, size: usize) {
self.tracing_config.spacing = size;
}

/// Sets tracing to skip implicit whitespace / comments
pub fn tracing_skip_implicit(&mut self) {
self.tracing_config.skip_implicit = true;
}

/// Sets tracing to skip silent rules
pub fn tracing_skip_silent(&mut self) {
self.tracing_config.skip_silent = true;
}

/// Removes a rule from breakpoints.
pub fn delete_breakpoint(&mut self, rule: &str) {
let mut breakpoints = self.breakpoints.lock().expect(POISONED_LOCK_PANIC);
Expand Down Expand Up @@ -243,6 +264,7 @@ impl DebuggerContext {
let breakpoints = Arc::clone(&self.breakpoints);
let is_done = Arc::clone(&self.is_done);
let is_done_signal = Arc::clone(&self.is_done);
let tracing_config = self.tracing_config;

let rsender = sender.clone();
thread::spawn(move || {
Expand All @@ -269,7 +291,7 @@ impl DebuggerContext {
}),
);

match vm.parse(&rule, &input) {
match vm.parse_with_tracing(&rule, &input, tracing_config) {
Ok(_) => sender.send(DebuggerEvent::Eof).expect(CHANNEL_CLOSED_PANIC),
Err(error) => sender
.send(DebuggerEvent::Error(error.to_string()))
Expand Down Expand Up @@ -364,6 +386,7 @@ impl Default for DebuggerContext {
grammar: None,
input: None,
breakpoints: Arc::new(Mutex::new(HashSet::new())),
tracing_config: Default::default(),
}
}
}
Expand Down
Loading

0 comments on commit 74c00ed

Please sign in to comment.