diff --git a/src/lib.rs b/src/lib.rs index 2090f40..4a9b0f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,7 +171,7 @@ impl Parser { Action::None => (), action => { self.perform_action(performer, action, $arg); - } + }, } }; } @@ -180,18 +180,18 @@ impl Parser { State::Anywhere => { // Just run the action self.perform_action(performer, action, byte); - } + }, state => { match self.state { State::DcsPassthrough => { self.perform_action(performer, Action::Unhook, byte); - } + }, State::OscString => { self.perform_action(performer, Action::OscEnd, byte); - } + }, State::OpaqueString => { self.perform_action(performer, Action::OpaqueEnd, byte); - } + }, _ => (), } @@ -200,22 +200,22 @@ impl Parser { match state { State::CsiEntry | State::DcsEntry | State::Escape => { self.perform_action(performer, Action::Clear, byte); - } + }, State::DcsPassthrough => { self.perform_action(performer, Action::Hook, byte); - } + }, State::OscString => { self.perform_action(performer, Action::OscStart, byte); - } + }, State::OpaqueString => { self.perform_action(performer, Action::OpaqueStart, byte); - } + }, _ => (), } // Assume the new state self.state = state; - } + }, } } @@ -252,12 +252,12 @@ impl Parser { } performer.hook(self.params(), self.intermediates(), self.ignoring, byte as char); - } + }, Action::Put => performer.put(byte), Action::OscStart => { self.osc_raw.clear(); self.osc_num_params = 0; - } + }, Action::OscPut => { #[cfg(feature = "no_std")] { @@ -278,21 +278,21 @@ impl Parser { // First param is special - 0 to current byte index 0 => { self.osc_params[param_idx] = (0, idx); - } + }, // All other params depend on previous indexing _ => { let prev = self.osc_params[param_idx - 1]; let begin = prev.1; self.osc_params[param_idx] = (begin, idx); - } + }, } self.osc_num_params += 1; } else { self.osc_raw.push(byte); } - } + }, Action::OscEnd => { let param_idx = self.osc_num_params; let idx = self.osc_raw.len(); @@ -305,7 +305,7 @@ impl Parser { 0 => { self.osc_params[param_idx] = (0, idx); self.osc_num_params += 1; - } + }, // All other params depend on previous indexing _ => { @@ -313,10 +313,10 @@ impl Parser { let begin = prev.1; self.osc_params[param_idx] = (begin, idx); self.osc_num_params += 1; - } + }, } self.osc_dispatch(performer, byte); - } + }, Action::Unhook => performer.unhook(), Action::CsiDispatch => { if self.params.is_full() { @@ -331,10 +331,10 @@ impl Parser { self.ignoring, byte as char, ); - } + }, Action::EscDispatch => { performer.esc_dispatch(self.intermediates(), self.ignoring, byte); - } + }, Action::Collect => { if self.intermediate_idx == MAX_INTERMEDIATES { self.ignoring = true; @@ -342,7 +342,7 @@ impl Parser { self.intermediates[self.intermediate_idx] = byte; self.intermediate_idx += 1; } - } + }, Action::Param => { if self.params.is_full() { self.ignoring = true; @@ -360,7 +360,7 @@ impl Parser { self.param = self.param.saturating_mul(10); self.param = self.param.saturating_add((byte - b'0') as u16); } - } + }, Action::Clear => { // Reset everything on ESC/CSI/DCS entry self.intermediate_idx = 0; @@ -368,7 +368,7 @@ impl Parser { self.param = 0; self.params.clear(); - } + }, Action::BeginUtf8 => self.process_utf8(performer, byte), Action::Ignore => (), Action::None => (), @@ -392,7 +392,7 @@ impl Parser { OpaqueSequenceKind::Pm => performer.pm_start(), OpaqueSequenceKind::Apc => performer.apc_start(), } - } + }, Action::OpaquePut => { match self.opaque_sequence_kind { Some(OpaqueSequenceKind::Sos) => performer.sos_put(byte), @@ -402,7 +402,7 @@ impl Parser { // that the opaque_sequence_kind is set to a Some(x) value. None => unreachable!("opaque sequence kind not set"), } - } + }, Action::OpaqueEnd => { match self.opaque_sequence_kind { Some(OpaqueSequenceKind::Sos) => performer.sos_end(), @@ -413,7 +413,7 @@ impl Parser { None => unreachable!("opaque sequence kind not set"), } self.opaque_sequence_kind = None; - } + }, } } } @@ -470,7 +470,8 @@ pub trait Perform { _intermediates: &[u8], _ignore: bool, _action: char, - ) {} + ) { + } /// The final character of an escape sequence has arrived. /// @@ -639,7 +640,7 @@ mod tests { assert_eq!(params.len(), 2); assert_eq!(params[0], &OSC_BYTES[2..3]); assert_eq!(params[1], &OSC_BYTES[4..(OSC_BYTES.len() - 1)]); - } + }, _ => panic!("expected osc sequence"), } } @@ -676,7 +677,7 @@ mod tests { Sequence::Osc(params, _) => { assert_eq!(params.len(), MAX_OSC_PARAMS); assert!(params.iter().all(Vec::is_empty)); - } + }, _ => panic!("expected osc sequence"), } } @@ -734,7 +735,7 @@ mod tests { Sequence::Osc(params, _) => { assert_eq!(params[0], &[b'2']); assert_eq!(params[1], &INPUT[5..(INPUT.len() - 1)]); - } + }, _ => panic!("expected osc sequence"), } } @@ -753,7 +754,7 @@ mod tests { match &dispatcher.dispatched[0] { Sequence::Osc(params, _) => { assert_eq!(params[1], &INPUT[4..(INPUT.len() - 2)]); - } + }, _ => panic!("expected osc sequence"), } } @@ -859,7 +860,7 @@ mod tests { #[cfg(feature = "no_std")] assert_eq!(params[1].len(), MAX_OSC_RAW - params[0].len()); - } + }, _ => panic!("expected osc sequence"), } } @@ -884,7 +885,7 @@ mod tests { Sequence::Csi(params, _, ignore, _) => { assert_eq!(params.len(), params::MAX_PARAMS); assert!(!ignore); - } + }, _ => panic!("expected csi sequence"), } } @@ -909,7 +910,7 @@ mod tests { Sequence::Csi(params, _, ignore, _) => { assert_eq!(params.len(), params::MAX_PARAMS); assert!(ignore); - } + }, _ => panic!("expected csi sequence"), } } @@ -981,7 +982,7 @@ mod tests { assert_eq!(intermediates, &[b'?']); assert_eq!(params, &[[1049]]); assert!(!ignore); - } + }, _ => panic!("expected csi sequence"), } } @@ -1002,7 +1003,7 @@ mod tests { assert_eq!(params, &[vec![38, 2, 255, 0, 255], vec![1]]); assert_eq!(intermediates, &[]); assert!(!ignore); - } + }, _ => panic!("expected csi sequence"), } } @@ -1024,7 +1025,7 @@ mod tests { assert_eq!(params.len(), params::MAX_PARAMS); assert!(params.iter().all(|param| param == &[1])); assert!(ignore); - } + }, _ => panic!("expected dcs sequence"), } } @@ -1045,7 +1046,7 @@ mod tests { assert_eq!(intermediates, &[b'$']); assert_eq!(params, &[[1]]); assert!(!ignore); - } + }, _ => panic!("expected dcs sequence"), } assert_eq!(dispatcher.dispatched[1], Sequence::DcsPut(b'x')); @@ -1067,7 +1068,7 @@ mod tests { Sequence::DcsHook(params, _, _, c) => { assert_eq!(params, &[[0], [1]]); assert_eq!(c, &'|'); - } + }, _ => panic!("expected dcs sequence"), } for (i, byte) in b"17/ab".iter().enumerate() { @@ -1109,7 +1110,7 @@ mod tests { assert_eq!(intermediates, &[b'(']); assert_eq!(*byte, b'A'); assert!(!ignore); - } + }, _ => panic!("expected esc sequence"), } } @@ -1131,7 +1132,7 @@ mod tests { assert_eq!(params, &[[0; 32]]); assert_eq!(c, &'x'); assert!(ignore); - } + }, _ => panic!("expected csi sequence"), } } @@ -1153,7 +1154,7 @@ mod tests { assert_eq!(intermediates, &[b'?']); assert_eq!(params, &[[1049]]); assert!(!ignore); - } + }, _ => panic!("expected csi sequence"), } } @@ -1193,7 +1194,7 @@ mod tests { for item in params[1].iter() { assert_eq!(*item, b'a'); } - } + }, _ => panic!("expected osc sequence"), } } @@ -1223,7 +1224,7 @@ mod tests { Sequence::Osc(params, false) => { assert_eq!(params[0], b"2"); assert_eq!(params[1], INPUT_MIDDLE); - } + }, _ => panic!("expected osc sequence"), } }