Fix #379 snippet parse

This commit is contained in:
Shougo Matsushita 2017-04-01 10:23:58 +09:00
parent 368f83d39c
commit affc71bd9f
3 changed files with 10 additions and 14 deletions

View File

@ -81,19 +81,19 @@ endfunction"}}}
" Get marker patterns.
function! neosnippet#get_placeholder_target_marker_pattern() abort "{{{
return '\${\d\+:\(#:\)\?TARGET\%(:.\{-}\)\?\\\@<!}'
return '\%(\\\@<!\|\\\\\zs\)\${\d\+:\(#:\)\?TARGET\%(:.\{-}\)\?\\\@<!}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_pattern() abort "{{{
return '<`\d\+\%(:.\{-}\)\?\\\@<!`>'
endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_pattern() abort "{{{
return '\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}'
return '\%(\\\@<!\|\\\\\zs\)\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_nonzero_pattern() abort "{{{
return '\${\([1-9]\d*\%(:.\{-}\)\?\\\@<!\)}'
return '\%(\\\@<!\|\\\\\zs\)\${\([1-9]\d*\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_zero_pattern() abort "{{{
return '\${\(0\%(:.\{-}\)\?\\\@<!\)}'
return '\%(\\\@<!\|\\\\\zs\)\${\(0\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_default_pattern() abort "{{{
return '<`\d\+:\zs.\{-}\ze\\\@<!`>'

View File

@ -58,20 +58,16 @@ function! neosnippet#view#_insert(snippet, options, cur_text, col) abort "{{{
let snip_word = s:eval_snippet(snip_word)
endif
" Substitute escaped `.
let snip_word = substitute(snip_word, '\\`', '`', 'g')
" Substitute markers.
let snip_word = substitute(snip_word,
\ '\\\@<!'.neosnippet#get_placeholder_marker_substitute_pattern(),
\ neosnippet#get_placeholder_marker_substitute_pattern(),
\ '<`\1`>', 'g')
let snip_word = substitute(snip_word,
\ '\\\@<!'.neosnippet#get_mirror_placeholder_marker_substitute_pattern(),
\ neosnippet#get_mirror_placeholder_marker_substitute_pattern(),
\ '<|\1|>', 'g')
let snip_word = substitute(snip_word,
\ '\\'.neosnippet#get_mirror_placeholder_marker_substitute_pattern().'\|'.
\ '\\'.neosnippet#get_placeholder_marker_substitute_pattern(),
\ '\=submatch(0)[1:]', 'g')
" Substitute escaped characters.
let snip_word = substitute(snip_word, '\\\\', '\\', 'g')
" Insert snippets.
let next_line = getline('.')[a:col-1 :]

View File

@ -42,7 +42,7 @@ syntax match neosnippetWord
\ '^\s\+.*$' contains=
\neosnippetEval,neosnippetPlaceHolder,neosnippetEscape,neosnippetVariable
syntax match neosnippetPlaceHolder
\ '\\\@<!\${\d\+\%(:.\{-}\)\?\\\@<!}'
\ '\%(\\\@<!\|\\\\\zs\)\${\d\+\%(:.\{-}\)\?\\\@<!}'
\ contained contains=neosnippetPlaceHolderComment
syntax match neosnippetVariable
\ '\\\@<!\$\d\+' contained