ScrapVim-lite-3/ParseStateFunction
状態を持たない関数で実装する
interface
code:ts
type ParseState = (key:string) =>
{type: 'states'; parseState: ParseState[];} | {type: 'command'; command: VimCommand;};
code:ts
type ParseStateGenerator = (command: VimCommand, keys: string) => ParseState
引数
解析が完了した場合は、{type: 'command', command}を返す
commandが見つからなかったときは{type: 'states', parseState: []}を返す
解析中のときは、parseStateに自分自身と同じ関数を入れて返す
これ循環定義になっちゃっているな
まあ/icons/typescript.iconを書くわけじゃないから別に良いか。
中でやること
設定ファイルを用いてcustomizeできるようにするために、対応表を別のclassに持たせておく
対応表をどう作るか考えないといけないのか
作成するParseStateの一覧
以下はNormal Modeの場合
OperatorState
defaultはd,c,y
MotionState or CountStateを返す
MiscCommand
Normal Modeで単独で使用されるcommad
<C-f>やH,>>など
別のstateには遷移しない
MotionState
基本的にこのstateでcommandが確定する
RegisterState
"aなど、いくつかの文字列が対象
OperatorState, UseRegisterState, CountStateを返す
UseRegisterState
registerは使うがmotionは使わないcommandを扱う
x, p, dd, Dなど
CountState
繰り返しを指定する数字を入力するState
code:ts
type CountState = (command: VimCommand, keys: string, nextGenerator: ParseStateGenerator[]) => ParseState
nextGeneratorでどのParseStateに遷移するのかを予め決めておく。
どこで生成したかで返す状態が変わる
OperatorStateの場合はMotionState (と自分自身) のみを返す
RegisterStateの場合はOperatorState, UseRegisterState (と自分自身) を返す
初期状態ではOperatorState, MotionState, MiscCommand (と自分自身) を返す
https://gyazo.com/8205ddebb4c55d49400a8225e10bda7c