annotate runtime/indent/dtd.vim @ 31525:f7c82a85e88a v9.0.1095

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