-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXPath 1.0.sublime-syntax
344 lines (295 loc) · 10.1 KB
/
XPath 1.0.sublime-syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
%YAML 1.2
---
# https://www.w3.org/TR/xpath-10
name: XPath 1.0
scope: source.xpath.1
version: 2
hidden: true
variables:
# The atomic part of a tag or attribute name without namespace separator `:`
# see: https://www.w3.org/TR/REC-xml-names/#NT-NCName
nc_name: '[[:alpha:]_][[:alnum:]_.-]*'
axis_name: |-
(?x:
ancestor(?:-or-self)?
| attribute
| child
| descendant(?:-or-self)?
| following(?:-sibling)?
| namespace
| parent
| preceding(?:-sibling)?
| self
)
kind_test_functions: |-
(?x: comment | node | processing-instruction | text )
contexts:
prototype:
- include: comments
main:
- include: expressions
###[ COMMENTS ]###############################################################
comments:
- match: '\(:'
scope: punctuation.definition.comment.begin.xpath
push: comment-content
comment-content:
- meta_scope: comment.block.xpath
- match: :\)
scope: punctuation.definition.comment.end.xpath
pop: 1
###[ EXPRESSIONS ]############################################################
expressions:
- include: stray-brackets
- match: ','
scope: punctuation.separator.sequence.xpath
- match: (?=\S)
push: expression
expression:
# https://www.w3.org/TR/xpath-10/#NT-Expr
- include: scope:text.xml#entity
- include: unary
- include: predicate
- include: path-sep
- include: path-step
###[ GROUPS ]#################################################################
group:
# https://www.w3.org/TR/xpath-10/#NT-PrimaryExpr (2nd clause)
- match: \(
scope: punctuation.section.group.begin.xpath
set: group-body
group-body:
- meta_scope: meta.group.xpath
- match: \)
scope: punctuation.section.group.end.xpath
set: predicate-or-path-sep-or-operator
- include: expressions
###[ PREDICATES ]#############################################################
predicate-or-path-sep-or-operator:
- include: predicate
- include: path-sep
- include: operator
predicate:
# https://www.w3.org/TR/xpath-10/#NT-Predicate
- match: \[
scope: punctuation.section.predicate.begin.xpath
set: predicate-body
predicate-body:
- meta_scope: meta.predicate.xpath
- match: \]
scope: punctuation.section.predicate.end.xpath
set: predicate-or-path-sep-or-operator
- include: expressions
###[ STEPS ]##################################################################
path-sep:
# https://www.w3.org/TR/xpath-10/#NT-LocationPath
- match: /{1,2}
scope: punctuation.separator.path.xpath
set: path-step
path-step:
# https://www.w3.org/TR/xpath-10/#NT-Step
# https://www.w3.org/TR/xpath-10/#NT-AbbreviatedAxisSpecifier
- match: \.{1,2}(?!\d)
scope: variable.language.path.xpath
set: predicate-or-path-sep-or-operator
- match: \@
scope: punctuation.definition.attribute.xpath
set: attribute-node-test
# https://www.w3.org/TR/xpath-10/#NT-AxisSpecifier
- match: (attribute)\s*(::)
captures:
1: constant.language.axis.xpath
2: punctuation.accessor.double-colon.xpath
set: attribute-node-test
- match: (?:({{axis_name}})|({{nc_name}}))\s*(::)
captures:
1: constant.language.axis.xpath
2: invalid.illegal.axis.xpath
3: punctuation.accessor.double-colon.xpath
set: element-node-test
- include: element-node-test
###[ TESTS ]##################################################################
attribute-node-test:
- include: group
- include: number
- include: string
- include: kind-test
- include: function-call
- include: attribute-name
element-node-test:
- include: group
- include: number
- include: string
- include: kind-test
- include: function-call
- include: element-name
kind-test:
- match: (({{kind_test_functions}})\s*)(\()
captures:
1: meta.function-call.identifier.xpath
2: support.function.kind-test.xpath
3: meta.function-call.arguments.xpath punctuation.section.arguments.begin.xpath
set:
- predicate-or-path-sep-or-operator
- function-call-arguments
###[ FUNCTION CALLS ]#########################################################
function-call:
# https://www.w3.org/TR/xpath-10/#NT-FunctionCall
- match: ((?:({{nc_name}})\s*(:)\s*)?({{nc_name}})\s*)(\()
captures:
1: meta.function-call.identifier.xpath
2: variable.namespace.xpath
3: punctuation.separator.namespace.xpath
4: variable.function.xpath
5: meta.function-call.arguments.xpath punctuation.section.arguments.begin.xpath
set:
- predicate-or-path-sep-or-operator
- function-call-arguments
function-call-arguments:
- meta_content_scope: meta.function-call.arguments.xpath
- match: \)
scope: meta.function-call.arguments.xpath punctuation.section.arguments.end.xpath
pop: 1
- include: stray-brackets
- match: ','
scope: punctuation.separator.arguments.xpath
- match: (?=\S)
push: expression
###[ IDENTIFIERS ]############################################################
attribute-name:
# https://www.w3.org/TR/xpath-10/#NT-NameTest
- match: ({{nc_name}})(\s*(:))
captures:
1: entity.other.attribute-name.namespace.xpath
2: entity.other.attribute-name.xpath
3: punctuation.separator.namespace.xpath
set: attribute-local-name
- include: variable
- include: attribute-local-name
attribute-local-name:
- meta_content_scope: entity.other.attribute-name.xpath
- match: '{{nc_name}}'
scope: entity.other.attribute-name.localname.xpath
set: predicate-or-path-sep-or-operator
- match: \*
scope: entity.other.attribute-name.localname.xpath constant.other.wildcard.asterisk.xpath
set: predicate-or-path-sep-or-operator
- include: else-pop
element-name:
# https://www.w3.org/TR/xpath-10/#NT-NameTest
- match: ({{nc_name}})(\s*(:))
captures:
1: entity.name.tag.namespace.xpath
2: entity.name.tag.xpath
3: punctuation.separator.namespace.xpath
set: element-local-name
- include: variable
- include: element-local-name
element-local-name:
- meta_content_scope: entity.name.tag.xpath
- match: '{{nc_name}}'
scope: entity.name.tag.localname.xpath
set: predicate-or-path-sep-or-operator
- match: \*
scope: entity.name.tag.localname.xpath constant.other.wildcard.asterisk.xpath
set: predicate-or-path-sep-or-operator
- include: else-pop
variable:
# https://www.w3.org/TR/xpath-10/#NT-VariableReference
- match: \$
scope: variable.other.xpath punctuation.definition.variable.xpath
set: variable-name
variable-name:
- match: ({{nc_name}})\s*(:)
captures:
1: variable.namespace.xpath
2: punctuation.separator.namespace.xpath
set: variable-local-name
- include: variable-local-name
variable-local-name:
- match: '{{nc_name}}'
scope: variable.other.xpath
set: predicate-or-path-sep-or-operator
- include: else-pop
###[ LITERALS ]###############################################################
number:
# https://www.w3.org/TR/xpath-10/#NT-Number
- match: (-*)((\.)\d+|\d+(\.)\d*)
scope: meta.number.float.decimal.xpath
captures:
1: keyword.operator.arithmetic.xpath
2: constant.numeric.value.xpath
3: punctuation.separator.decimal.xpath
4: punctuation.separator.decimal.xpath
set: predicate-or-path-sep-or-operator
- match: (-*)(\d+)
scope: meta.number.integer.decimal.xpath
captures:
1: keyword.operator.arithmetic.xpath
2: constant.numeric.value.xpath
set: predicate-or-path-sep-or-operator
string:
# https://www.w3.org/TR/xpath-10/#NT-Literal
- match: \"
scope: punctuation.definition.string.begin.xpath
set: double-quoted-string-body
- match: \'
scope: punctuation.definition.string.begin.xpath
set: single-quoted-string-body
double-quoted-string-body:
- meta_include_prototype: false
- meta_scope: meta.string.xpath string.quoted.double.xpath
- match: \"
scope: punctuation.definition.string.end.xpath
set: predicate-or-path-sep-or-operator
single-quoted-string-body:
- meta_include_prototype: false
- meta_scope: meta.string.xpath string.quoted.single.xpath
- match: \'
scope: punctuation.definition.string.end.xpath
set: predicate-or-path-sep-or-operator
###[ OPERATORS ]##############################################################
unary:
# netative unary expression
# https://www.w3.org/TR/xpath-10/#NT-UnaryExpr
- match: (?!-+\.?\d)\-+
scope: keyword.operator.arithmetic.xpath
operator:
# https://www.w3.org/TR/xpath-10/#NT-Operator
- match: '[-+*]'
scope: keyword.operator.arithmetic.xpath
set: expression
- match: mod|div
scope: keyword.operator.arithmetic.xpath
set: expression
- match: \!?=|<=?|>=?
scope: keyword.operator.comparison.xpath
set: expression
- match: eq|ne|lt|le|gt|ge
scope: keyword.operator.comparison.xpath
set: expression
- match: and|or
scope: keyword.operator.logical.xpath
set: expression
# https://www.w3.org/TR/xpath-10/#NT-UnionExpr
- match: \|
scope: keyword.operator.union.xpath
set: expression
# The following pattern is a heuristic as several real world xslt files
# seem to prefer entities to encode `<` or `>` over `lt` `gt` operators.
- match: ((&)(?:amp|[gl]t)(;))=?
scope: keyword.operator.comparison.xpath
captures:
1: constant.character.entity.named.xml
2: punctuation.definition.entity.xml
3: punctuation.terminator.entity.xml
set: expression
- include: else-pop
###[ ILLEGALS ]###############################################################
stray-brackets:
- match: '[])}]'
scope: invalid.illegal.stray.xpath
###[ PROTOTYPES ]#############################################################
else-pop:
- match: (?=\S)
pop: 1