Shougo / context_filetype.vim

Context filetype library for Vim script
Other
160 stars 20 forks source link

error: after #44 merged, end match fail #45

Closed tsuyoshicho closed 4 years ago

tsuyoshicho commented 4 years ago

44 マージ後に追加設定なしで、以下の操作がエラーします

手順

  1. deinのtomlを開く
  2. hookの領域に入る

ログ

function precious#context_filetype[2]..99[5]..context_filetype#get_filetype[2]..context_filetype#get[3]..<SNR>327_get_nest[1]..<SNR>327_get_context[20]..<SNR>327_search_range の処理中にエラーが検出されました:
行   28:
E65: 不正な後方参照です
function precious#context_filetype[2]..99[5]..context_filetype#get_filetype の処理中にエラーが検出されました:
行    2:
E121: 未定義の変数です: filetype

(preciousのエラーも出ますが、参考までに付けています)

確認

以下のデバッグコードを入れ

echom 'end forward search:' end_pattern
let end_forward = searchpos(end_pattern, 'ncW', stopline_forward)

再現させると

end forward search: \1\V'''\m

となりました。

searchposへ \1 を含んだパターンが入ったためのようです。

備考

マージ前のcontext_filetypeが残っている環境での動作に問題ないことは確認しました。

tsuyoshicho commented 4 years ago

追加テスト

    let old_end = end_pattern
    let end_pattern = s:replace_submatch_pattern(end_pattern, match_list)
    let new_end = end_pattern
    echom 'end pattern replace(old,new,match list)' old_end new_end match_list

を仕込んだ結果

end pattern replace(old,new,match list) \1 \1\V'''\m ['hook_post_source = ''''''', '''''''', '', '', '', '', '', '', '', '']

となりました

Shougo commented 4 years ago

https://github.com/Shougo/context_filetype.vim/pull/44#issue-409122633

This patch breaks "end" patterns utilizing a backref to a Vim pattern embedded within the referenced "start" submatch. I see this behavior as pretty unexpected (and not that portable), so these sub-matches will now be matched literally.

もしかして、この話?

Shougo commented 4 years ago

reproduced for me. I will revert it later.

Shougo commented 4 years ago

I will fix it later instead.

Shougo commented 4 years ago

It is reproduce-able only both css and toml... It is not easy to find.

bb010g commented 4 years ago

Sorry, this looks like a bug in #44's processing. That immediate match should be

'\V```\m'

instead. I unfortunately can't submit a fix for this myself for the next few days, but it's an edge case with I'm guessing l:backref_end_prev & l:backref_start's initial values.

bb010g commented 4 years ago

Found the problem and commented it over on #44. -1 upper bound on range where there should be 0, leading the whole string's insertion.

Shougo commented 4 years ago

Yes. I have fixed the error.