vtparse: avoid build.rs codegen
Change build.rs codegen to const_fns. This makes vtparse more friendly for buck build. Note const_fn functions still have limitation on the current stable (1.41) rustc (ex. native "match" or "if" cannot be used in const_fn). So I used some tricks to get it compile.
This commit is contained in:
1 parent
412d0de7f5
commit
2dc4cfe61d
3 files changed
+353
-387
No files matched your search
@@ -1,386 +0,0 @@
|
||||
// Builds up the transition table for a state machine based on
|
||||
// https://vt100.net/emu/dec_ansi_parser
|
||||
use std::collections::HashMap;
|
||||
use std::io::prelude::*;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
#[path = "src/enums.rs"]
|
||||
mod enums;
|
||||
use crate::enums::*;
|
||||
|
||||
type StateMap = HashMap<u8, (Action, State)>;
|
||||
|
||||
fn r(key: u8) -> RangeInclusive<u8> {
|
||||
key..=key
|
||||
}
|
||||
|
||||
fn insert(map: &mut StateMap, keys: RangeInclusive<u8>, value: (Action, State)) {
|
||||
for k in keys {
|
||||
map.insert(k, value);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! sparse_table {
|
||||
($( $key:expr => ($action:ident, $state:ident) ),* $(,)?) => {
|
||||
{
|
||||
let mut map = StateMap::new();
|
||||
|
||||
$(
|
||||
insert(&mut map, $key, (Action::$action, State::$state));
|
||||
)*
|
||||
|
||||
map
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_anywhere(anywhere: &StateMap, mut map: StateMap) -> StateMap {
|
||||
for (k, v) in anywhere {
|
||||
map.insert(*k, *v);
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
struct Tables {
|
||||
transitions: HashMap<State, StateMap>,
|
||||
entry: HashMap<State, Action>,
|
||||
exit: HashMap<State, Action>,
|
||||
}
|
||||
|
||||
fn build_tables() -> Tables {
|
||||
let mut transitions = HashMap::new();
|
||||
let mut entry = HashMap::new();
|
||||
let mut exit = HashMap::new();
|
||||
|
||||
let anywhere = sparse_table! {
|
||||
r(0x18) => (Execute, Ground),
|
||||
r(0x1a) => (Execute, Ground),
|
||||
0x80..=0x8f => (Execute, Ground),
|
||||
0x91..=0x97 => (Execute, Ground),
|
||||
r(0x99) => (Execute, Ground),
|
||||
r(0x9a) => (Execute, Ground),
|
||||
r(0x9c) => (None, Ground),
|
||||
r(0x1b) => (None, Escape),
|
||||
r(0x98) => (None, SosPmApcString),
|
||||
r(0x9e) => (None, SosPmApcString),
|
||||
r(0x9f) => (None, SosPmApcString),
|
||||
r(0x90) => (None, DcsEntry),
|
||||
r(0x9d) => (None, OscString),
|
||||
r(0x9b) => (None, CsiEntry),
|
||||
};
|
||||
|
||||
transitions.insert(
|
||||
State::Ground,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, Ground),
|
||||
r(0x19) => (Execute, Ground),
|
||||
0x1c..=0x1f => (Execute, Ground),
|
||||
0x20..=0x7f => (Print, Ground),
|
||||
// The following three ranges allow for
|
||||
// UTF-8 multibyte sequences to be recognized
|
||||
// and emitted as byte sequences in the ground
|
||||
// state.
|
||||
0xc2..=0xdf => (Utf8, Utf8Sequence),
|
||||
0xe0..=0xef => (Utf8, Utf8Sequence),
|
||||
0xf0..=0xf4 => (Utf8, Utf8Sequence),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
entry.insert(State::Escape, Action::Clear);
|
||||
transitions.insert(
|
||||
State::Escape,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, Escape),
|
||||
r(0x19) => (Execute, Escape),
|
||||
0x1c..=0x1f => (Execute, Escape),
|
||||
r(0x7f) => (Ignore, Escape),
|
||||
0x20..=0x2f => (Collect, EscapeIntermediate),
|
||||
0x30..=0x4f => (EscDispatch, Ground),
|
||||
0x51..=0x57 => (EscDispatch, Ground),
|
||||
r(0x59) => (EscDispatch, Ground),
|
||||
r(0x5a) => (EscDispatch, Ground),
|
||||
r(0x5c) => (EscDispatch, Ground),
|
||||
0x60..=0x7e => (EscDispatch, Ground),
|
||||
r(0x5b) => (None, CsiEntry),
|
||||
r(0x5d) => (None, OscString),
|
||||
r(0x50) => (None, DcsEntry),
|
||||
r(0x58) => (None, SosPmApcString),
|
||||
r(0x5e) => (None, SosPmApcString),
|
||||
r(0x5f) => (None, SosPmApcString),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::EscapeIntermediate,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, EscapeIntermediate),
|
||||
r(0x19) => (Execute, EscapeIntermediate),
|
||||
0x1c..=0x1f => (Execute, EscapeIntermediate),
|
||||
0x20..=0x2f => (Collect, EscapeIntermediate),
|
||||
r(0x7f) => (Ignore, EscapeIntermediate),
|
||||
0x30..=0x7e => (EscDispatch, Ground),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
entry.insert(State::CsiEntry, Action::Clear);
|
||||
transitions.insert(
|
||||
State::CsiEntry,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, CsiEntry),
|
||||
r(0x19) => (Execute, CsiEntry),
|
||||
0x1c..=0x1f => (Execute, CsiEntry),
|
||||
r(0x7f) => (Ignore, CsiEntry),
|
||||
0x20..=0x2f => (Collect, CsiIntermediate),
|
||||
r(0x3a) => (None, CsiIgnore),
|
||||
0x30..=0x39 => (Param, CsiParam),
|
||||
r(0x3b) => (Param, CsiParam),
|
||||
0x3c..=0x3f => (Collect, CsiParam),
|
||||
0x40..=0x7e => (CsiDispatch, Ground),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::CsiIgnore,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, CsiIgnore),
|
||||
r(0x19) => (Execute, CsiIgnore),
|
||||
0x1c..=0x1f => (Execute, CsiIgnore),
|
||||
0x20..=0x3f => (Ignore, CsiIgnore),
|
||||
r(0x7f) => (Ignore, CsiIgnore),
|
||||
0x40..=0x7e => (None, Ground),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::CsiParam,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, CsiParam),
|
||||
r(0x19) => (Execute, CsiParam),
|
||||
0x1c..=0x1f => (Execute, CsiParam),
|
||||
0x30..=0x39 => (Param, CsiParam),
|
||||
r(0x3b) => (Param, CsiParam),
|
||||
r(0x7f) => (Ignore, CsiParam),
|
||||
r(0x3a) => (None, CsiIgnore),
|
||||
0x3c..=0x3f => (None, CsiIgnore),
|
||||
0x20..=0x2f => (Collect, CsiIntermediate),
|
||||
0x40..=0x7e => (CsiDispatch, Ground),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::CsiIntermediate,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Execute, CsiIntermediate),
|
||||
r(0x19) => (Execute, CsiIntermediate),
|
||||
0x1c..=0x1f => (Execute, CsiIntermediate),
|
||||
0x20..=0x2f => (Collect, CsiIntermediate),
|
||||
r(0x7f) => (Ignore, CsiIntermediate),
|
||||
0x30..=0x3f => (None, CsiIgnore),
|
||||
0x40..=0x7e => (CsiDispatch, Ground),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
entry.insert(State::DcsEntry, Action::Clear);
|
||||
transitions.insert(
|
||||
State::DcsEntry,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Ignore, DcsEntry),
|
||||
r(0x19) => (Ignore, DcsEntry),
|
||||
0x1c..=0x1f => (Ignore, DcsEntry),
|
||||
r(0x7f) => (Ignore, DcsEntry),
|
||||
r(0x3a) => (None, DcsIgnore),
|
||||
0x20..=0x2f => (Collect, DcsIntermediate),
|
||||
0x30..=0x39 => (Param, DcsParam),
|
||||
r(0x3b) => (Param, DcsParam),
|
||||
0x3c..=0x3f => (Collect, DcsParam),
|
||||
0x40..=0x7e => (None, DcsPassthrough),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::DcsIntermediate,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Ignore, DcsIntermediate),
|
||||
r(0x19) => (Ignore, DcsIntermediate),
|
||||
0x1c..=0x1f => (Ignore, DcsIntermediate),
|
||||
0x20..=0x2f => (Collect, DcsIntermediate),
|
||||
r(0x7f) => (Ignore, DcsIntermediate),
|
||||
0x30..=0x3f => (None, DcsIgnore),
|
||||
0x40..=0x7e => (None, DcsPassthrough),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::DcsIgnore,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Ignore, DcsIgnore),
|
||||
r(0x19) => (Ignore, DcsIgnore),
|
||||
0x1c..=0x1f => (Ignore, DcsIgnore),
|
||||
0x20..=0x7f => (Ignore, DcsIgnore),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::DcsParam,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Ignore, DcsParam),
|
||||
r(0x19) => (Ignore, DcsParam),
|
||||
0x1c..=0x1f => (Ignore, DcsParam),
|
||||
0x30..=0x39 => (Param, DcsParam),
|
||||
r(0x3b) => (Param, DcsParam),
|
||||
r(0x7f) => (Ignore, DcsParam),
|
||||
r(0x3a) => (None, DcsIgnore),
|
||||
0x3c..=0x3f => (None, DcsIgnore),
|
||||
0x20..=0x2f => (Collect, DcsIntermediate),
|
||||
0x40..=0x7e => (None, DcsPassthrough),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
entry.insert(State::DcsPassthrough, Action::Hook);
|
||||
exit.insert(State::DcsPassthrough, Action::Unhook);
|
||||
transitions.insert(
|
||||
State::DcsPassthrough,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Put, DcsPassthrough),
|
||||
r(0x19) => (Put, DcsPassthrough),
|
||||
0x1c..=0x1f => (Put, DcsPassthrough),
|
||||
0x20..=0x7e => (Put, DcsPassthrough),
|
||||
r(0x7f) => (Ignore, DcsPassthrough),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
transitions.insert(
|
||||
State::SosPmApcString,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x17 => (Ignore, SosPmApcString),
|
||||
r(0x19) => (Ignore, SosPmApcString),
|
||||
0x1c..=0x1f => (Ignore, SosPmApcString),
|
||||
0x20..=0x7f => (Ignore, SosPmApcString),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
entry.insert(State::OscString, Action::OscStart);
|
||||
exit.insert(State::OscString, Action::OscEnd);
|
||||
transitions.insert(
|
||||
State::OscString,
|
||||
apply_anywhere(
|
||||
&anywhere,
|
||||
sparse_table! {
|
||||
0x00..=0x06 => (Ignore, OscString),
|
||||
// Using BEL in place of ST is a deviation from
|
||||
// https://vt100.net/emu/dec_ansi_parser and was
|
||||
// introduced AFAICT by xterm
|
||||
r(0x07) => (Ignore, Ground),
|
||||
0x08..=0x17 => (Ignore, OscString),
|
||||
r(0x19) => (Ignore, OscString),
|
||||
0x1c..=0x1f => (Ignore, OscString),
|
||||
0x20..=0x7f => (OscPut, OscString),
|
||||
// This extended range allows for UTF-8 characters
|
||||
// to be embedded in OSC parameters. It is not
|
||||
// part of the base state machine.
|
||||
0xc2..=0xdf => (Utf8, Utf8Sequence),
|
||||
0xe0..=0xef => (Utf8, Utf8Sequence),
|
||||
0xf0..=0xf4 => (Utf8, Utf8Sequence),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Tables {
|
||||
transitions,
|
||||
entry,
|
||||
exit,
|
||||
}
|
||||
}
|
||||
|
||||
fn pack(action: Action, state: State) -> u8 {
|
||||
((action as u8) << 4) | (state as u8)
|
||||
}
|
||||
|
||||
fn write_tables(dest_path: std::path::PathBuf, tables: &Tables) -> std::io::Result<()> {
|
||||
let mut f = std::fs::File::create(&dest_path)?;
|
||||
writeln!(f, "static TRANSITIONS: [[u8; 256]; 14] = [")?;
|
||||
for state_num in State::Ground as u8..State::Anywhere as u8 {
|
||||
let this_state = State::from_u8(state_num);
|
||||
writeln!(f, " // State: {:?}", this_state)?;
|
||||
write!(f, " [")?;
|
||||
let state_transitions = tables.transitions.get(&this_state).unwrap();
|
||||
for byte in 0u8..=0xff {
|
||||
let (action, state) = state_transitions
|
||||
.get(&byte)
|
||||
.cloned()
|
||||
.unwrap_or((Action::None, this_state));
|
||||
if byte % 12 == 0 {
|
||||
write!(f, "\n ")?;
|
||||
}
|
||||
write!(f, " 0x{:02x},", pack(action, state))?;
|
||||
}
|
||||
writeln!(f, " ],")?;
|
||||
}
|
||||
writeln!(f, "];")?;
|
||||
|
||||
event_table("ENTRY", &mut f, &tables.entry)?;
|
||||
event_table("EXIT", &mut f, &tables.exit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn event_table(
|
||||
label: &str,
|
||||
f: &mut std::fs::File,
|
||||
table: &HashMap<State, Action>,
|
||||
) -> std::io::Result<()> {
|
||||
writeln!(f, "static {}: [Action; 14] = [", label)?;
|
||||
for state_num in State::Ground as u8..State::Anywhere as u8 {
|
||||
let this_state = State::from_u8(state_num);
|
||||
let action = table.get(&this_state).cloned().unwrap_or(Action::None);
|
||||
writeln!(f, " Action::{:?}, // {:?}", action, this_state)?;
|
||||
}
|
||||
writeln!(f, "];")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let out_dir = std::env::var("OUT_DIR").unwrap();
|
||||
let dest_path = std::path::Path::new(&out_dir).join("transitions.rs");
|
||||
|
||||
let tables = build_tables();
|
||||
write_tables(dest_path, &tables).unwrap();
|
||||
}
|
||||
+2
-1
@@ -13,8 +13,9 @@
|
||||
use utf8parse::Parser as Utf8Parser;
|
||||
mod enums;
|
||||
use crate::enums::*;
|
||||
mod transitions;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/transitions.rs"));
|
||||
use transitions::{ENTRY, EXIT, TRANSITIONS};
|
||||
|
||||
#[inline(always)]
|
||||
fn lookup(state: State, b: u8) -> (Action, State) {
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
// Builds up the transition table for a state machine based on
|
||||
// https://vt100.net/emu/dec_ansi_parser
|
||||
|
||||
use crate::enums::{Action, State};
|
||||
|
||||
/// Returns 1 if a <= x and x <= b. Otherwise returns 0.
|
||||
const fn in_range(x: u8, a: u8, b: u8) -> u8 {
|
||||
((x <= b) as u8) & ((a <= x) as u8)
|
||||
}
|
||||
|
||||
/// Returns `true_value` if `condition` is true. Otherwise returns `false_value`.
|
||||
const fn cond(condition: bool, true_value: u8, false_value: u8) -> u8 {
|
||||
((condition as u8) * true_value) | ((!condition as u8) * false_value)
|
||||
}
|
||||
|
||||
/// Match `u8` using given patterns. Return `OptionPack`.
|
||||
/// The patterns should not overlap.
|
||||
///
|
||||
/// This should really be just a normal `match { .. }`
|
||||
/// statement. However `match` is not const_fn right now.
|
||||
/// See https://github.com/rust-lang/rust/issues/49146.
|
||||
macro_rules! match_action_state {
|
||||
( $name:ident => {
|
||||
$( $a:tt $( ..= $b:tt )? => ($action:ident, $state:ident), )*
|
||||
}) => {
|
||||
OptionPack(
|
||||
$(
|
||||
({
|
||||
// B: $b if $b exists, or $a if $b does not exist.
|
||||
const B: u8 = [$a $(,$b)?][[$a $(,$b)?].len() - 1];
|
||||
in_range($name, $a, B) as u16 * OptionPack::pack(Action::$action, State::$state).0
|
||||
}) |
|
||||
)* 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Define `fn(u8) -> u8`.
|
||||
macro_rules! define_function {
|
||||
( $( $state:tt $func_name:ident { $($body:tt)* } )* ) => {
|
||||
$(
|
||||
const fn $func_name(i: u8) -> u8 {
|
||||
let v = match_action_state! { i => { $($body)* } };
|
||||
v.or(anywhere(i).or(pack(Action::None, State::$state)))
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
/// Apply all u8 values to `fn(u8) -> u8`, return `[u8; 256]`.
|
||||
macro_rules! define_table {
|
||||
( $func:tt ) => {
|
||||
define_table!( func=$func result=[] iter=(0) remaining=[i i i i i i i i i i i i i i i i] )
|
||||
};
|
||||
|
||||
( func=$func:tt result=[$($result:tt)*] iter=($($iter:tt)*) remaining=[]) => {
|
||||
[ $($result, )* ]
|
||||
};
|
||||
|
||||
( func=$func:tt result=[$($result:tt)*] iter=($($iter:tt)*) remaining=[i $($remaining:tt)*]) => {
|
||||
define_table! (
|
||||
func=$func
|
||||
result=[
|
||||
$($result)*
|
||||
($func($($iter)*))
|
||||
($func($($iter)* + 1))
|
||||
($func($($iter)* + 2))
|
||||
($func($($iter)* + 3))
|
||||
($func($($iter)* + 4))
|
||||
($func($($iter)* + 5))
|
||||
($func($($iter)* + 6))
|
||||
($func($($iter)* + 7))
|
||||
($func($($iter)* + 8))
|
||||
($func($($iter)* + 9))
|
||||
($func($($iter)* + 10))
|
||||
($func($($iter)* + 11))
|
||||
($func($($iter)* + 12))
|
||||
($func($($iter)* + 13))
|
||||
($func($($iter)* + 14))
|
||||
($func($($iter)* + 15))
|
||||
]
|
||||
iter=($($iter)*+16)
|
||||
remaining=[$($remaining)*]
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
/// An alternative form of `Option<u8>` that works with const_fn.
|
||||
///
|
||||
/// This should really be just an `Option<u8>`. However that is
|
||||
/// hard to express in const_fn right now.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
struct OptionPack(u16);
|
||||
|
||||
impl OptionPack {
|
||||
const fn is_none(self) -> bool {
|
||||
(self.0 & 1) == 0
|
||||
}
|
||||
|
||||
const fn to_u8(self) -> u8 {
|
||||
(self.0 >> 1) as u8
|
||||
}
|
||||
|
||||
const fn pack(action: Action, state: State) -> Self {
|
||||
Self(1 | ((((action as u16) << 4) | (state as u16)) << 1))
|
||||
}
|
||||
|
||||
const fn or(self, default: u8) -> u8 {
|
||||
cond(self.is_none(), default, self.to_u8())
|
||||
}
|
||||
}
|
||||
|
||||
const fn pack(action: Action, state: State) -> u8 {
|
||||
((action as u8) << 4) | (state as u8)
|
||||
}
|
||||
|
||||
const fn anywhere(i: u8) -> OptionPack {
|
||||
match_action_state! { i => {
|
||||
0x18 => (Execute, Ground),
|
||||
0x1a => (Execute, Ground),
|
||||
0x80..=0x8f => (Execute, Ground),
|
||||
0x91..=0x97 => (Execute, Ground),
|
||||
0x99 => (Execute, Ground),
|
||||
0x9a => (Execute, Ground),
|
||||
0x9c => (None, Ground),
|
||||
0x1b => (None, Escape),
|
||||
0x98 => (None, SosPmApcString),
|
||||
0x9e => (None, SosPmApcString),
|
||||
0x9f => (None, SosPmApcString),
|
||||
0x90 => (None, DcsEntry),
|
||||
0x9d => (None, OscString),
|
||||
0x9b => (None, CsiEntry),
|
||||
} }
|
||||
}
|
||||
|
||||
define_function! {
|
||||
Ground ground {
|
||||
0x00..=0x17 => (Execute, Ground),
|
||||
0x19 => (Execute, Ground),
|
||||
0x1c..=0x1f => (Execute, Ground),
|
||||
0x20..=0x7f => (Print, Ground),
|
||||
// The following three ranges allow for
|
||||
// UTF-8 multibyte sequences to be recognized
|
||||
// and emitted as byte sequences in the ground
|
||||
// state.
|
||||
0xc2..=0xdf => (Utf8, Utf8Sequence),
|
||||
0xe0..=0xef => (Utf8, Utf8Sequence),
|
||||
0xf0..=0xf4 => (Utf8, Utf8Sequence),
|
||||
}
|
||||
|
||||
Escape escape {
|
||||
0x00..=0x17 => (Execute, Escape),
|
||||
0x19 => (Execute, Escape),
|
||||
0x1c..=0x1f => (Execute, Escape),
|
||||
0x7f => (Ignore, Escape),
|
||||
0x20..=0x2f => (Collect, EscapeIntermediate),
|
||||
0x30..=0x4f => (EscDispatch, Ground),
|
||||
0x51..=0x57 => (EscDispatch, Ground),
|
||||
0x59 => (EscDispatch, Ground),
|
||||
0x5a => (EscDispatch, Ground),
|
||||
0x5c => (EscDispatch, Ground),
|
||||
0x60..=0x7e => (EscDispatch, Ground),
|
||||
0x5b => (None, CsiEntry),
|
||||
0x5d => (None, OscString),
|
||||
0x50 => (None, DcsEntry),
|
||||
0x58 => (None, SosPmApcString),
|
||||
0x5e => (None, SosPmApcString),
|
||||
0x5f => (None, SosPmApcString),
|
||||
}
|
||||
|
||||
EscapeIntermediate escape_intermediate {
|
||||
0x00..=0x17 => (Execute, EscapeIntermediate),
|
||||
0x19 => (Execute, EscapeIntermediate),
|
||||
0x1c..=0x1f => (Execute, EscapeIntermediate),
|
||||
0x20..=0x2f => (Collect, EscapeIntermediate),
|
||||
0x7f => (Ignore, EscapeIntermediate),
|
||||
0x30..=0x7e => (EscDispatch, Ground),
|
||||
}
|
||||
|
||||
CsiEntry csi_entry {
|
||||
0x00..=0x17 => (Execute, CsiEntry),
|
||||
0x19 => (Execute, CsiEntry),
|
||||
0x1c..=0x1f => (Execute, CsiEntry),
|
||||
0x7f => (Ignore, CsiEntry),
|
||||
0x20..=0x2f => (Collect, CsiIntermediate),
|
||||
0x3a => (None, CsiIgnore),
|
||||
0x30..=0x39 => (Param, CsiParam),
|
||||
0x3b => (Param, CsiParam),
|
||||
0x3c..=0x3f => (Collect, CsiParam),
|
||||
0x40..=0x7e => (CsiDispatch, Ground),
|
||||
}
|
||||
|
||||
CsiParam csi_param {
|
||||
0x00..=0x17 => (Execute, CsiParam),
|
||||
0x19 => (Execute, CsiParam),
|
||||
0x1c..=0x1f => (Execute, CsiParam),
|
||||
0x30..=0x39 => (Param, CsiParam),
|
||||
0x3b => (Param, CsiParam),
|
||||
0x7f => (Ignore, CsiParam),
|
||||
0x3a => (None, CsiIgnore),
|
||||
0x3c..=0x3f => (None, CsiIgnore),
|
||||
0x20..=0x2f => (Collect, CsiIntermediate),
|
||||
0x40..=0x7e => (CsiDispatch, Ground),
|
||||
}
|
||||
|
||||
CsiIntermediate csi_intermediate {
|
||||
0x00..=0x17 => (Execute, CsiIntermediate),
|
||||
0x19 => (Execute, CsiIntermediate),
|
||||
0x1c..=0x1f => (Execute, CsiIntermediate),
|
||||
0x20..=0x2f => (Collect, CsiIntermediate),
|
||||
0x7f => (Ignore, CsiIntermediate),
|
||||
0x30..=0x3f => (None, CsiIgnore),
|
||||
0x40..=0x7e => (CsiDispatch, Ground),
|
||||
}
|
||||
|
||||
CsiIgnore csi_ignore {
|
||||
0x00..=0x17 => (Execute, CsiIgnore),
|
||||
0x19 => (Execute, CsiIgnore),
|
||||
0x1c..=0x1f => (Execute, CsiIgnore),
|
||||
0x20..=0x3f => (Ignore, CsiIgnore),
|
||||
0x7f => (Ignore, CsiIgnore),
|
||||
0x40..=0x7e => (None, Ground),
|
||||
}
|
||||
|
||||
DcsEntry dcs_entry {
|
||||
0x00..=0x17 => (Ignore, DcsEntry),
|
||||
0x19 => (Ignore, DcsEntry),
|
||||
0x1c..=0x1f => (Ignore, DcsEntry),
|
||||
0x7f => (Ignore, DcsEntry),
|
||||
0x3a => (None, DcsIgnore),
|
||||
0x20..=0x2f => (Collect, DcsIntermediate),
|
||||
0x30..=0x39 => (Param, DcsParam),
|
||||
0x3b => (Param, DcsParam),
|
||||
0x3c..=0x3f => (Collect, DcsParam),
|
||||
0x40..=0x7e => (None, DcsPassthrough),
|
||||
}
|
||||
|
||||
DcsParam dcs_param {
|
||||
0x00..=0x17 => (Ignore, DcsParam),
|
||||
0x19 => (Ignore, DcsParam),
|
||||
0x1c..=0x1f => (Ignore, DcsParam),
|
||||
0x30..=0x39 => (Param, DcsParam),
|
||||
0x3b => (Param, DcsParam),
|
||||
0x7f => (Ignore, DcsParam),
|
||||
0x3a => (None, DcsIgnore),
|
||||
0x3c..=0x3f => (None, DcsIgnore),
|
||||
0x20..=0x2f => (Collect, DcsIntermediate),
|
||||
0x40..=0x7e => (None, DcsPassthrough),
|
||||
}
|
||||
|
||||
DcsIntermediate dcs_intermediate {
|
||||
0x00..=0x17 => (Ignore, DcsIntermediate),
|
||||
0x19 => (Ignore, DcsIntermediate),
|
||||
0x1c..=0x1f => (Ignore, DcsIntermediate),
|
||||
0x20..=0x2f => (Collect, DcsIntermediate),
|
||||
0x7f => (Ignore, DcsIntermediate),
|
||||
0x30..=0x3f => (None, DcsIgnore),
|
||||
0x40..=0x7e => (None, DcsPassthrough),
|
||||
}
|
||||
|
||||
DcsPassthrough dcs_passthrough {
|
||||
0x00..=0x17 => (Put, DcsPassthrough),
|
||||
0x19 => (Put, DcsPassthrough),
|
||||
0x1c..=0x1f => (Put, DcsPassthrough),
|
||||
0x20..=0x7e => (Put, DcsPassthrough),
|
||||
0x7f => (Ignore, DcsPassthrough),
|
||||
}
|
||||
|
||||
DcsIgnore dcs_ignore {
|
||||
0x00..=0x17 => (Ignore, DcsIgnore),
|
||||
0x19 => (Ignore, DcsIgnore),
|
||||
0x1c..=0x1f => (Ignore, DcsIgnore),
|
||||
0x20..=0x7f => (Ignore, DcsIgnore),
|
||||
}
|
||||
|
||||
OscString osc_string {
|
||||
0x00..=0x06 => (Ignore, OscString),
|
||||
// Using BEL in place of ST is a deviation from
|
||||
// https://vt100.net/emu/dec_ansi_parser and was
|
||||
// introduced AFAICT by xterm
|
||||
0x07 => (Ignore, Ground),
|
||||
0x08..=0x17 => (Ignore, OscString),
|
||||
0x19 => (Ignore, OscString),
|
||||
0x1c..=0x1f => (Ignore, OscString),
|
||||
0x20..=0x7f => (OscPut, OscString),
|
||||
// This extended range allows for UTF-8 characters
|
||||
// to be embedded in OSC parameters. It is not
|
||||
// part of the base state machine.
|
||||
0xc2..=0xdf => (Utf8, Utf8Sequence),
|
||||
0xe0..=0xef => (Utf8, Utf8Sequence),
|
||||
0xf0..=0xf4 => (Utf8, Utf8Sequence),
|
||||
}
|
||||
|
||||
SosPmApcString sos_pm_apc_string {
|
||||
0x00..=0x17 => (Ignore, SosPmApcString),
|
||||
0x19 => (Ignore, SosPmApcString),
|
||||
0x1c..=0x1f => (Ignore, SosPmApcString),
|
||||
0x20..=0x7f => (Ignore, SosPmApcString),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) static TRANSITIONS: [[u8; 256]; 14] = [
|
||||
define_table!(ground),
|
||||
define_table!(escape),
|
||||
define_table!(escape_intermediate),
|
||||
define_table!(csi_entry),
|
||||
define_table!(csi_param),
|
||||
define_table!(csi_intermediate),
|
||||
define_table!(csi_ignore),
|
||||
define_table!(dcs_entry),
|
||||
define_table!(dcs_param),
|
||||
define_table!(dcs_intermediate),
|
||||
define_table!(dcs_passthrough),
|
||||
define_table!(dcs_ignore),
|
||||
define_table!(osc_string),
|
||||
define_table!(sos_pm_apc_string),
|
||||
];
|
||||
|
||||
pub(crate) static ENTRY: [Action; 14] = [
|
||||
Action::None, // Ground
|
||||
Action::Clear, // Escape
|
||||
Action::None, // EscapeIntermediate
|
||||
Action::Clear, // CsiEntry
|
||||
Action::None, // CsiParam
|
||||
Action::None, // CsiIntermediate
|
||||
Action::None, // CsiIgnore
|
||||
Action::Clear, // DcsEntry
|
||||
Action::None, // DcsParam
|
||||
Action::None, // DcsIntermediate
|
||||
Action::Hook, // DcsPassthrough
|
||||
Action::None, // DcsIgnore
|
||||
Action::OscStart, // OscString
|
||||
Action::None, // SosPmApcString
|
||||
];
|
||||
|
||||
pub(crate) static EXIT: [Action; 14] = [
|
||||
Action::None, // Ground
|
||||
Action::None, // Escape
|
||||
Action::None, // EscapeIntermediate
|
||||
Action::None, // CsiEntry
|
||||
Action::None, // CsiParam
|
||||
Action::None, // CsiIntermediate
|
||||
Action::None, // CsiIgnore
|
||||
Action::None, // DcsEntry
|
||||
Action::None, // DcsParam
|
||||
Action::None, // DcsIntermediate
|
||||
Action::Unhook, // DcsPassthrough
|
||||
Action::None, // DcsIgnore
|
||||
Action::OscEnd, // OscString
|
||||
Action::None, // SosPmApcString
|
||||
];
|
||||
Reference in new issue
Block a user