ScrapVim-lite-3/ParseStateFunction
ScrapVim-lite-3/Mode内で実際にScrapVim-lite-3/command文字列を1文字ごとに解析し、対応するcommandを生成する機能
状態を持たない関数で実装する
interface
code:ts
type ParseState = (key:string) =>
{type: 'states'; parseState: ParseState[];} | {type: 'command'; command: VimCommand;};
code:ts
type ParseStateGenerator = (command: VimCommand, keys: string) => ParseState
引数
key: ScrapVim-lite-3/command文字列
ScrapVim-lite-3/Modeで渡す
解析したScrapVim-lite-3/VimCommandと解析開始時点から渡された全てのScrapVim-lite-3/command文字列をつなげたやつを事前に渡した関数リストを作って返す
解析が完了した場合は、{type: 'command', command}を返す
commandが見つからなかったときは{type: 'states', parseState: []}を返す
解析中のときは、parseStateに自分自身と同じ関数を入れて返す
これ循環定義になっちゃっているな
まあ/icons/typescript.iconを書くわけじゃないから別に良いか。
中でやること
${keys}${key}に前方一致するScrapVim-lite-3/command文字列を探す
ScrapVim-lite-3/command文字列と実際のcommandとの対応表は外部から取得する
設定ファイルを用いてcustomizeできるようにするために、対応表を別のclassに持たせておく
対応表をどう作るか考えないといけないのか
単純なstring - ScrapVim-lite-3/VimCommandの対応ではない
ScrapVim-lite-3/command文字列とVimCommandとの対応リスト
作成するParseStateの一覧
以下はNormal Modeの場合
型は特筆しない限りScrapVim-lite-3/ParseStateFunction#5fdb8b891280f0000021c78bと同じ
OperatorState
operator command (vim)を扱う
defaultはd,c,y
MotionState or CountStateを返す
MiscCommand
Normal Modeで単独で使用されるcommad
<C-f>やH,>>など
別のstateには遷移しない
MotionState
motion (vim)を扱う
基本的にこのstateでcommandが確定する
RegisterState
register (vim)を扱う
"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
#2020-12-17 05:46:54
#2020-12-13 07:03:16