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

Debugger tweaks, added tracing #1080

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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
Loading