2 " Author: A. S. Budden <abudden _at_ gmail _dot_ com>
3 " Copyright: Copyright (C) 2009-2011 A. S. Budden
4 " Permission is hereby granted to use and distribute this code,
5 " with or without modifications, provided that this copyright
6 " notice is copied with it. Like anything else that's free,
7 " the TagHighlight plugin is provided *as is* and comes with no
8 " warranty of any kind, either expressed or implied. By using
9 " this plugin, you agree that in no event will the copyright
10 " holder be liable for any damages resulting from the use
13 " ---------------------------------------------------------------------
15 if &cp || v:version < 700 || (exists('g:loaded_TagHLLoadDataFile') && (g:plugin_development_mode != 1))
16 throw "Already loaded"
21 let g:loaded_TagHLLoadDataFile = 1
23 function! TagHighlight#LoadDataFile#LoadDataFile(filename)
24 let filename = g:TagHighlightPrivate['PluginPath'] . '/data/' . a:filename
25 return TagHighlight#LoadDataFile#LoadFile(filename)
28 function! TagHighlight#LoadDataFile#LoadFile(filename)
30 let entries = readfile(a:filename)
35 elseif entry[0] =~ '\k'
36 " Keyword character, so not sub entry or comment
37 if entry[len(entry)-1:] == ":"
38 " Beginning of a field, but we don't know whether
39 " it's a list or a dict yet
40 let top_key = entry[:len(entry)-2]
41 elseif stridx(entry, ':') != -1
42 " This is key:value, so it's a simple dictionary entry
43 let parts = split(entry, ':')
44 " Rather coarse replacement of split(x,y,n)
46 let parts[1] = join(parts[1:], ':')
48 if stridx(parts[1], ',') != -1
49 " This entry is a list
50 let result[parts[0]] = split(parts[1], ',')
52 let result[parts[0]] = parts[1]
54 " Clear the top key as this isn't a multi-line entry
57 call TagHLDebug(" Unhandled line: '" . entry . "'", "Error")
59 elseif entry[0] == "\t" && top_key != ''
60 " This is a continuation of a top level key
61 if stridx(entry, ':') != -1
62 " The key is a dictionary, check for mismatch:
63 if has_key(result, top_key)
64 if type(result[top_key]) != type({})
65 call TagHLDebug("Type mismatch on line '".entry."': expected key:value", "Error")
68 let result[top_key] = {}
70 " Handle the entry (without the preceding tab)
71 let parts = split(entry[1:], ':')
72 " Rather coarse replacement of split(x,y,n)
74 let parts[1] = join(parts[1:], ':')
76 if stridx(parts[1], ',') != -1
77 " This entry is a list
78 let result[top_key][parts[0]] = split(parts[1], ',')
80 let result[top_key][parts[0]] = parts[1]
83 " This is a list of strings, check for mismatch
84 if has_key(result, top_key)
85 if type(result[top_key]) != type([])
86 call TagHLDebug("Type mismatch on line '".entry."': didn't expect key:value", "Error")
89 let result[top_key] = []
91 " Add to the list (without the preceding tag)
92 let result[top_key] += [entry[1:]]
95 " Probably a comment or blank line