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. " Get marker patterns.
function! neosnippet#get_placeholder_target_marker_pattern() abort "{{{ function! neosnippet#get_placeholder_target_marker_pattern() abort "{{{
return '\${\d\+:\(#:\)\?TARGET\%(:.\{-}\)\?\\\@<!}' return '\%(\\\@<!\|\\\\\zs\)\${\d\+:\(#:\)\?TARGET\%(:.\{-}\)\?\\\@<!}'
endfunction"}}} endfunction"}}}
function! neosnippet#get_placeholder_marker_pattern() abort "{{{ function! neosnippet#get_placeholder_marker_pattern() abort "{{{
return '<`\d\+\%(:.\{-}\)\?\\\@<!`>' return '<`\d\+\%(:.\{-}\)\?\\\@<!`>'
endfunction"}}} endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_pattern() abort "{{{ function! neosnippet#get_placeholder_marker_substitute_pattern() abort "{{{
return '\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}' return '\%(\\\@<!\|\\\\\zs\)\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}} endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_nonzero_pattern() abort "{{{ function! neosnippet#get_placeholder_marker_substitute_nonzero_pattern() abort "{{{
return '\${\([1-9]\d*\%(:.\{-}\)\?\\\@<!\)}' return '\%(\\\@<!\|\\\\\zs\)\${\([1-9]\d*\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}} endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_zero_pattern() abort "{{{ function! neosnippet#get_placeholder_marker_substitute_zero_pattern() abort "{{{
return '\${\(0\%(:.\{-}\)\?\\\@<!\)}' return '\%(\\\@<!\|\\\\\zs\)\${\(0\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}} endfunction"}}}
function! neosnippet#get_placeholder_marker_default_pattern() abort "{{{ function! neosnippet#get_placeholder_marker_default_pattern() abort "{{{
return '<`\d\+:\zs.\{-}\ze\\\@<!`>' 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) let snip_word = s:eval_snippet(snip_word)
endif endif
" Substitute escaped `.
let snip_word = substitute(snip_word, '\\`', '`', 'g')
" Substitute markers. " Substitute markers.
let snip_word = substitute(snip_word, let snip_word = substitute(snip_word,
\ '\\\@<!'.neosnippet#get_placeholder_marker_substitute_pattern(), \ neosnippet#get_placeholder_marker_substitute_pattern(),
\ '<`\1`>', 'g') \ '<`\1`>', 'g')
let snip_word = substitute(snip_word, let snip_word = substitute(snip_word,
\ '\\\@<!'.neosnippet#get_mirror_placeholder_marker_substitute_pattern(), \ neosnippet#get_mirror_placeholder_marker_substitute_pattern(),
\ '<|\1|>', 'g') \ '<|\1|>', 'g')
let snip_word = substitute(snip_word,
\ '\\'.neosnippet#get_mirror_placeholder_marker_substitute_pattern().'\|'. " Substitute escaped characters.
\ '\\'.neosnippet#get_placeholder_marker_substitute_pattern(), let snip_word = substitute(snip_word, '\\\\', '\\', 'g')
\ '\=submatch(0)[1:]', 'g')
" Insert snippets. " Insert snippets.
let next_line = getline('.')[a:col-1 :] let next_line = getline('.')[a:col-1 :]

View File

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