annotate runtime/indent/dtd.vim @ 23298:553475a18c8c

Added tag v8.2.2194 for changeset 40f1d3f0c53e3717430e7b81e704a45ead448f1e
author Bram Moolenaar <Bram@vim.org>
date Tue, 22 Dec 2020 21:30:04 +0100
parents 0ecb909e3249
children 11b656e74444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
1 " Vim indent file
11062
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 3445
diff changeset
2 " Language: DTD (Document Type Definition for XML)
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 3445
diff changeset
3 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
1218c5353e2b Runtime file updates.
Christian Brabandt <cb@256bit.org>
parents: 3445
diff changeset
4 " Latest Revision: 2011-07-08
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
5
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
6 setlocal indentexpr=GetDTDIndent()
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
7 setlocal indentkeys=!^F,o,O,>
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
8 setlocal nosmartindent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
9
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
10 if exists("*GetDTDIndent")
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
11 finish
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
12 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
13
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
14 let s:cpo_save = &cpo
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
15 set cpo&vim
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
16
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
17 " TODO: Needs to be adjusted to stop at [, <, and ].
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
18 let s:token_pattern = '^[^[:space:]]\+'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
19
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
20 function s:lex1(input, start, ...)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
21 let pattern = a:0 > 0 ? a:1 : s:token_pattern
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
22 let start = matchend(a:input, '^\_s*', a:start)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
23 if start == -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
24 return ["", a:start]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
25 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
26 let end = matchend(a:input, pattern, start)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
27 if end == -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
28 return ["", a:start]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
29 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
30 let token = strpart(a:input, start, end - start)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
31 return [token, end]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
32 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
33
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
34 function s:lex(input, start, ...)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
35 let pattern = a:0 > 0 ? a:1 : s:token_pattern
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
36 let info = s:lex1(a:input, a:start, pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
37 while info[0] == '--'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
38 let info = s:lex1(a:input, info[1], pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
39 while info[0] != "" && info[0] != '--'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
40 let info = s:lex1(a:input, info[1], pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
41 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
42 if info[0] == ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
43 return info
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
44 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
45 let info = s:lex1(a:input, info[1], pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
46 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
47 return info
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
48 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
49
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
50 function s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
51 let token = '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
52 let end = a:end
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
53 let parentheses = [end - 1]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
54 while token != ""
2965
f2de38a019a2 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2587
diff changeset
55 let [token, end] = s:lex(a:line, end, '^\%([(),|]\|[A-Za-z0-9_-]\+\|#P\=CDATA\|%[A-Za-z0-9_-]\+;\)[?*+]\=')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
56 if token[0] == '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
57 call add(parentheses, end - 1)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
58 elseif token[0] == ')'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
59 if len(parentheses) == 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
60 return [-1, end]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
61 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
62 call remove(parentheses, -1)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
63 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
64 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
65 return [parentheses[-1] - strridx(a:line, "\n", parentheses[-1]), end]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
66 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
67
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
68 " TODO: Line and end could be script global (think OO members).
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
69 function GetDTDIndent()
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
70 if v:lnum == 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
71 return 0
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
72 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
73
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
74 " Begin by searching back for a <! that isn’t inside a comment.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
75 " From here, depending on what follows immediately after, parse to
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
76 " where we’re at to determine what to do.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
77 if search('<!', 'bceW') == 0
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
78 return indent(v:lnum - 1)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
79 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
80 let lnum = line('.')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
81 let col = col('.')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
82 let indent = indent('.')
2587
d0049ff5969e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
83 let line = lnum == v:lnum ? getline(lnum) : join(getline(lnum, v:lnum - 1), "\n")
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
84
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
85 let [declaration, end] = s:lex1(line, col)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
86 if declaration == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
87 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
88 elseif declaration == '--'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
89 " We’re looking at a comment. Now, simply determine if the comment is
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
90 " terminated or not. If it isn’t, let Vim take care of that using
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
91 " 'comments' and 'autoindent'. Otherwise, indent to the first lines level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
92 while declaration != ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
93 let [declaration, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
94 if declaration == "-->"
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
95 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
96 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
97 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
98 return -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
99 elseif declaration == 'ELEMENT'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
100 " Check for element name. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
101 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
102 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
103 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
104 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
105
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
106 " Check for token following element name. This can be a specification of
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
107 " whether the start or end tag may be omitted. If nothing is found, indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
108 " one level.
2587
d0049ff5969e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
109 let [token, end] = s:lex(line, end, '^\%([-O(]\|ANY\|EMPTY\)')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
110 let n = 0
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
111 while token =~ '[-O]' && n < 2
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
112 let [token, end] = s:lex(line, end, '^\%([-O(]\|ANY\|EMPTY\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
113 let n += 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
114 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
115 if token == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
116 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
117 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
118
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
119 " Next comes the content model. If the token we’ve found isn’t a
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
120 " parenthesis it must be either ANY, EMPTY or some random junk. Either
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
121 " way, we’re done indenting this element, so set it to that of the first
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
122 " line so that the terminating “>” winds up having the same indention.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
123 if token != '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
124 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
125 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
126
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
127 " Now go through the content model. We need to keep track of the nesting
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
128 " of parentheses. As soon as we hit 0 we’re done. If that happens we must
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
129 " have a complete content model. Thus set indention to be the same as that
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
130 " of the first line so that the terminating “>” winds up having the same
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
131 " indention. Otherwise, we’ll indent to the innermost parentheses not yet
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
132 " matched.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
133 let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
134 if indent_of_innermost != -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
135 return indent_of_innermost
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
136 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
137
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
138 " Finally, look for any additions and/or exceptions to the content model.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
139 " This is defined by a “+” or “-” followed by another content model
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
140 " declaration.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
141 " TODO: Can the “-” be separated by whitespace from the “(”?
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
142 let seen = { '+(': 0, '-(': 0 }
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
143 while 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
144 let [additions_exceptions, end] = s:lex(line, end, '^[+-](')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
145 if additions_exceptions != '+(' && additions_exceptions != '-('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
146 let [token, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
147 if token == '>'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
148 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
149 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
150 " TODO: Should use s:lex here on getline(v:lnum) and check for >.
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
151 return getline(v:lnum) =~ '^\s*>' || count(values(seen), 0) == 0 ? indent : (indent + shiftwidth())
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
152 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
153
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
154 " If we’ve seen an addition or exception already and this is of the same
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
155 " kind, the user is writing a broken DTD. Time to bail.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
156 if seen[additions_exceptions]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
157 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
158 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
159 let seen[additions_exceptions] = 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
160
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
161 let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
162 if indent_of_innermost != -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
163 return indent_of_innermost
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
164 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
165 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
166 elseif declaration == 'ATTLIST'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
167 " Check for element name. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
168 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
169 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
170 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
171 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
172
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
173 " Check for any number of attributes.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
174 while 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
175 " Check for attribute name. If none exists, indent one level, unless the
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
176 " current line is a lone “>”, in which case we indent to the same level
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
177 " as the first line. Otherwise, if the attribute name is “>”, we have
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
178 " actually hit the end of the attribute list, in which case we indent to
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
179 " the same level as the first line.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
180 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
181 if name == ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
182 " TODO: Should use s:lex here on getline(v:lnum) and check for >.
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
183 return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth())
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
184 elseif name == ">"
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
185 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
186 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
187
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
188 " Check for attribute value declaration. If none exists, indent two
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
189 " levels. Otherwise, if it’s an enumerated value, check for nested
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
190 " parentheses and indent to the innermost one if we don’t reach the end
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
191 " of the listc. Otherwise, just continue with looking for the default
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
192 " attribute value.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
193 " TODO: Do validation of keywords
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
194 " (CDATA|NMTOKEN|NMTOKENS|ID|IDREF|IDREFS|ENTITY|ENTITIES)?
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
195 let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
196 if value == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
197 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
198 elseif value == 'NOTATION'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
199 " If this is a enumerated value based on notations, read another token
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
200 " for the actual value. If it doesn’t exist, indent three levels.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
201 " TODO: If validating according to above, value must be equal to '('.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
202 let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
203 if value == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
204 return indent + shiftwidth() * 3
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
205 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
206 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
207
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
208 if value == '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
209 let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
210 if indent_of_innermost != -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
211 return indent_of_innermost
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
212 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
213 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
214
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
215 " Finally look for the attribute’s default value. If non exists, indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
216 " two levels.
2587
d0049ff5969e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
217 let [default, end] = s:lex(line, end, '^\%("\_[^"]*"\|#\(REQUIRED\|IMPLIED\|FIXED\)\)')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
218 if default == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
219 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
220 elseif default == '#FIXED'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
221 " We need to look for the fixed value. If non exists, indent three
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
222 " levels.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
223 let [default, end] = s:lex(line, end, '^"\_[^"]*"')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
224 if default == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
225 return indent + shiftwidth() * 3
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
226 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
227 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
228 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
229 elseif declaration == 'ENTITY'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
230 " Check for entity name. If none exists, indent one level. Otherwise, if
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
231 " the name actually turns out to be a percent sign, “%”, this is a
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
232 " parameter entity. Read another token to determine the entity name and,
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
233 " again, if none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
234 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
235 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
236 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
237 elseif name == '%'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
238 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
239 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
240 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
241 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
242 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
243
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
244 " Now check for the entity value. If none exists, indent one level. If it
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
245 " does exist, indent to same level as first line, as we’re now done with
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
246 " this entity.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
247 "
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
248 " The entity value can be a string in single or double quotes (no escapes
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
249 " to worry about, as entities are used instead). However, it can also be
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
250 " that this is an external unparsed entity. In that case we have to look
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
251 " further for (possibly) a public ID and an URI followed by the NDATA
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
252 " keyword and the actual notation name. For the public ID and URI, indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
253 " two levels, if they don’t exist. If the NDATA keyword doesn’t exist,
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
254 " indent one level. Otherwise, if the actual notation name doesn’t exist,
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
255 " indent two level. If it does, indent to same level as first line, as
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
256 " we’re now done with this entity.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
257 let [value, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
258 if value == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
259 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
260 elseif value == 'SYSTEM' || value == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
261 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
262 if quoted_string == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
263 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
264 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
265
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
266 if value == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
267 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
268 if quoted_string == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
269 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
270 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
271 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
272
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
273 let [ndata, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
274 if ndata == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
275 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
276 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
277
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
278 let [name, end] = s:lex(line, end)
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
279 return name == "" ? (indent + shiftwidth() * 2) : indent
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
280 else
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
281 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
282 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
283 elseif declaration == 'NOTATION'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
284 " Check for notation name. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
285 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
286 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
287 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
288 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
289
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
290 " Now check for the external ID. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
291 let [id, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
292 if id == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
293 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
294 elseif id == 'SYSTEM' || id == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
295 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
296 if quoted_string == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
297 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
298 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
299
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
300 if id == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
301 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\|>\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
302 if quoted_string == ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
303 " TODO: Should use s:lex here on getline(v:lnum) and check for >.
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
304 return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth() * 2)
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
305 elseif quoted_string == '>'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
306 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
307 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
308 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
309 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
310
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
311 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
312 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
313
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
314 " TODO: Processing directives could be indented I suppose. But perhaps it’s
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
315 " just as well to let the user decide how to indent them (perhaps extending
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
316 " this function to include proper support for whatever processing directive
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
317 " language they want to use).
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
318
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
319 " Conditional sections are simply passed along to let Vim decide what to do
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
320 " (and hence the user).
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
321 return -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
322 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
323
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
324 let &cpo = s:cpo_save
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2965
diff changeset
325 unlet s:cpo_save