Source file tm_grammar_cypher.ml

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
345
346
347
let lang_id = "cypher"
let json = {json|{
  "displayName": "Cypher",
  "fileTypes": [
    "cql",
    "cyp",
    "cypher"
  ],
  "name": "cypher",
  "patterns": [
    {
      "include": "#comments"
    },
    {
      "include": "#constants"
    },
    {
      "include": "#keywords"
    },
    {
      "include": "#functions"
    },
    {
      "include": "#path-patterns"
    },
    {
      "include": "#operators"
    },
    {
      "include": "#identifiers"
    },
    {
      "include": "#properties_literal"
    },
    {
      "include": "#numbers"
    },
    {
      "include": "#strings"
    }
  ],
  "repository": {
    "comments": {
      "patterns": [
        {
          "match": "//.*$\\n?",
          "name": "comment.line.double-slash.cypher"
        }
      ]
    },
    "constants": {
      "patterns": [
        {
          "match": "(?i)\\bTRUE|FALSE\\b",
          "name": "constant.language.bool.cypher"
        },
        {
          "match": "(?i)\\bNULL\\b",
          "name": "constant.language.missing.cypher"
        }
      ]
    },
    "functions": {
      "patterns": [
        {
          "match": "(?i)\\b((NOT)(?=\\s*\\()|IS\\s+NULL|IS\\s+NOT\\s+NULL)",
          "name": "keyword.control.function.boolean.cypher"
        },
        {
          "match": "(?i)\\b(ALL|ANY|NONE|SINGLE)(?=\\s*\\()",
          "name": "support.function.predicate.cypher"
        },
        {
          "match": "(?i)\\b(LENGTH|TYPE|ID|COALESCE|HEAD|LAST|TIMESTAMP|STARTNODE|ENDNODE|TOINT|TOFLOAT)(?=\\s*\\()",
          "name": "support.function.scalar.cypher"
        },
        {
          "match": "(?i)\\b(NODES|RELATIONSHIPS|LABELS|EXTRACT|FILTER|TAIL|RANGE|REDUCE)(?=\\s*\\()",
          "name": "support.function.collection.cypher"
        },
        {
          "match": "(?i)\\b(ABS|ACOS|ASIN|ATAN2??|COS|COT|DEGREES|E|EXP|FLOOR|HAVERSIN|LOG|LOG10|PI|RADIANS|RAND|ROUND|SIGN|SIN|SQRT|TAN)(?=\\s*\\()",
          "name": "support.function.math.cypher"
        },
        {
          "match": "(?i)\\b(COUNT|sum|avg|max|min|stdevp??|percentileDisc|percentileCont|collect)(?=\\s*\\()",
          "name": "support.function.aggregation.cypher"
        },
        {
          "match": "(?i)\\b(STR|REPLACE|SUBSTRING|LEFT|RIGHT|LTRIM|RTRIM|TRIM|LOWER|UPPER|SPLIT)(?=\\s*\\()",
          "name": "support.function.string.cypher"
        }
      ]
    },
    "identifiers": {
      "patterns": [
        {
          "match": "`.+?`",
          "name": "variable.other.quoted-identifier.cypher"
        },
        {
          "match": "[_\\p{L}][0-9_\\p{L}]*",
          "name": "variable.other.identifier.cypher"
        }
      ]
    },
    "keywords": {
      "patterns": [
        {
          "match": "(?i)\\b(START|MATCH|WHERE|RETURN|UNION|FOREACH|WITH|AS|LIMIT|SKIP|UNWIND|HAS|DISTINCT|OPTIONAL\\\\s+MATCH|ORDER\\s+BY|CALL|YIELD)\\b",
          "name": "keyword.control.clause.cypher"
        },
        {
          "match": "(?i)\\b(ELSE|END|THEN|CASE|WHEN)\\b",
          "name": "keyword.control.case.cypher"
        },
        {
          "match": "(?i)\\b(FIELDTERMINATOR|USING\\s+PERIODIC\\s+COMMIT|HEADERS|LOAD\\s+CSV|FROM)\\b",
          "name": "keyword.data.import.cypher"
        },
        {
          "match": "(?i)\\b(USING\\s+INDEX|CREATE\\s+INDEX\\s+ON|DROP\\s+INDEX\\s+ON|CREATE\\s+CONSTRAINT\\s+ON|DROP\\s+CONSTRAINT\\s+ON)\\b",
          "name": "keyword.other.indexes.cypher"
        },
        {
          "match": "(?i)\\b(MERGE|DELETE|SET|REMOVE|ON\\s+CREATE|ON\\s+MATCH|CREATE\\s+UNIQUE|CREATE)\\b",
          "name": "keyword.data.definition.cypher"
        },
        {
          "match": "(?i)\\b(DESC|ASC)\\b",
          "name": "keyword.other.order.cypher"
        },
        {
          "begin": "(?i)\\b(node|relationship|rel)((:)([-_\\p{L}][0-9_\\p{L}]*))?(?=\\s*\\()",
          "beginCaptures": {
            "1": {
              "name": "support.class.starting-functions-point.cypher"
            },
            "2": {
              "name": "keyword.control.index-seperator.cypher"
            },
            "3": {
              "name": "keyword.control.index-seperator.cypher"
            },
            "4": {
              "name": "support.class.index.cypher"
            }
          },
          "end": "\\)",
          "name": "source.starting-functions.cypher",
          "patterns": [
            {
              "match": "(`.+?`|[_\\p{L}][0-9_\\p{L}]*)",
              "name": "variable.parameter.relationship-name.cypher"
            },
            {
              "match": "(\\*)",
              "name": "keyword.control.starting-function-params.cypher"
            },
            {
              "include": "#comments"
            },
            {
              "include": "#numbers"
            },
            {
              "include": "#strings"
            }
          ]
        }
      ]
    },
    "numbers": {
      "patterns": [
        {
          "match": "\\b\\d+(\\.\\d+)?\\b",
          "name": "constant.numeric.cypher"
        }
      ]
    },
    "operators": {
      "patterns": [
        {
          "match": "([-!%*+/?])",
          "name": "keyword.operator.math.cypher"
        },
        {
          "match": "(<=|=>|<>|[<>]|=~?)",
          "name": "keyword.operator.compare.cypher"
        },
        {
          "match": "(?i)\\b(OR|AND|XOR|IS)\\b",
          "name": "keyword.operator.logical.cypher"
        },
        {
          "match": "(?i)\\b(IN)\\b",
          "name": "keyword.operator.in.cypher"
        }
      ]
    },
    "path-patterns": {
      "patterns": [
        {
          "match": "(<--|-->?)",
          "name": "support.function.relationship-pattern.cypher"
        },
        {
          "begin": "(<?-)(\\[)",
          "beginCaptures": {
            "1": {
              "name": "support.function.relationship-pattern-start.cypher"
            },
            "2": {
              "name": "keyword.operator.relationship-pattern-start.cypher"
            }
          },
          "end": "(])(->?)",
          "endCaptures": {
            "1": {
              "name": "keyword.operator.relationship-pattern-end.cypher"
            },
            "2": {
              "name": "support.function.relationship-pattern-end.cypher"
            }
          },
          "name": "path-pattern.cypher",
          "patterns": [
            {
              "include": "#identifiers"
            },
            {
              "captures": {
                "1": {
                  "name": "keyword.operator.relationship-type-start.cypher"
                },
                "2": {
                  "name": "entity.name.class.relationship.type.cypher"
                }
              },
              "match": "(:)(`.+?`|[_\\p{L}][0-9_\\p{L}]*)",
              "name": "entity.name.class.relationship-type.cypher"
            },
            {
              "captures": {
                "1": {
                  "name": "support.type.operator.relationship-type-or.cypher"
                },
                "2": {
                  "name": "entity.name.class.relationship.type-or.cypher"
                }
              },
              "match": "(\\|)(\\s*)(`.+?`|[_\\p{L}][0-9_\\p{L}]*)",
              "name": "entity.name.class.relationship-type-ored.cypher"
            },
            {
              "match": "(?:\\?\\*|[*?])\\s*(?:\\d+\\s*(?:\\.\\.\\s*\\d+)?)?",
              "name": "support.function.relationship-pattern.quant.cypher"
            },
            {
              "include": "#properties_literal"
            }
          ]
        }
      ]
    },
    "properties_literal": {
      "patterns": [
        {
          "begin": "\\{",
          "beginCaptures": {
            "0": {
              "name": "keyword.control.properties_literal.cypher"
            }
          },
          "end": "}",
          "endCaptures": {
            "0": {
              "name": "keyword.control.properties_literal.cypher"
            }
          },
          "name": "source.cypher",
          "patterns": [
            {
              "match": "[,:]",
              "name": "keyword.control.properties_literal.seperator.cypher"
            },
            {
              "include": "#comments"
            },
            {
              "include": "#constants"
            },
            {
              "include": "#functions"
            },
            {
              "include": "#operators"
            },
            {
              "include": "#identifiers"
            },
            {
              "include": "#numbers"
            },
            {
              "include": "#strings"
            }
          ]
        }
      ]
    },
    "string_escape": {
      "captures": {
        "2": {
          "name": "string.quoted.double.cypher"
        }
      },
      "match": "(\\\\[\\\\bfnrt])|(\\\\[\"'])",
      "name": "constant.character.escape.cypher"
    },
    "strings": {
      "patterns": [
        {
          "begin": "'",
          "end": "'",
          "name": "string.quoted.single.cypher",
          "patterns": [
            {
              "include": "#string_escape"
            }
          ]
        },
        {
          "begin": "\"",
          "end": "\"",
          "name": "string.quoted.double.cypher",
          "patterns": [
            {
              "include": "#string_escape"
            }
          ]
        }
      ]
    }
  },
  "scopeName": "source.cypher"
}|json}