Skip to content

Commit

Permalink
[Cider] Documentation pass (#2268)
Browse files Browse the repository at this point in the history
Minor refactoring a documentation pass
  • Loading branch information
EclecticGriffin authored Aug 22, 2024
1 parent 8d3708d commit 7614bea
Show file tree
Hide file tree
Showing 27 changed files with 691 additions and 258 deletions.
25 changes: 24 additions & 1 deletion interp/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ pub struct Config {
}

#[derive(Default)]
/// A builder for [`Config`] struct.
///
/// ```
/// # use interp::configuration::ConfigBuilder;
/// let config = ConfigBuilder::new()
/// .quiet(false)
/// .allow_invalid_memory_access(true)
/// .dump_all_memories(true)
/// .build();
/// assert_eq!(config.quiet, false);
/// assert_eq!(config.allow_invalid_memory_access, true);
/// assert_eq!(config.dump_all_memories, true);
/// assert_eq!(config.dump_registers, false);
/// ```
pub struct ConfigBuilder {
allow_invalid_memory_access: Option<bool>,
error_on_overflow: Option<bool>,
Expand All @@ -28,41 +42,50 @@ pub struct ConfigBuilder {
}

impl ConfigBuilder {
/// Create a new [`ConfigBuilder`] with all options unset. This is the same
/// as calling [`ConfigBuilder::default`].
#[inline]
pub fn new() -> Self {
Self::default()
}

/// Sets the quiet flag to the given value.
pub fn quiet(mut self, value: bool) -> Self {
self.quiet = Some(value);
self
}

/// Sets the `allow_invalid_memory_access` flag to the given value.
pub fn allow_invalid_memory_access(mut self, value: bool) -> Self {
self.allow_invalid_memory_access = Some(value);
self
}

/// Sets the `error_on_overflow` flag to the given value.
pub fn error_on_overflow(mut self, value: bool) -> Self {
self.error_on_overflow = Some(value);
self
}

/// Sets the `allow_par_conflicts` flag to the given value.
pub fn allow_par_conflicts(mut self, value: bool) -> Self {
self.allow_par_conflicts = Some(value);
self
}

/// Sets the `dump_registers` flag to the given value.
pub fn dump_registers(mut self, value: bool) -> Self {
self.dump_registers = Some(value);
self
}

/// Sets the `dump_all_memories` flag to the given value.
pub fn dump_all_memories(mut self, value: bool) -> Self {
self.dump_all_memories = Some(value);
self
}

/// Builds a [`Config`] from the current state of the [`ConfigBuilder`]. For
/// any unset options, the default value will be used.
pub fn build(self) -> Config {
Config {
allow_par_conflicts: self.allow_par_conflicts.unwrap_or_default(),
Expand Down
1 change: 1 addition & 0 deletions interp/src/debugger/commands/command_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ impl CommandParser {
}
}

/// Parse the given string into a debugger command.
pub fn parse_command(input_str: &str) -> InterpreterResult<Command> {
let inputs = CommandParser::parse(Rule::command, input_str)?;
let input = inputs.single()?;
Expand Down
22 changes: 11 additions & 11 deletions interp/src/debugger/commands/commands.pest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
WHITESPACE = _{ " " | "\t" | NEWLINE }
WHITESPACE = _{ " " | "\t" }
dot = _{ "." }
ident_syms = _{ "_" | "-" | "'" }
num = @{ ASCII_DIGIT+ }
Expand All @@ -21,10 +21,10 @@ print_code = {
pc_fail = @{ "\\" ~ ASCII_ALPHANUMERIC* }

print = {
(^"print" | ^"p") ~ (print_code)? ~ name+
(^"print " | ^"p ") ~ (print_code)? ~ name+
}

print_state = { ^"print-state" ~ (print_code)? ~ name+ }
print_state = { ^"print-state " ~ (print_code)? ~ name+ }

print_fail = {
(^"print-state" | ^"print" | ^"p") ~ (print_code | pc_fail)?
Expand All @@ -36,7 +36,7 @@ after = { ^"after" }
watch_position = { before | after }

watch = {
(^"watch" | ^"w") ~ (watch_position)? ~ group ~ ^"with" ~ (print_state | print)
(^"watch " | ^"w ") ~ (watch_position)? ~ group ~ (^"with")? ~ (print_state | print)
}

step_over = { ^"step-over" ~ group }
Expand All @@ -52,18 +52,18 @@ display = { ^"display" | ^"d" }
info_break = { (^"info" ~ ^"break") | ^"i" ~ ^"b" }
info_watch = { (^"info" ~ ^"watch") | ^"i" ~ ^"w" }

brk = { (^"break" | ^"br") ~ group+ }
brk = { (^"break " | ^"br ") ~ group+ }
brk_id = { (group | num) }

delete = { (^"delete" | ^"del") ~ brk_id+ }
delete = { (^"delete " | ^"del ") ~ brk_id+ }

delete_watch = { (^"delete-watch" | ^"del-watch") ~ brk_id+ }
delete_watch = { (^"delete-watch " | ^"del-watch " | ^"delw ") ~ brk_id+ }

enable = { (^"enable" | ^"en") ~ brk_id+ }
disable = { (^"disable" | ^"dis") ~ brk_id+ }
enable = { (^"enable " | ^"en ") ~ brk_id+ }
disable = { (^"disable " | ^"dis ") ~ brk_id+ }

enable_watch = { (^"enable-watch" | ^"enw") ~ brk_id+ }
disable_watch = { (^"disable-watch" | ^"disw") ~ brk_id+ }
enable_watch = { (^"enable-watch " | ^"enw ") ~ brk_id+ }
disable_watch = { (^"disable-watch " | ^"disw ") ~ brk_id+ }

exit = { ^"exit" | ^"quit" }

Expand Down
Loading

0 comments on commit 7614bea

Please sign in to comment.