forked from rosshadden/sublime-xpath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpath.sublime-syntax
145 lines (145 loc) · 5.07 KB
/
xpath.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
%YAML 1.2
---
name: XPath 1.0
scope: query.xml.xpath # http://www.w3.org/TR/xpath/
variables:
QName: '(?![\d.\-])[\w.\-]+'
Prefix: '(?:{{QName}}\s*:)?'
NCName: '{{Prefix}}(?:{{QName}}|\*)'
Attribute: '@\s*(?:{{NCName}})?'
contexts:
prototype:
- include: comments
comments:
- match: '\(:'
scope: punctuation.definition.comment.begin.xpath
push:
- meta_scope: comment.block.xpath
- match: :\)
scope: punctuation.definition.comment.end.xpath
pop: true
- include: comments
main:
- match: \]|\)
scope: invalid.illegal.stray-bracket-end.xpath
- match: ''
push: base
base_without_pop:
- include: location_step
- match: -*\(
scope: punctuation.section.arguments.begin.xpath.subexpression
set: [inside_subexpression, base_disallow_pop] # don't allow an opening parenthesis followed immediately by a closing parenthesis
- match: (")([^"]*)(")
captures:
0: string.quoted.double.xpath # Literal
1: punctuation.definition.string.begin.xpath
3: punctuation.definition.string.end.xpath
set: operator
- match: (')([^']*)(')
captures:
0: string.quoted.single.xpath # Literal
1: punctuation.definition.string.begin.xpath
3: punctuation.definition.string.end.xpath
set: operator
- match: -*(?:\d+\.\d*|\.?\d+) # lxml allows '2', '2.', '.5', '2.5' and '---3' for example - '2.' is treated as '2.0'
scope: constant.numeric.xpath # Number
set: operator
- match: \$({{QName}})?
scope: variable.other.xpath # VariableReference
set: operator_or_predicate_or_location_step
- include: location_test
inside_subexpression:
- meta_scope: meta.block.query.xpath
- match: \)
scope: punctuation.section.arguments.end.xpath.subexpression
set: operator_or_predicate_or_location_step
base:
- include: pop_me
- include: base_without_pop
- include: unexpected_token
location_step:
- match: /{1,2}
scope: punctuation.accessor.location_step.xpath
set: location_test_or_invalid
axis_step:
- match: \.{1,2}
scope: keyword.control.flow.xpath # AxisStep
set: operator_or_location_step
base_disallow_pop:
- include: base_without_pop
- match: '[,\]\)]'
scope: invalid.illegal.unexpected_token.xpath
pop_me:
- match: (?=[,\]\)])
pop: true
operator:
- match: and|or|mod|div|\*|\||\+|-|!?=|<=?|>=?
scope: keyword.operator.xpath # Operator
set: base_disallow_pop #_without_pop # show invalid end predicate when an operator is at the end of a predicate for example //*[a or ]
- include: pop_me
- include: unexpected_token
operator_or_predicate:
- match: \[
scope: punctuation.section.arguments.begin.xpath.predicate
set: [inside_predicate, base_disallow_pop]
- include: operator
operator_or_predicate_or_location_step:
- include: location_step
- include: operator_or_predicate
operator_or_location_step:
- include: location_step
- include: operator
inside_predicate:
- meta_scope: meta.predicate.xpath
- match: \]
scope: punctuation.section.arguments.end.xpath.predicate
set: operator_or_predicate_or_location_step
- include: unexpected_token
node_type:
- match: (comment|text|processing-instruction|node)\s*\(\s*\)
scope: storage.type.node_type.xpath # NodeType
set: operator_or_predicate_or_location_step
name_test:
- match: '{{NCName}}'
scope: variable.parameter.xpath # NameTest
set: operator_or_predicate_or_location_step
node_test:
- include: node_type
- include: name_test
node_test_or_invalid:
- include: node_test
- include: unexpected_token
location_test:
- match: '{{Attribute}}'
scope: keyword.control.flow.xpath # Attribute
set: operator_or_predicate_or_location_step
- match: ((?:ancestor(?:-or-self)?|attribute|child|descendant(?:-or-self)?|following(?:-sibling)?|namespace|parent|preceding(?:-sibling)?|self)\s*::)\s*
captures:
1: constant.language.axis_name.xpath # AxisName
2: variable.parameter.xpath # NameTest
3: keyword.control.flow.xpath # Attribute
set: node_test_or_invalid
- include: node_type
- match: ({{Prefix}}{{QName}})\s*(\()
captures:
0: variable.function.xpath # NameTest # TODO: scope known, built-in names differently to user defined functions
2: punctuation.section.arguments.begin.xpath.subexpression
set: [inside_function, base]
- include: name_test
- include: axis_step
location_test_or_invalid:
- include: location_test
- include: unexpected_token
inside_function:
- meta_scope: meta.function-call.xpath
- match: \)
scope: punctuation.section.arguments.end.xpath.subexpression
set: operator_or_predicate_or_location_step
- match: ','
scope: punctuation.separator.arguments.xpath
push: base
unexpected_token:
- match: '[)\]]'
scope: invalid.illegal.stray-bracket-end.xpath
- match: '[^)\]\s]+'
scope: invalid.illegal.unexpected_token.xpath