Drastic Changes: include extended resource. this make be possible that php can expand 'html:5'.

This commit is contained in:
mattn
2010-03-16 18:18:54 +09:00
parent 8c2a246bee
commit 06130914c6

View File

@@ -843,11 +843,10 @@ let s:zen_settings = {
\ } \ }
\} \}
function! s:zen_expandos(key, type) function! s:zen_expandos(type, key)
if has_key(s:zen_settings[a:type], 'expandos') let expandos = s:zen_getResource(a:type, 'expandos', {})
if has_key(s:zen_settings[a:type].expandos, a:key) if has_key(expandos, a:key)
return s:zen_settings[a:type].expandos[a:key] return expandos[a:key]
endif
endif endif
return a:key return a:key
endfunction endfunction
@@ -871,10 +870,18 @@ function! s:zen_is_extends(type, extend)
if !has_key(s:zen_settings[a:type], 'extends') if !has_key(s:zen_settings[a:type], 'extends')
return 0 return 0
endif endif
if a:extends != s:zen_settings[a:type].extends let extends = s:zen_settings[a:type].extends
return 0 if type(extends) == 1
let tmp = split(extends, '\s*,\s*')
unlet! extends
let extends = tmp
endif endif
for ext in extends
if a:extend == ext
return 1 return 1
endif
endfor
return 0
endfunction endfunction
function! s:zen_parseIntoTree(abbr, type) function! s:zen_parseIntoTree(abbr, type)
@@ -891,13 +898,14 @@ function! s:zen_parseIntoTree(abbr, type)
let indent = s:zen_settings.indentation let indent = s:zen_settings.indentation
endif endif
let abbr = substitute(abbr, '\([a-zA-Z][a-zA-Z0-9]*\)+\([()]\|$\)', '\="(".s:zen_expandos(submatch(1), type).")".submatch(2)', 'i') let abbr = substitute(abbr, '\([a-zA-Z][a-zA-Z0-9]*\)+\([()]\|$\)', '\="(".s:zen_expandos(type, submatch(1)).")".submatch(2)', 'i')
let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#]\{-}[a-zA-Z\!][a-zA-Z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#[a-zA-Z0-9_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[a-zA-Z0-9_\-\$]\+\)\)*\)\%(\({[^}]\+}\)\)\{0,1}\%(\s*\*\s*\([0-9]\+\)\s*\)\{0,1}\(\%(\s*)\%(\s*\*\s*[0-9]\+\s*\)\{0,1}\)*\)' let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#]\{-}[a-zA-Z\!][a-zA-Z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#[a-zA-Z0-9_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[a-zA-Z0-9_\-\$]\+\)\)*\)\%(\({[^}]\+}\)\)\{0,1}\%(\s*\*\s*\([0-9]\+\)\s*\)\{0,1}\(\%(\s*)\%(\s*\*\s*[0-9]\+\s*\)\{0,1}\)*\)'
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 } let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
let parent = root let parent = root
let last = root let last = root
let pos = [] let pos = []
while len(abbr) while len(abbr)
" parse line
let match = matchstr(abbr, mx) let match = matchstr(abbr, mx)
let str = substitute(match, mx, '\0', 'ig') let str = substitute(match, mx, '\0', 'ig')
let operator = substitute(match, mx, '\1', 'ig') let operator = substitute(match, mx, '\1', 'ig')
@@ -915,23 +923,31 @@ function! s:zen_parseIntoTree(abbr, type)
let tag_name = 'div' let tag_name = 'div'
endif endif
if multiplier <= 0 | let multiplier = 1 | endif if multiplier <= 0 | let multiplier = 1 | endif
" make default node
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 } let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
let current.name = tag_name let current.name = tag_name
if has_key(s:zen_settings[type], 'aliases')
if has_key(s:zen_settings[type].aliases, tag_name) " aliases
let current.name = s:zen_settings[type].aliases[tag_name] let aliases = s:zen_getResource(type, 'aliases', {})
if has_key(aliases, tag_name)
let current.name = aliases[tag_name]
endif endif
endif
if has_key(s:zen_settings[type], 'snippets') && has_key(s:zen_settings[type].snippets, tag_name) " snippets
let snippet = s:zen_settings[type].snippets[tag_name] let snippets = s:zen_getResource(type, 'snippets', {})
if !empty(snippets) && has_key(snippets, tag_name)
let snippet = snippets[tag_name]
let snippet = substitute(snippet, '|', '${cursor}', 'g') let snippet = substitute(snippet, '|', '${cursor}', 'g')
let lines = split(snippet, "\n") let lines = split(snippet, "\n")
call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", indent, "g")') call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", indent, "g")')
let current.snippet = join(lines, "\n") let current.snippet = join(lines, "\n")
let current.name = '' let current.name = ''
else endif
if has_key(s:zen_settings[type], 'default_attributes')
let default_attributes = s:zen_settings[type].default_attributes " default_attributes
let default_attributes = s:zen_getResource(type, 'default_attributes', {})
if !empty(default_attributes)
for pat in [current.name, tag_name] for pat in [current.name, tag_name]
if has_key(default_attributes, pat) if has_key(default_attributes, pat)
if type(default_attributes[pat]) == 4 if type(default_attributes[pat]) == 4
@@ -946,14 +962,15 @@ function! s:zen_parseIntoTree(abbr, type)
endfor endfor
endfor endfor
endif endif
if type == 'html' if s:zen_is_extends(type, 'html')
let current.name = substitute(current.name, ':.*$', '', '') let current.name = substitute(current.name, ':.*$', '', '')
endif endif
break break
endif endif
endfor endfor
endif endif
endif
" parse attributes
if len(attributes) if len(attributes)
let attr = attributes let attr = attributes
while len(attr) while len(attr)
@@ -977,6 +994,8 @@ function! s:zen_parseIntoTree(abbr, type)
let attr = substitute(strpart(attr, len(item)), '^\s*', '', '') let attr = substitute(strpart(attr, len(item)), '^\s*', '', '')
endwhile endwhile
endif endif
" parse text
if tag_name =~ '^{.*}$' if tag_name =~ '^{.*}$'
let current.name = '' let current.name = ''
let current.value = tag_name let current.value = tag_name
@@ -985,6 +1004,7 @@ function! s:zen_parseIntoTree(abbr, type)
endif endif
let current.multiplier = multiplier let current.multiplier = multiplier
" parse step inside/outside
if !empty(last) if !empty(last)
if operator =~ '>' if operator =~ '>'
unlet! parent unlet! parent
@@ -1012,6 +1032,7 @@ function! s:zen_parseIntoTree(abbr, type)
call add(parent.child, current) call add(parent.child, current)
let last = current let last = current
" parse block
if block_start =~ '(' if block_start =~ '('
if operator =~ '>' if operator =~ '>'
let last.pos += 1 let last.pos += 1
@@ -1020,7 +1041,6 @@ function! s:zen_parseIntoTree(abbr, type)
let pos += [last.pos] let pos += [last.pos]
endfor endfor
endif endif
if block_end =~ ')' if block_end =~ ')'
for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',') for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',')
if n == ')' if n == ')'
@@ -1047,6 +1067,7 @@ function! s:zen_parseIntoTree(abbr, type)
endfor endfor
endif endif
let abbr = abbr[stridx(abbr, match) + len(match):] let abbr = abbr[stridx(abbr, match) + len(match):]
if g:zencoding_debug > 1 if g:zencoding_debug > 1
echo "str=".str echo "str=".str
echo "block_start=".block_start echo "block_start=".block_start
@@ -1262,6 +1283,32 @@ function! s:zen_toString(...)
return str return str
endfunction endfunction
function! s:zen_getResource(type, name, default)
if !has_key(s:zen_settings, a:type)
return a:default
endif
let ret = a:default
if has_key(s:zen_settings[a:type], a:name)
call s:zen_mergeConfig(ret, s:zen_settings[a:type][a:name])
endif
if has_key(s:zen_settings[a:type], 'extends')
let extends = s:zen_settings[a:type].extends
if type(extends) == 1
let tmp = split(extends, '\s*,\s*')
unlet! extends
let extends = tmp
endif
for ext in extends
if has_key(s:zen_settings, ext) && has_key(s:zen_settings[ext], a:name)
call s:zen_mergeConfig(ret, s:zen_settings[ext][a:name])
endif
endfor
endif
return ret
endfunction
function! s:zen_getFileType() function! s:zen_getFileType()
let type = &ft let type = &ft
if type == 'xslt' | let type = 'xsl' | endif if type == 'xslt' | let type = 'xsl' | endif
@@ -1708,14 +1755,20 @@ endfunction
function! s:zen_mergeConfig(lhs, rhs) function! s:zen_mergeConfig(lhs, rhs)
if type(a:lhs) == 3 && type(a:rhs) == 3 if type(a:lhs) == 3 && type(a:rhs) == 3
let a:lhs += a:rhs
if len(a:lhs)
call remove(a:lhs, 0, len(a:lhs)-1) call remove(a:lhs, 0, len(a:lhs)-1)
for index in a:rhs endif
call add(a:lhs, a:rhs[index]) for rhi in a:rhs
call add(a:lhs, a:rhs[rhi])
endfor endfor
elseif type(a:lhs) == 4 && type(a:rhs) == 4 elseif type(a:lhs) == 4 && type(a:rhs) == 4
for key in keys(a:rhs) for key in keys(a:rhs)
if type(a:rhs[key]) == 3 if type(a:rhs[key]) == 3
call s:zen_mergeConfig(a:lhs[key], a:rhs[key]) if !has_key(a:lhs, key)
let a:lhs[key] = []
endif
let a:lhs[key] += a:rhs[key]
elseif type(a:rhs[key]) == 4 elseif type(a:rhs[key]) == 4
if has_key(a:lhs, key) if has_key(a:lhs, key)
call s:zen_mergeConfig(a:lhs[key], a:rhs[key]) call s:zen_mergeConfig(a:lhs[key], a:rhs[key])
@@ -1854,24 +1907,21 @@ function! ZenCompleteTag(findstart, base)
endwhile endwhile
return start return start
else else
let type = &ft let type = s:zen_getFileType()
let res = [] let res = []
if !has_key(s:zen_settings, type)
return res let snippets = s:zen_getResource(type, 'snippets', {})
endif for item in keys(snippets)
if len(type) == 0 | let type = 'html' | endif
for item in keys(s:zen_settings[type].snippets)
if stridx(item, a:base) != -1
call add(res, item)
endif
endfor
if has_key(s:zen_settings[type], 'aliases')
for item in values(s:zen_settings[type].aliases)
if stridx(item, a:base) != -1 if stridx(item, a:base) != -1
call add(res, substitute(item, '\${cursor}', '', 'g')) call add(res, substitute(item, '\${cursor}', '', 'g'))
endif endif
endfor endfor
let aliases = s:zen_getResource(type, 'aliases', {})
for item in values(aliases)
if stridx(item, a:base) != -1
call add(res, substitute(item, '\${cursor}', '', 'g'))
endif endif
endfor
return res return res
endif endif
endfunction endfunction