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: add long versions of the commands as well as all of their prefixes #1062

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Changes from 1 commit
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
75 changes: 55 additions & 20 deletions debugger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ impl Cli {
println!(
"\n\
Use the following commands:\n\
g <grammar filename> - load .pest grammar\n\
i <input filename> - load input from a file\n\
id <input text> - load input directly from a single-line input\n\
ba - add breakpoints at all rules\n\
b <rule> - add a breakpoint at a rule\n\
d <rule> - delete a breakpoint at a rule\n\
da - delete all breakpoints\n\
r <rule> - run a rule\n\
c - continue\n\
l - list breakpoints\n\
h - help\n\
g(grammar) <grammar filename> - load .pest grammar\n\
i(input) <input filename> - load input from a file\n\
id <input text> - load input directly from a single-line input\n\
ba - add breakpoints at all rules\n\
b(breakpoint) <rule> - add a breakpoint at a rule\n\
d(delete) <rule> - delete a breakpoint at a rule\n\
da - delete all breakpoints\n\
r(run) <rule> - run a rule\n\
c(continue) - continue\n\
l(list) - list breakpoints\n\
h(help) - help\n\
"
);
}
Expand All @@ -128,22 +128,57 @@ impl Cli {
fn execute_command(&mut self, command: &str) -> Result<(), DebuggerError> {
match command {
"" => (),
"h" => Cli::help(),
"l" => self.list(),
"c" => self.cont()?,
help if "help".starts_with(help) => Cli::help(),
list if "list".starts_with(list) => self.list(),
cont if "continue".starts_with(cont) => self.cont()?,
"ba" => self.context.add_all_rules_breakpoints()?,
"da" => self.context.delete_all_breakpoints(),
x if x.starts_with("g ") => self.grammar(PathBuf::from(&x[2..]))?,
x if x.starts_with("i ") => self.input(PathBuf::from(&x[2..]))?,
grammar if "grammar".starts_with(grammar) => {
let grammar_file = grammar.find(" ").and_then(|pos| Some(&grammar[pos + 1..]));
if let Some(grammar_file) = grammar_file {
self.grammar(PathBuf::from(grammar_file))?;
} else {
println!("expected filename, usage: g(grammar) <filename>");
}
}
input if "input".starts_with(input) => {
let input_file = input.find(" ").and_then(|pos| Some(&input[pos + 1..]));
alpaylan marked this conversation as resolved.
Show resolved Hide resolved
if let Some(input_file) = input_file {
self.input(PathBuf::from(input_file))?;
} else {
println!("expected filename, usage: i(input) <filename>");
}
}
x if x.starts_with("id ") => {
let input = &x[3..];
self.context.load_input_direct(input.to_owned());
}
x if x.starts_with("b ") => self.breakpoint(&x[2..]),
x if x.starts_with("d ") => {
self.context.delete_breakpoint(&x[2..]);
breakpoint if "breakpoint".starts_with(breakpoint) => {
let rule = breakpoint
.find(" ")
.and_then(|pos| Some(&breakpoint[pos + 1..]));
if let Some(rule) = rule {
self.breakpoint(rule);
} else {
println!("expected rule, usage: b(breakpoint) <rule>");
}
}
delete if "delete".starts_with(delete) => {
let rule = delete.find(" ").and_then(|pos| Some(&delete[pos + 1..]));
if let Some(rule) = rule {
self.context.delete_breakpoint(rule);
} else {
println!("expected rule, usage: d(delete) <rule>");
}
}
run if "run".starts_with(run) => {
let rule = run.find(" ").and_then(|pos| Some(&run[pos + 1..]));
if let Some(rule) = rule {
self.run(rule)?;
} else {
println!("expected rule, usage: r(run) <rule>");
}
}
x if x.starts_with("r ") => self.run(&x[2..])?,
x => Cli::unrecognized(x),
};
Ok(())
Expand Down
Loading