diff options
Diffstat (limited to 'chain/src/atom')
-rw-r--r-- | chain/src/atom/default.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/chain/src/atom/default.rs b/chain/src/atom/default.rs index e88cfc9..9c91296 100644 --- a/chain/src/atom/default.rs +++ b/chain/src/atom/default.rs @@ -48,18 +48,31 @@ pub struct DefaultAtom { impl DefaultAtom { /// Return the string description of a rule position. pub fn rule_pos_string(&self, pos: usize) -> Result<String, Box<dyn std::error::Error>> { + if pos == self.grammar.total() { + return Ok("End of rules".to_owned()); + } + let rule_num = self.grammar.get_rule_num(pos)?; assert!(rule_num < self.grammar.non_num()); - let display_tnt = |tnt| self.name_of_tnt(tnt).unwrap_or_else(|e| format!("{e}")); + let display_tnt = |tnt| { + format!( + " {} ", + self.name_of_tnt(match tnt { + TNT::Non(_) => tnt, + TNT::Ter(t) => self.unpack_tnt(t).unwrap(), + }) + .unwrap_or_else(|e| format!("{e}")) + ) + }; Ok(self.regexp.get(rule_num).unwrap().to_string_with_dot( display_tnt, if rule_num == 0 { pos } else { - pos - self.grammar.nth_accumulator(rule_num - 1)? + pos - self.grammar.nth_accumulator(rule_num)? }, )?) } @@ -394,8 +407,6 @@ impl DefaultAtom { } } - // dbg!(&accumulators); - for nt in 0..nt_num { let children: std::collections::HashMap<_, _> = nfa // This is safe because of the above assertion. |